[0] | 1 | //clients.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
[668] | 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[4921] | 26 | /* ckport options: |
---|
[4923] | 27 | * ckport: ignore-symbol: roar_event_to_blob of target libroar0 |
---|
[4921] | 28 | */ |
---|
| 29 | |
---|
[0] | 30 | #include "roard.h" |
---|
| 31 | |
---|
[5192] | 32 | // declared 'extern' |
---|
| 33 | struct roar_client_server * g_clients[ROAR_CLIENTS_MAX]; |
---|
| 34 | |
---|
[5567] | 35 | static struct roard_proto_handle __protos[MAX_PROTOS] = { |
---|
| 36 | {.proto = ROAR_PROTO_ROARAUDIO, .lhandle = NULL, .type = ROARD_PROTO_TYPE_BUILDIN, |
---|
| 37 | .impl = {.buildin = 0}}, |
---|
| 38 | #if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD) |
---|
| 39 | {.proto = ROAR_PROTO_ESOUND, .lhandle = NULL, .type = ROARD_PROTO_TYPE_ROARDPROTO, |
---|
| 40 | .impl = {.roardproto = {ROAR_PROTO_ESOUND, ROAR_SUBSYS_WAVEFORM, "EsounD emulation", NULL, NULL, NULL, emul_esd_check_client, NULL, NULL}}}, |
---|
[4678] | 41 | #endif |
---|
| 42 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY |
---|
[5567] | 43 | {.proto = ROAR_PROTO_RPLAY, .lhandle = NULL, .type = ROARD_PROTO_TYPE_ROARDPROTO, |
---|
| 44 | .impl = {.roardproto = {ROAR_PROTO_RPLAY, ROAR_SUBSYS_WAVEFORM, "RPlay emulation", NULL, NULL, NULL, emul_rplay_check_client, NULL, NULL}}}, |
---|
[4678] | 45 | #endif |
---|
[4703] | 46 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER |
---|
[5567] | 47 | {.proto = ROAR_PROTO_GOPHER, .lhandle = NULL, .type = ROARD_PROTO_TYPE_ROARDPROTO, |
---|
| 48 | .impl = {.roardproto = {ROAR_PROTO_GOPHER, ROAR_SUBSYS_WAVEFORM, "The Internet Gopher Protocol", NULL, NULL, NULL, emul_gopher_check_client, NULL, |
---|
| 49 | emul_gopher_flushed_client}}}, |
---|
[4703] | 50 | #endif |
---|
[5567] | 51 | {.proto = -1} |
---|
[4678] | 52 | }; |
---|
| 53 | |
---|
[3910] | 54 | #define _CHECK_CID_RET(id,ret) if ( (id) < 0 || (id) > ROAR_CLIENTS_MAX || g_clients[(id)] == NULL ) return (ret) |
---|
| 55 | #define _CHECK_CID(id) _CHECK_CID_RET((id), -1) |
---|
| 56 | |
---|
[0] | 57 | int clients_init (void) { |
---|
| 58 | int i; |
---|
| 59 | |
---|
| 60 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 61 | g_clients[i] = NULL; |
---|
| 62 | |
---|
[5567] | 63 | for (i = 0; __protos[i].proto != -1; i++); |
---|
[5275] | 64 | |
---|
| 65 | for (; i < MAX_PROTOS; i++) |
---|
[5567] | 66 | __protos[i].proto = -1; |
---|
[5275] | 67 | |
---|
[0] | 68 | return 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | int clients_free (void) { |
---|
| 72 | int i; |
---|
| 73 | |
---|
| 74 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
[3910] | 75 | if ( g_clients[i] != NULL ) |
---|
[0] | 76 | clients_delete(i); |
---|
| 77 | |
---|
| 78 | return 0; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | int clients_new (void) { |
---|
| 82 | int i; |
---|
| 83 | int s; |
---|
[4326] | 84 | struct roar_client_server * ns; |
---|
[0] | 85 | struct roar_client * n; |
---|
| 86 | |
---|
| 87 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 88 | if ( g_clients[i] == NULL ) { |
---|
[4326] | 89 | ns = roar_mm_malloc(sizeof(struct roar_client_server)); |
---|
| 90 | n = ROAR_CLIENT(ns); |
---|
| 91 | |
---|
| 92 | memset(ns, 0, sizeof(struct roar_client_server)); |
---|
| 93 | |
---|
[0] | 94 | if ( n != NULL ) { |
---|
| 95 | n->pid = -1; |
---|
[437] | 96 | n->uid = -1; |
---|
| 97 | n->gid = -1; |
---|
[0] | 98 | n->fh = -1; |
---|
| 99 | |
---|
| 100 | *n->name = 0; |
---|
| 101 | |
---|
[2614] | 102 | n->proto = ROAR_PROTO_ROARAUDIO; |
---|
| 103 | n->byteorder = ROAR_BYTEORDER_NETWORK; |
---|
[2517] | 104 | |
---|
[346] | 105 | n->acl = NULL; |
---|
| 106 | |
---|
[0] | 107 | n->execed = -1; |
---|
| 108 | for (s = 0; s < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; s++) |
---|
| 109 | n->streams[s] = -1; |
---|
| 110 | |
---|
[2815] | 111 | if ( roar_nnode_new(&(n->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) { |
---|
[3063] | 112 | roar_mm_free(n); |
---|
[2815] | 113 | return -1; |
---|
| 114 | } |
---|
| 115 | |
---|
[4343] | 116 | ns->blockc = 0; |
---|
| 117 | ns->waits = NULL; |
---|
[4468] | 118 | ns->acclev = ACCLEV_NONE; |
---|
[4343] | 119 | |
---|
[4326] | 120 | g_clients[i] = ns; |
---|
[0] | 121 | |
---|
[4101] | 122 | counters_inc(clients, 1); |
---|
[4346] | 123 | roar_notify_core_emit_snoargs(ROAR_OE_BASICS_NEW, -1, i, ROAR_OT_CLIENT); |
---|
[0] | 124 | ROAR_DBG("clients_new(void) = %i", i); |
---|
| 125 | return i; |
---|
| 126 | } else { |
---|
| 127 | ROAR_ERR("clients_new(void): Can not alloc memory for new client: %s", strerror(errno)); |
---|
| 128 | ROAR_ERR("clients_new(void) = -1"); |
---|
| 129 | return -1; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | return -1; |
---|
| 135 | } |
---|
| 136 | |
---|
[3737] | 137 | int clients_new_from_fh(int fh, int proto, int byteorder, int update_nnode) { |
---|
[5571] | 138 | return clients_new_from_fh2(fh, proto, byteorder, update_nnode, NULL, NULL, 0); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | int clients_new_from_fh2(int fh, int proto, int byteorder, |
---|
| 142 | int update_nnode, |
---|
| 143 | struct roard_listen * lsock, struct sockaddr * sockaddr, socklen_t addrlen) { |
---|
| 144 | const struct roard_proto_handle * protohandle; |
---|
| 145 | struct roar_vio_calls vio; |
---|
[3737] | 146 | struct roar_client * c; |
---|
[5571] | 147 | int supported = 0; |
---|
[3737] | 148 | int client; |
---|
| 149 | |
---|
[5571] | 150 | if ( fh == -1 ) { |
---|
| 151 | roar_err_set(ROAR_ERROR_BADFH); |
---|
| 152 | return -1; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | if ( lsock == NULL ) { |
---|
| 156 | switch (proto) { |
---|
| 157 | case ROAR_PROTO_RSOUND: |
---|
| 158 | case ROAR_PROTO_SIMPLE: |
---|
| 159 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 160 | return -1; |
---|
| 161 | break; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if ( byteorder != ROAR_BYTEORDER_NETWORK ) |
---|
[3737] | 166 | return -1; |
---|
| 167 | |
---|
| 168 | |
---|
[5571] | 169 | if ( proto == ROAR_PROTO_RSOUND ) { |
---|
| 170 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 171 | client = emul_rsound_on_connect(fh, lsock); |
---|
| 172 | switch (client) { |
---|
| 173 | case -1: return -1; break; |
---|
| 174 | case -2: return 0; break; |
---|
| 175 | default: // TODO: write error handling |
---|
| 176 | clients_get(client, &c); |
---|
| 177 | fh = c->fh; |
---|
| 178 | break; |
---|
| 179 | } |
---|
| 180 | #else |
---|
| 181 | roar_err_set(ROAR_ERROR_PROTONOSUP); |
---|
[3737] | 182 | return -1; |
---|
[5571] | 183 | #endif |
---|
| 184 | } else { |
---|
| 185 | client = clients_new(); |
---|
[3737] | 186 | |
---|
[5571] | 187 | if ( client == -1 ) { |
---|
| 188 | ROAR_DBG("clients_new_from_fh2(*) = -1 // can not create new client"); |
---|
| 189 | return -1; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if ( clients_set_fh(client, fh) == -1 ) { |
---|
| 193 | ROAR_ERR("clients_new_from_fh2(*): Can not set client's fh"); |
---|
| 194 | |
---|
| 195 | clients_delete(client); |
---|
| 196 | |
---|
| 197 | ROAR_DBG("clients_new_from_fh2(*) = -1"); |
---|
| 198 | return -1; |
---|
| 199 | } |
---|
[3737] | 200 | } |
---|
| 201 | |
---|
| 202 | if ( update_nnode ) { |
---|
| 203 | if ( clients_get(client, &c) != -1 ) { |
---|
| 204 | if ( roar_nnode_free(&(c->nnode)) != -1 ) { |
---|
[5571] | 205 | if ( sockaddr != NULL && addrlen != 0 ) { |
---|
| 206 | roar_nnode_new_from_sockaddr(&(c->nnode), sockaddr, addrlen); |
---|
| 207 | } else { |
---|
| 208 | roar_nnode_new_from_fh(&(c->nnode), fh, 1); |
---|
| 209 | } |
---|
[3737] | 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
[5571] | 214 | if ( clients_set_proto(client, proto) == -1 ) { |
---|
| 215 | ROAR_WARN("clients_new_from_fh2(*): Setting proto(0x%.4x) of client %i failed.", proto, client); |
---|
| 216 | clients_delete(client); |
---|
| 217 | return -1; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | switch (proto) { |
---|
| 221 | case ROAR_PROTO_ROARAUDIO: |
---|
| 222 | // nothing needed to be done here |
---|
| 223 | break; |
---|
| 224 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD |
---|
| 225 | #ifdef ROAR_HAVE_H_ESD |
---|
| 226 | case ROAR_PROTO_ESOUND: |
---|
| 227 | ROAR_DBG("net_get_new_client(*): execing ESD CONNECT command"); |
---|
| 228 | |
---|
| 229 | if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) |
---|
| 230 | return -1; |
---|
| 231 | |
---|
| 232 | ROAR_DBG("net_get_new_client(*): creating VIO OK"); |
---|
| 233 | |
---|
| 234 | if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 ) |
---|
| 235 | return -1; |
---|
| 236 | |
---|
| 237 | ROAR_DBG("net_get_new_client(*): CONNECT execed sucessfully"); |
---|
| 238 | break; |
---|
| 239 | #endif |
---|
| 240 | #endif |
---|
| 241 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
| 242 | case ROAR_PROTO_SIMPLE: |
---|
| 243 | if ( emul_simple_on_connect(client, lsock) == -1 ) |
---|
| 244 | return -1; |
---|
| 245 | break; |
---|
| 246 | #endif |
---|
| 247 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 248 | case ROAR_PROTO_RSOUND: // nothing to do here. |
---|
| 249 | break; |
---|
| 250 | #endif |
---|
| 251 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY |
---|
| 252 | case ROAR_PROTO_RPLAY: |
---|
| 253 | if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) |
---|
| 254 | return -1; |
---|
| 255 | |
---|
| 256 | if ( emul_rplay_on_status(client, NULL, &vio, NULL, 0) == -1 ) |
---|
| 257 | return -1; |
---|
| 258 | break; |
---|
| 259 | #endif |
---|
| 260 | default: |
---|
| 261 | // OS independiend code to close the socket: |
---|
| 262 | if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) |
---|
| 263 | return -1; |
---|
| 264 | |
---|
| 265 | protohandle = clients_get_protohandle(proto); |
---|
| 266 | supported = 0; |
---|
| 267 | if ( protohandle != NULL ) { |
---|
| 268 | switch (protohandle->type) { |
---|
| 269 | case ROARD_PROTO_TYPE_BUILDIN: |
---|
| 270 | //this should not end up here. |
---|
| 271 | ROAR_WARN("net_get_new_client(lsock=%p): proto(%i) marked as buildin but isn't. BAD.", lsock, proto); |
---|
| 272 | supported = 0; |
---|
| 273 | break; |
---|
| 274 | case ROARD_PROTO_TYPE_ROARDPROTO: |
---|
| 275 | supported = 1; |
---|
| 276 | if ( protohandle->impl.roardproto.new_client != NULL ) { |
---|
| 277 | if ( protohandle->impl.roardproto.new_client(client, &vio, lsock) == -1 ) { |
---|
| 278 | supported = 0; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | break; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | if ( !supported ) { |
---|
| 286 | clients_delete(client); |
---|
| 287 | //roar_vio_close(&vio); |
---|
| 288 | return -1; |
---|
| 289 | } |
---|
| 290 | break; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
[3737] | 294 | return 0; |
---|
| 295 | } |
---|
| 296 | |
---|
[0] | 297 | int clients_delete (int id) { |
---|
[4394] | 298 | struct roar_client_server * cs; |
---|
[5567] | 299 | const struct roard_proto_handle * proto; |
---|
[0] | 300 | int i; |
---|
[1164] | 301 | int close_client_fh = 1; |
---|
[0] | 302 | |
---|
[2608] | 303 | ROAR_DBG("clients_delete(id=%i) = ?", id); |
---|
| 304 | |
---|
[4394] | 305 | _CHECK_CID(id); |
---|
| 306 | |
---|
| 307 | cs = g_clients[id]; |
---|
| 308 | |
---|
[5567] | 309 | proto = clients_get_protohandle(ROAR_CLIENT(cs)->proto); |
---|
| 310 | if ( proto != NULL ) { |
---|
| 311 | switch (proto->type) { |
---|
| 312 | case ROARD_PROTO_TYPE_BUILDIN: |
---|
| 313 | /* noop */ |
---|
| 314 | break; |
---|
| 315 | case ROARD_PROTO_TYPE_ROARDPROTO: |
---|
| 316 | if ( proto->impl.roardproto.delete_client != NULL ) |
---|
| 317 | proto->impl.roardproto.delete_client(id); |
---|
| 318 | break; |
---|
[5452] | 319 | } |
---|
| 320 | } |
---|
| 321 | |
---|
[4394] | 322 | if ( cs->waits != NULL ) { |
---|
| 323 | for (i = 0; cs->waits[i] != NULL; i++) |
---|
| 324 | roar_notify_core_unsubscribe(NULL, cs->waits[i]); |
---|
| 325 | |
---|
| 326 | roar_mm_free(cs->waits); |
---|
| 327 | cs->waits = NULL; |
---|
| 328 | } |
---|
| 329 | |
---|
[4346] | 330 | roar_notify_core_emit_snoargs(ROAR_OE_BASICS_DELETE, -1, id, ROAR_OT_CLIENT); |
---|
| 331 | |
---|
[4101] | 332 | counters_inc(clients, -1); |
---|
| 333 | |
---|
[4395] | 334 | if (ROAR_CLIENT(cs)->execed != -1) { |
---|
[0] | 335 | // return streams_delete(g_clients[id]->execed); |
---|
[4395] | 336 | ROAR_CLIENT(cs)->execed = -1; |
---|
[1164] | 337 | close_client_fh = 0; |
---|
[0] | 338 | } |
---|
| 339 | |
---|
| 340 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
[4395] | 341 | streams_delete(ROAR_CLIENT(cs)->streams[i]); |
---|
[0] | 342 | } |
---|
| 343 | |
---|
[4395] | 344 | if ( ROAR_CLIENT(cs)->fh != -1 && close_client_fh ) |
---|
| 345 | close(ROAR_CLIENT(cs)->fh); |
---|
[0] | 346 | |
---|
[4395] | 347 | roar_nnode_free(&(ROAR_CLIENT(cs)->nnode)); |
---|
[2815] | 348 | |
---|
[4684] | 349 | if ( cs->inbuf != NULL ) |
---|
| 350 | roar_buffer_free(cs->inbuf); |
---|
| 351 | |
---|
| 352 | if ( cs->outbuf != NULL ) |
---|
| 353 | roar_buffer_free(cs->outbuf); |
---|
| 354 | |
---|
[5452] | 355 | if ( cs->protoinst != NULL ) |
---|
| 356 | roar_mm_free(cs->protoinst); |
---|
| 357 | |
---|
[4395] | 358 | roar_mm_free(cs); |
---|
[0] | 359 | g_clients[id] = NULL; |
---|
| 360 | |
---|
| 361 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 362 | return 0; |
---|
| 363 | } |
---|
| 364 | |
---|
[3927] | 365 | int clients_close (int id, int nocheck_exec) { |
---|
| 366 | struct roar_client * c; |
---|
| 367 | |
---|
| 368 | ROAR_DBG("clients_close(id=%i) = ?", id); |
---|
| 369 | |
---|
| 370 | _CHECK_CID(id); |
---|
| 371 | |
---|
[4326] | 372 | c = ROAR_CLIENT(g_clients[id]); |
---|
[3927] | 373 | |
---|
| 374 | if ( c->fh == -1 ) { |
---|
| 375 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 376 | return 0; |
---|
| 377 | } |
---|
| 378 | |
---|
[4326] | 379 | if (nocheck_exec || c->execed != -1) { |
---|
[3927] | 380 | close(c->fh); |
---|
| 381 | c->fh = -1; |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 385 | return 0; |
---|
| 386 | } |
---|
| 387 | |
---|
[0] | 388 | int clients_get (int id, struct roar_client ** client) { |
---|
[3910] | 389 | _CHECK_CID(id); |
---|
| 390 | |
---|
[4326] | 391 | *client = ROAR_CLIENT(g_clients[id]); |
---|
[0] | 392 | |
---|
| 393 | if ( *client == NULL ) |
---|
| 394 | return -1; |
---|
| 395 | |
---|
| 396 | return 0; |
---|
| 397 | } |
---|
| 398 | |
---|
[4468] | 399 | int clients_get_server (int id, struct roar_client_server ** client) { |
---|
| 400 | _CHECK_CID(id); |
---|
| 401 | |
---|
| 402 | *client = g_clients[id]; |
---|
| 403 | |
---|
| 404 | if ( *client == NULL ) |
---|
| 405 | return -1; |
---|
| 406 | |
---|
| 407 | return 0; |
---|
| 408 | } |
---|
| 409 | |
---|
[0] | 410 | int clients_set_fh (int id, int fh) { |
---|
[3713] | 411 | struct roar_client * c; |
---|
| 412 | #ifdef SO_PEERCRED |
---|
| 413 | struct ucred cred; |
---|
| 414 | socklen_t cred_len = sizeof(cred); |
---|
| 415 | #endif |
---|
[501] | 416 | |
---|
[3910] | 417 | _CHECK_CID(id); |
---|
| 418 | |
---|
[4326] | 419 | if ( (c = ROAR_CLIENT(g_clients[id])) == NULL ) |
---|
[0] | 420 | return -1; |
---|
| 421 | |
---|
[3713] | 422 | c->fh = fh; |
---|
| 423 | |
---|
[4947] | 424 | if ( fh == -1 ) |
---|
| 425 | return 0; |
---|
| 426 | |
---|
[3713] | 427 | #ifdef SO_PEERCRED |
---|
| 428 | if (getsockopt(fh, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len) != -1) { |
---|
| 429 | if ( cred.pid != 0 ) { |
---|
| 430 | c->pid = cred.pid; |
---|
| 431 | c->uid = cred.uid; |
---|
| 432 | c->gid = cred.gid; |
---|
| 433 | } |
---|
| 434 | } else { |
---|
| 435 | ROAR_DBG("req_on_identify(): Can't get creds via SO_PEERCRED: %s", strerror(errno)); |
---|
| 436 | } |
---|
| 437 | #elif defined(ROAR_HAVE_GETPEEREID) |
---|
| 438 | if (getpeereid(fh, &(c->uid), &(c->gid)) == -1) { |
---|
| 439 | ROAR_DBG("req_on_identify(): Can't get creds via getpeereid(): %s", strerror(errno)); |
---|
| 440 | } |
---|
| 441 | #endif |
---|
[0] | 442 | |
---|
| 443 | return 0; |
---|
| 444 | } |
---|
| 445 | |
---|
[755] | 446 | int clients_get_fh (int id) { |
---|
[3910] | 447 | _CHECK_CID(id); |
---|
[755] | 448 | |
---|
[4326] | 449 | return ROAR_CLIENT(g_clients[id])->fh; |
---|
[755] | 450 | } |
---|
| 451 | |
---|
[0] | 452 | int clients_set_pid (int id, int pid) { |
---|
[3910] | 453 | _CHECK_CID(id); |
---|
[0] | 454 | |
---|
[4326] | 455 | ROAR_CLIENT(g_clients[id])->pid = pid; |
---|
[0] | 456 | |
---|
| 457 | return 0; |
---|
| 458 | } |
---|
| 459 | |
---|
[439] | 460 | int clients_set_uid (int id, int uid) { |
---|
[3910] | 461 | _CHECK_CID(id); |
---|
[439] | 462 | |
---|
[4326] | 463 | ROAR_CLIENT(g_clients[id])->uid = uid; |
---|
[439] | 464 | |
---|
| 465 | return 0; |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | int clients_set_gid (int id, int gid) { |
---|
[3910] | 469 | _CHECK_CID(id); |
---|
[439] | 470 | |
---|
[4326] | 471 | ROAR_CLIENT(g_clients[id])->gid = gid; |
---|
[439] | 472 | |
---|
| 473 | return 0; |
---|
| 474 | } |
---|
| 475 | |
---|
[2517] | 476 | int clients_set_proto (int id, int proto) { |
---|
[2614] | 477 | int byteorder = ROAR_BYTEORDER_UNKNOWN; |
---|
| 478 | |
---|
[3910] | 479 | _CHECK_CID(id); |
---|
[2517] | 480 | |
---|
[2614] | 481 | switch (proto) { |
---|
| 482 | case ROAR_PROTO_ROARAUDIO: |
---|
[2828] | 483 | case ROAR_PROTO_ESOUND: |
---|
[3981] | 484 | case ROAR_PROTO_RPLAY: |
---|
[3255] | 485 | case ROAR_PROTO_SIMPLE: |
---|
[2614] | 486 | byteorder = ROAR_BYTEORDER_NETWORK; |
---|
| 487 | break; |
---|
| 488 | } |
---|
| 489 | |
---|
[4326] | 490 | ROAR_CLIENT(g_clients[id])->proto = proto; |
---|
| 491 | ROAR_CLIENT(g_clients[id])->byteorder = byteorder; |
---|
[2517] | 492 | |
---|
| 493 | return 0; |
---|
| 494 | } |
---|
| 495 | |
---|
[4343] | 496 | int clients_block (int id, int unblock) { |
---|
| 497 | _CHECK_CID(id); |
---|
| 498 | |
---|
| 499 | if ( unblock ) { |
---|
| 500 | g_clients[id]->blockc--; |
---|
| 501 | } else { |
---|
| 502 | g_clients[id]->blockc++; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | return 0; |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | |
---|
[498] | 509 | #define MAX_STREAMLESS 8 |
---|
| 510 | |
---|
[0] | 511 | int clients_check_all (void) { |
---|
[1480] | 512 | #ifdef ROAR_HAVE_SELECT |
---|
[4326] | 513 | struct roar_client * c; |
---|
[0] | 514 | struct timeval tv; |
---|
[4686] | 515 | fd_set r, w, e; |
---|
[66] | 516 | int i, j; |
---|
[0] | 517 | int ret; |
---|
| 518 | int fh; |
---|
| 519 | int max_fh = -1; |
---|
[71] | 520 | int have = 0; |
---|
[498] | 521 | struct { |
---|
| 522 | int id; |
---|
| 523 | int fh; |
---|
| 524 | } streamless[MAX_STREAMLESS]; |
---|
| 525 | int have_streamless = 0; |
---|
| 526 | int have_stream; |
---|
[0] | 527 | |
---|
[4815] | 528 | ROAR_DBG("clients_check_all(void) = ?"); |
---|
| 529 | |
---|
[0] | 530 | FD_ZERO(&r); |
---|
[4686] | 531 | FD_ZERO(&w); |
---|
[0] | 532 | FD_ZERO(&e); |
---|
| 533 | |
---|
| 534 | tv.tv_sec = 0; |
---|
| 535 | tv.tv_usec = 1; |
---|
| 536 | |
---|
| 537 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
[4326] | 538 | if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) |
---|
[0] | 539 | continue; |
---|
| 540 | |
---|
[4815] | 541 | ROAR_DBG("clients_check_all(void): i(client)=%i", i); |
---|
| 542 | |
---|
[4326] | 543 | if ( (fh = c->fh) != -1 ) { |
---|
[71] | 544 | have++; |
---|
| 545 | |
---|
[610] | 546 | ROAR_DBG("clients_check_all(*): fh=%i", fh); |
---|
| 547 | |
---|
[66] | 548 | FD_SET(fh, &r); |
---|
| 549 | FD_SET(fh, &e); |
---|
| 550 | |
---|
[4686] | 551 | if ( g_clients[i]->outbuf != NULL ) { |
---|
| 552 | FD_SET(fh, &w); |
---|
| 553 | } |
---|
| 554 | |
---|
[66] | 555 | if ( fh > max_fh ) |
---|
| 556 | max_fh = fh; |
---|
[84] | 557 | } |
---|
[0] | 558 | |
---|
[498] | 559 | have_stream = 0; |
---|
| 560 | |
---|
[84] | 561 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[4815] | 562 | ROAR_DBG("clients_check_all(void): i(client)=%i, j(stream)=%i", i, j); |
---|
[4326] | 563 | if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { |
---|
| 564 | ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, c->streams[j], fh); |
---|
[1504] | 565 | if ( fh > -1 ) { |
---|
| 566 | FD_SET(fh, &r); |
---|
[0] | 567 | |
---|
[1504] | 568 | if ( fh > max_fh ) |
---|
| 569 | max_fh = fh; |
---|
[3579] | 570 | } else if ( fh == -2 ) { |
---|
[4326] | 571 | streams_check(c->streams[j]); |
---|
[1504] | 572 | } |
---|
[498] | 573 | |
---|
| 574 | have_stream = 1; |
---|
[66] | 575 | } |
---|
[84] | 576 | //printf("D: client=%i, stream=%i, fh=%i\n", i, j, fh); |
---|
[66] | 577 | } |
---|
| 578 | |
---|
[498] | 579 | if ( !have_stream && have_streamless < MAX_STREAMLESS ) { |
---|
| 580 | streamless[have_streamless ].id = i; |
---|
[4326] | 581 | if ( (streamless[have_streamless++].fh = c->fh) == -1 ) |
---|
[498] | 582 | have_streamless--; |
---|
| 583 | } |
---|
[0] | 584 | } |
---|
| 585 | |
---|
[4815] | 586 | ROAR_DBG("clients_check_all(void): max_fh=%i", max_fh); |
---|
| 587 | |
---|
[256] | 588 | if ( max_fh == -1 ) |
---|
| 589 | return 0; |
---|
| 590 | |
---|
[4686] | 591 | if ( (ret = select(max_fh + 1, &r, &w, &e, &tv)) < 1 ) { |
---|
[71] | 592 | return ret < 0 ? ret : have; |
---|
[0] | 593 | } |
---|
| 594 | |
---|
| 595 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
[4326] | 596 | if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) |
---|
[0] | 597 | continue; |
---|
| 598 | |
---|
[4326] | 599 | if ( (fh = c->fh) != -1 ) { |
---|
[66] | 600 | if ( FD_ISSET(fh, &r) ) { |
---|
[4326] | 601 | if ( c->execed == -1 ) { |
---|
[66] | 602 | clients_check(i); |
---|
[4326] | 603 | if ( g_clients[i] != NULL && ROAR_CLIENT(g_clients[i])->execed != -1 ) { |
---|
[1834] | 604 | FD_CLR(fh, &r); |
---|
| 605 | } |
---|
[255] | 606 | /* |
---|
[66] | 607 | } else { |
---|
| 608 | streams_check(g_clients[i]->execed); |
---|
[255] | 609 | */ |
---|
[66] | 610 | } |
---|
| 611 | } |
---|
[4686] | 612 | if ( FD_ISSET(fh, &w) ) { |
---|
| 613 | clients_flush(i); |
---|
| 614 | } |
---|
[0] | 615 | |
---|
[84] | 616 | if ( FD_ISSET(fh, &e) ) { |
---|
[66] | 617 | clients_delete(i); |
---|
[84] | 618 | continue; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | |
---|
[4326] | 622 | if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) |
---|
[84] | 623 | continue; |
---|
| 624 | |
---|
| 625 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[1611] | 626 | ROAR_DBG("clients_check_all(*): D: client=%i, stream=%i, g_clients[i=%i] = %p", i, j, i, g_clients[i]); |
---|
[136] | 627 | if ( g_clients[i] == NULL ) // streams_check() bellow can delete our client (why?) |
---|
| 628 | break; |
---|
[1611] | 629 | |
---|
| 630 | //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); |
---|
[4326] | 631 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, c->streams[j]); |
---|
[1611] | 632 | |
---|
[4326] | 633 | if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { |
---|
[1611] | 634 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); |
---|
[3579] | 635 | if ( fh > -1 && FD_ISSET(fh, &r) ) { |
---|
[4326] | 636 | streams_check(c->streams[j]); |
---|
[66] | 637 | } |
---|
[0] | 638 | } |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | |
---|
[498] | 642 | if ( have_streamless ) { |
---|
| 643 | FD_ZERO(&r); |
---|
[4686] | 644 | FD_ZERO(&w); |
---|
[498] | 645 | |
---|
| 646 | tv.tv_sec = 0; |
---|
| 647 | tv.tv_usec = 1; |
---|
| 648 | |
---|
| 649 | max_fh = -1; |
---|
| 650 | |
---|
| 651 | for (i = 0; i < have_streamless; i++) { |
---|
[4326] | 652 | if ( g_clients[j = streamless[i].id] == NULL ) |
---|
[607] | 653 | continue; |
---|
| 654 | |
---|
[4326] | 655 | if ( ROAR_CLIENT(g_clients[j])->execed != -1 ) |
---|
[601] | 656 | continue; |
---|
| 657 | |
---|
[498] | 658 | fh = streamless[i].fh; |
---|
| 659 | |
---|
| 660 | ROAR_DBG("clients_check_all(void): fh=%i", fh); |
---|
| 661 | FD_SET(fh, &r); |
---|
| 662 | |
---|
[4688] | 663 | if ( g_clients[j]->outbuf != NULL ) { |
---|
[4686] | 664 | FD_SET(fh, &w); |
---|
| 665 | } |
---|
| 666 | |
---|
[498] | 667 | if ( fh > max_fh ) |
---|
| 668 | max_fh = fh; |
---|
| 669 | } |
---|
| 670 | |
---|
[4686] | 671 | if ( (ret = select(max_fh + 1, &r, &w, NULL, &tv)) < 0 ) { |
---|
[498] | 672 | return ret; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | for (i = 0; i < have_streamless; i++) { |
---|
| 676 | if ( FD_ISSET(streamless[i].fh, &r) ) { |
---|
| 677 | clients_check(streamless[i].id); |
---|
| 678 | } |
---|
[4686] | 679 | if ( FD_ISSET(streamless[i].fh, &w) ) { |
---|
| 680 | clients_flush(streamless[i].id); |
---|
| 681 | } |
---|
[498] | 682 | } |
---|
| 683 | } |
---|
| 684 | |
---|
[71] | 685 | ROAR_DBG("clients_check_all(void) = %i // have value", have); |
---|
| 686 | return have; |
---|
[1480] | 687 | #else |
---|
[4815] | 688 | ROAR_DBG("clients_check_all(void) = -1"); |
---|
[1480] | 689 | return -1; |
---|
| 690 | #endif |
---|
[0] | 691 | } |
---|
| 692 | |
---|
| 693 | int clients_check (int id) { |
---|
[4326] | 694 | struct roar_client * c; |
---|
[0] | 695 | struct roar_message m; |
---|
| 696 | struct roar_connection con; |
---|
[5190] | 697 | struct roar_vio_calls vio; |
---|
[5155] | 698 | struct roar_error_state errstate; |
---|
[5567] | 699 | const struct roard_proto_handle * proto; |
---|
[5155] | 700 | int command_error; |
---|
[0] | 701 | char * data = NULL; |
---|
| 702 | int oldcmd; |
---|
| 703 | int r; |
---|
[498] | 704 | int rv = 0; |
---|
[3926] | 705 | uint32_t flags[2] = {COMMAND_FLAG_NONE, COMMAND_FLAG_NONE}; |
---|
[4325] | 706 | uint32_t event; |
---|
[0] | 707 | |
---|
[4713] | 708 | ROAR_DBG("clients_check(id=%i) = ?", id); |
---|
| 709 | |
---|
[3910] | 710 | _CHECK_CID(id); |
---|
| 711 | |
---|
[4326] | 712 | c = ROAR_CLIENT(g_clients[id]); |
---|
| 713 | |
---|
| 714 | if ( c->fh == -1 ) |
---|
[0] | 715 | return -1; |
---|
| 716 | |
---|
[4326] | 717 | roar_connect_fh(&con, c->fh); |
---|
[0] | 718 | |
---|
[4713] | 719 | ROAR_DBG("clients_check(id=%i): c->proto=%i", id, c->proto); |
---|
| 720 | |
---|
[4326] | 721 | switch (c->proto) { |
---|
[2517] | 722 | case ROAR_PROTO_ROARAUDIO: |
---|
| 723 | r = roar_recv_message(&con, &m, &data); |
---|
[0] | 724 | |
---|
[2517] | 725 | if ( r == -1 ) { // should we drop the client? |
---|
| 726 | clients_delete(id); |
---|
| 727 | return -1; |
---|
| 728 | } |
---|
[0] | 729 | |
---|
[4325] | 730 | event = ROAR_NOTIFY_CMD2EVENT(m.cmd); |
---|
| 731 | |
---|
[2517] | 732 | oldcmd = m.cmd; |
---|
[0] | 733 | |
---|
[5155] | 734 | roar_err_store(&errstate); |
---|
| 735 | roar_err_clear_all(); |
---|
| 736 | r = command_exec(id, &m, &data, flags); |
---|
| 737 | roar_err_update(); |
---|
| 738 | command_error = roar_error; |
---|
| 739 | roar_err_restore(&errstate); |
---|
| 740 | |
---|
| 741 | if ( r == -1 ) { |
---|
| 742 | // use command_error to create an error frame here as soon as this is supported. |
---|
[2517] | 743 | m.cmd = ROAR_CMD_ERROR; |
---|
| 744 | m.datalen = 0; |
---|
| 745 | ROAR_DBG("clients_check(*): Exec of command faild!"); |
---|
| 746 | } else { |
---|
| 747 | if ( m.cmd == oldcmd ) { |
---|
| 748 | m.cmd = ROAR_CMD_OK; |
---|
| 749 | m.datalen = 0; |
---|
| 750 | } else if ( m.cmd == ROAR_CMD_OK_STOP ) { |
---|
| 751 | m.cmd = ROAR_CMD_OK; |
---|
| 752 | rv = 1; |
---|
| 753 | } |
---|
| 754 | } |
---|
[4298] | 755 | ROAR_DBG("clients_check(*): data=%p", data); |
---|
| 756 | |
---|
[4347] | 757 | if ( flags[1] & COMMAND_FLAG_OUT_NOSEND ) { |
---|
| 758 | roar_notify_core_emit_simple(event, id, -1, -1, -1, -1, NULL, 0); |
---|
| 759 | } else { |
---|
| 760 | roar_notify_core_emit_simple(event, id, -1, -1, m.cmd, -1, NULL, 0); |
---|
[4343] | 761 | roar_send_message(&con, &m, flags[1] & COMMAND_FLAG_OUT_LONGDATA ? data : NULL); |
---|
[4347] | 762 | } |
---|
[3928] | 763 | |
---|
| 764 | if ( flags[1] & COMMAND_FLAG_OUT_CLOSECON ) |
---|
| 765 | clients_close(id, 1); |
---|
| 766 | |
---|
[2517] | 767 | break; |
---|
[4020] | 768 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
[3684] | 769 | case ROAR_PROTO_RSOUND: |
---|
[3820] | 770 | rv = emul_rsound_check_client(id, NULL); |
---|
[3825] | 771 | if ( rv == 0 ) { // loop as long as we don't get an error. |
---|
| 772 | while (rv == 0) |
---|
| 773 | rv = emul_rsound_check_client(id, NULL); |
---|
| 774 | rv = 0; // restore |
---|
| 775 | } else { // in case of error delete the client |
---|
[4131] | 776 | if ( |
---|
| 777 | #ifdef EAGAIN |
---|
[4153] | 778 | errno != EAGAIN && |
---|
[4131] | 779 | #endif |
---|
| 780 | #ifdef EWOULDBLOCK |
---|
[4153] | 781 | errno != EWOULDBLOCK && |
---|
[4131] | 782 | #endif |
---|
| 783 | #ifdef EINTR |
---|
[4153] | 784 | errno != EINTR && |
---|
[4131] | 785 | #endif |
---|
[4153] | 786 | 1 ) { |
---|
[4131] | 787 | rv = clients_delete(id); |
---|
| 788 | } else { |
---|
| 789 | rv = 0; |
---|
| 790 | } |
---|
[3825] | 791 | } |
---|
[3684] | 792 | break; |
---|
| 793 | #endif |
---|
[2517] | 794 | default: |
---|
| 795 | rv = -1; |
---|
[5567] | 796 | proto = clients_get_protohandle(c->proto); |
---|
| 797 | if ( proto != NULL ) { |
---|
| 798 | roar_vio_open_fh_socket(&vio, clients_get_fh(id)); |
---|
| 799 | if ( proto->lhandle != NULL ) |
---|
| 800 | roar_dl_context_restore(proto->lhandle); |
---|
| 801 | |
---|
| 802 | switch (proto->type) { |
---|
| 803 | case ROARD_PROTO_TYPE_BUILDIN: |
---|
| 804 | ROAR_WARN("clients_check(id=%i): proto(%i) marked as buildin but isn't. BAD.", id, proto->proto); |
---|
| 805 | break; |
---|
| 806 | case ROARD_PROTO_TYPE_ROARDPROTO: |
---|
| 807 | if ( proto->impl.roardproto.check_client != NULL ) |
---|
| 808 | rv = proto->impl.roardproto.check_client(id, &vio); |
---|
| 809 | break; |
---|
[4678] | 810 | } |
---|
[5567] | 811 | |
---|
| 812 | if ( proto->lhandle != NULL ) |
---|
| 813 | roar_dl_context_store(proto->lhandle); |
---|
[4678] | 814 | } |
---|
[0] | 815 | } |
---|
| 816 | |
---|
[4297] | 817 | if ( data != NULL ) |
---|
[5295] | 818 | roar_mm_free(data); |
---|
[0] | 819 | |
---|
[2517] | 820 | ROAR_DBG("clients_check(id=%i) = %i", id, rv); |
---|
[498] | 821 | return rv; |
---|
[0] | 822 | } |
---|
| 823 | |
---|
[4686] | 824 | int clients_flush (int id) { |
---|
[5567] | 825 | struct roar_vio_calls vio; |
---|
| 826 | struct roar_client_server * cs; |
---|
| 827 | struct roar_client * c; |
---|
| 828 | const struct roard_proto_handle * p; |
---|
[4686] | 829 | size_t len; |
---|
| 830 | ssize_t ret; |
---|
| 831 | void * buf; |
---|
[5567] | 832 | int rv; |
---|
[4686] | 833 | |
---|
| 834 | _CHECK_CID(id); |
---|
| 835 | |
---|
| 836 | c = ROAR_CLIENT(cs = g_clients[id]); |
---|
| 837 | |
---|
[5567] | 838 | p = clients_get_protohandle(c->proto); |
---|
[4686] | 839 | |
---|
| 840 | if ( p == NULL ) |
---|
| 841 | return -1; |
---|
| 842 | |
---|
| 843 | roar_vio_open_fh_socket(&vio, clients_get_fh(id)); |
---|
| 844 | |
---|
[5567] | 845 | switch (p->type) { |
---|
| 846 | case ROARD_PROTO_TYPE_BUILDIN: |
---|
| 847 | /* noop */ |
---|
| 848 | break; |
---|
| 849 | case ROARD_PROTO_TYPE_ROARDPROTO: |
---|
| 850 | if ( p->impl.roardproto.flush_client != NULL ) { |
---|
| 851 | if ( p->lhandle != NULL ) |
---|
| 852 | roar_dl_context_restore(p->lhandle); |
---|
| 853 | rv = p->impl.roardproto.flush_client(id, &vio); |
---|
| 854 | if ( p->lhandle != NULL ) |
---|
| 855 | roar_dl_context_store(p->lhandle); |
---|
| 856 | return rv; |
---|
| 857 | } |
---|
| 858 | break; |
---|
[4686] | 859 | } |
---|
| 860 | |
---|
| 861 | if ( roar_buffer_get_len(cs->outbuf, &len) == -1 ) |
---|
| 862 | return -1; |
---|
| 863 | |
---|
| 864 | if ( roar_buffer_get_data(cs->outbuf, &buf) == -1 ) |
---|
| 865 | return -1; |
---|
| 866 | |
---|
| 867 | ret = roar_vio_write(&vio, buf, len); |
---|
| 868 | |
---|
| 869 | if ( ret < 1 ) { |
---|
| 870 | clients_delete(id); |
---|
| 871 | return -1; |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | if ( ret == len ) { |
---|
[5242] | 875 | if ( roar_buffer_next(&(cs->outbuf)) == -1 ) { |
---|
| 876 | clients_delete(id); |
---|
| 877 | return -1; |
---|
| 878 | } |
---|
[4686] | 879 | } else { |
---|
| 880 | if ( roar_buffer_set_offset(cs->outbuf, ret) == -1 ) { |
---|
| 881 | clients_delete(id); |
---|
| 882 | return -1; |
---|
| 883 | } |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | if ( cs->outbuf == NULL ) { |
---|
[5567] | 887 | switch (p->type) { |
---|
| 888 | case ROARD_PROTO_TYPE_BUILDIN: |
---|
| 889 | /* noop */ |
---|
| 890 | break; |
---|
| 891 | case ROARD_PROTO_TYPE_ROARDPROTO: |
---|
| 892 | if ( p->impl.roardproto.flushed_client != NULL ) { |
---|
| 893 | if ( p->lhandle != NULL ) |
---|
| 894 | roar_dl_context_restore(p->lhandle); |
---|
| 895 | rv = p->impl.roardproto.flushed_client(id, &vio); |
---|
| 896 | if ( p->lhandle != NULL ) |
---|
| 897 | roar_dl_context_store(p->lhandle); |
---|
| 898 | return rv; |
---|
| 899 | } |
---|
| 900 | break; |
---|
[4686] | 901 | } |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | return 0; |
---|
| 905 | } |
---|
| 906 | |
---|
[0] | 907 | int clients_send_mon (struct roar_audio_info * sa, uint32_t pos) { |
---|
| 908 | int i; |
---|
[934] | 909 | // int fh; |
---|
| 910 | int j; |
---|
[2715] | 911 | int keep_going; |
---|
[0] | 912 | |
---|
| 913 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 914 | if ( g_clients[i] == NULL ) |
---|
| 915 | continue; |
---|
| 916 | |
---|
[2715] | 917 | keep_going = 1; |
---|
| 918 | |
---|
[934] | 919 | /* |
---|
[0] | 920 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 921 | continue; |
---|
[934] | 922 | */ |
---|
[0] | 923 | |
---|
[4326] | 924 | ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, ROAR_CLIENT(g_clients[i])->execed); |
---|
[1905] | 925 | |
---|
[2706] | 926 | /* |
---|
[0] | 927 | if ( g_clients[i]->execed == -1 ) { |
---|
| 928 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
[2706] | 929 | */ |
---|
[2715] | 930 | for (j = 0; keep_going && j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[934] | 931 | //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2715] | 932 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); |
---|
[4326] | 933 | if ( ROAR_CLIENT(g_clients[i])->streams[j] != -1 ) { |
---|
| 934 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, ROAR_CLIENT(g_clients[i])->streams[j]); |
---|
| 935 | streams_send_mon(ROAR_CLIENT(g_clients[i])->streams[j]); |
---|
[2715] | 936 | |
---|
| 937 | // the client may be deleted here, check if it still exists: |
---|
| 938 | if ( g_clients[i] == NULL ) |
---|
| 939 | keep_going = 0; |
---|
[1905] | 940 | } |
---|
[934] | 941 | } |
---|
[2706] | 942 | /* |
---|
[0] | 943 | } else { |
---|
| 944 | // streams_check(g_clients[i]->execed); |
---|
| 945 | streams_send_mon(g_clients[i]->execed); |
---|
| 946 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 947 | // clients_delete(i); // delete client in case we could not write |
---|
| 948 | } |
---|
[2706] | 949 | */ |
---|
[0] | 950 | } |
---|
| 951 | |
---|
[1902] | 952 | // TODO: FIXME: should this really be -1? |
---|
[0] | 953 | return -1; |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { |
---|
[4326] | 957 | struct roar_client * c; |
---|
[0] | 958 | int i; |
---|
| 959 | int fh; |
---|
| 960 | |
---|
| 961 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
[4326] | 962 | if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) |
---|
[0] | 963 | continue; |
---|
| 964 | |
---|
[4326] | 965 | if ( (fh = c->fh) == -1 ) |
---|
[0] | 966 | continue; |
---|
| 967 | |
---|
[4326] | 968 | if ( c->execed == -1 ) { |
---|
[0] | 969 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
| 970 | } else { |
---|
| 971 | // streams_check(g_clients[i]->execed); |
---|
[4326] | 972 | streams_send_filter(c->execed); |
---|
[0] | 973 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 974 | // clients_delete(i); // delete client in case we could not write |
---|
| 975 | } |
---|
| 976 | } |
---|
| 977 | |
---|
| 978 | return -1; |
---|
| 979 | } |
---|
| 980 | |
---|
[5301] | 981 | int clients_add_output (int id, struct roar_buffer ** buf) { |
---|
[4686] | 982 | struct roar_client_server * cs; |
---|
| 983 | |
---|
| 984 | _CHECK_CID(id); |
---|
| 985 | cs = g_clients[id]; |
---|
| 986 | |
---|
| 987 | if ( cs->outbuf == NULL ) { |
---|
[5301] | 988 | cs->outbuf = *buf; |
---|
[4686] | 989 | } else { |
---|
[5301] | 990 | return roar_buffer_moveinto(cs->outbuf, buf); |
---|
[4686] | 991 | } |
---|
| 992 | |
---|
| 993 | return 0; |
---|
| 994 | } |
---|
| 995 | |
---|
[4679] | 996 | // proto support |
---|
[5567] | 997 | const struct roard_proto_handle * clients_get_protohandle(const int proto) { |
---|
| 998 | size_t i; |
---|
| 999 | |
---|
| 1000 | if ( proto < 0 ) { |
---|
| 1001 | roar_err_set(ROAR_ERROR_INVAL); |
---|
| 1002 | return NULL; |
---|
| 1003 | } |
---|
| 1004 | |
---|
| 1005 | for (i = 0; i < (sizeof(__protos)/sizeof(*__protos)); i++) |
---|
| 1006 | if ( __protos[i].proto == proto ) |
---|
| 1007 | return &(__protos[i]); |
---|
| 1008 | |
---|
| 1009 | roar_err_set(ROAR_ERROR_NOENT); |
---|
| 1010 | return NULL; |
---|
| 1011 | } |
---|
| 1012 | |
---|
[5312] | 1013 | int clients_register_proto(struct roard_proto * proto, struct roar_dl_lhandle * lhandle) { |
---|
[5567] | 1014 | const size_t len = sizeof(__protos)/sizeof(*__protos); |
---|
[4679] | 1015 | size_t i; |
---|
| 1016 | |
---|
| 1017 | if ( proto == NULL ) |
---|
| 1018 | return -1; |
---|
| 1019 | |
---|
[5567] | 1020 | for (i = 0; __protos[i].proto != -1; i++); |
---|
[4679] | 1021 | |
---|
| 1022 | // i is now at pos of current EOS entry. |
---|
| 1023 | |
---|
| 1024 | // test if we have space for one more entry: |
---|
| 1025 | if ( (i+1) >= len ) |
---|
| 1026 | return -1; |
---|
| 1027 | |
---|
[5567] | 1028 | memcpy(&(__protos[i].impl.roardproto), proto, sizeof(__protos[i].impl.roardproto)); |
---|
| 1029 | |
---|
| 1030 | __protos[i].impl.roardproto.lhandle = lhandle; |
---|
[4679] | 1031 | |
---|
[5567] | 1032 | __protos[i].proto = proto->proto; |
---|
| 1033 | __protos[i].type = ROARD_PROTO_TYPE_ROARDPROTO; |
---|
| 1034 | __protos[i].lhandle = lhandle; |
---|
[5312] | 1035 | |
---|
[4679] | 1036 | return 0; |
---|
| 1037 | } |
---|
| 1038 | |
---|
[5275] | 1039 | int clients_unregister_proto(int proto) { |
---|
| 1040 | size_t i; |
---|
| 1041 | |
---|
| 1042 | if ( proto < 0 ) { |
---|
| 1043 | roar_err_set(ROAR_ERROR_RANGE); |
---|
| 1044 | return -1; |
---|
| 1045 | } |
---|
| 1046 | |
---|
[5567] | 1047 | for (i = 0; i < (sizeof(__protos)/sizeof(*__protos)); i++) { |
---|
| 1048 | if ( __protos[i].proto == proto ) { |
---|
| 1049 | memset(&(__protos[i]), 0, sizeof(*__protos)); |
---|
| 1050 | __protos[i].proto = -1; |
---|
[5275] | 1051 | return 0; |
---|
| 1052 | } |
---|
| 1053 | } |
---|
| 1054 | |
---|
| 1055 | roar_err_set(ROAR_ERROR_NOENT); |
---|
| 1056 | return -1; |
---|
| 1057 | } |
---|
| 1058 | |
---|
| 1059 | void print_protolist (enum output_format format) { |
---|
[5567] | 1060 | struct roard_proto_handle * p; |
---|
[5275] | 1061 | char subsys[7] = " "; |
---|
[5567] | 1062 | const char * description; |
---|
[5275] | 1063 | size_t i; |
---|
| 1064 | |
---|
| 1065 | switch (format) { |
---|
| 1066 | case FORMAT_NATIVE: |
---|
| 1067 | printf(" Protocol Flag Subsys - Description\n"); |
---|
| 1068 | printf("------------------------------------------------------\n"); |
---|
| 1069 | printf(" roar WM LRX - RoarAudio native protocol\n"); |
---|
| 1070 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
| 1071 | printf(" simple WM LRX - PulseAudio simple protocol\n"); |
---|
| 1072 | #endif |
---|
| 1073 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 1074 | printf(" rsound W - RSound emulation\n"); |
---|
| 1075 | #endif |
---|
| 1076 | break; |
---|
| 1077 | case FORMAT_WIKI: |
---|
| 1078 | printf("||=Protocol =||=Flag =||=Subsys =||=Description =||\n"); |
---|
| 1079 | printf("||roar || ||WM LRX ||RoarAudio native protocol ||\n"); |
---|
| 1080 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
| 1081 | printf("||simple || ||WM LRX ||PulseAudio simple protocol ||\n"); |
---|
| 1082 | #endif |
---|
| 1083 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 1084 | printf("||rsound || ||W ||RSound emulation ||\n"); |
---|
| 1085 | #endif |
---|
| 1086 | break; |
---|
| 1087 | case FORMAT_CSV: |
---|
| 1088 | printf("Protocol,Flag,Subsys,Description\n"); |
---|
| 1089 | printf("roar,,WM LRX,RoarAudio native protocol\n"); |
---|
| 1090 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE |
---|
| 1091 | printf("simple,,WM LRX,PulseAudio simple protocol\n"); |
---|
| 1092 | #endif |
---|
| 1093 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
| 1094 | printf("rsound,,W,RSound emulation\n"); |
---|
| 1095 | #endif |
---|
| 1096 | break; |
---|
| 1097 | default: |
---|
| 1098 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
| 1099 | return; |
---|
| 1100 | } |
---|
| 1101 | |
---|
[5567] | 1102 | for (i = 0; i < (sizeof(__protos)/sizeof(*__protos)); i++) { |
---|
| 1103 | p = &(__protos[i]); |
---|
[5275] | 1104 | if ( p->proto == -1 ) |
---|
| 1105 | continue; |
---|
| 1106 | |
---|
[5574] | 1107 | // protocols of type BUILDIN are handled above. |
---|
| 1108 | if ( p->type == ROARD_PROTO_TYPE_BUILDIN ) |
---|
| 1109 | continue; |
---|
| 1110 | |
---|
[5275] | 1111 | strncpy(subsys, " ", 6); |
---|
[5567] | 1112 | description = "(none)"; |
---|
[5275] | 1113 | |
---|
[5567] | 1114 | if ( p->type == ROARD_PROTO_TYPE_ROARDPROTO ) { |
---|
| 1115 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 1116 | subsys[0] = 'W'; |
---|
| 1117 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 1118 | subsys[1] = 'M'; |
---|
| 1119 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_CB ) |
---|
| 1120 | subsys[2] = 'C'; |
---|
| 1121 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 1122 | subsys[3] = 'L'; |
---|
| 1123 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_RAW ) |
---|
| 1124 | subsys[4] = 'R'; |
---|
| 1125 | if ( p->impl.roardproto.subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
| 1126 | subsys[5] = 'X'; |
---|
| 1127 | |
---|
| 1128 | description = p->impl.roardproto.description; |
---|
| 1129 | } |
---|
[5275] | 1130 | |
---|
| 1131 | switch (format) { |
---|
| 1132 | case FORMAT_NATIVE: |
---|
[5567] | 1133 | printf(" %-13s %s - %s\n", roar_proto2str(p->proto), subsys, description); |
---|
[5275] | 1134 | break; |
---|
| 1135 | case FORMAT_WIKI: |
---|
[5567] | 1136 | printf("||%s || ||%s ||%s ||\n", roar_proto2str(p->proto), subsys, description); |
---|
[5275] | 1137 | break; |
---|
| 1138 | case FORMAT_CSV: |
---|
[5567] | 1139 | printf("%s,,%s,%s\n", roar_proto2str(p->proto), subsys, description); |
---|
[5275] | 1140 | break; |
---|
| 1141 | } |
---|
| 1142 | } |
---|
| 1143 | } |
---|
[4679] | 1144 | |
---|
[0] | 1145 | int client_stream_exec (int client, int stream) { |
---|
[4326] | 1146 | struct roar_client * c; |
---|
[0] | 1147 | int i; |
---|
[3920] | 1148 | int fh; |
---|
[0] | 1149 | |
---|
[3910] | 1150 | _CHECK_CID(client); |
---|
| 1151 | |
---|
| 1152 | #if 0 |
---|
[1901] | 1153 | if ( g_clients[client] == NULL ) { |
---|
| 1154 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream); |
---|
[0] | 1155 | return -1; |
---|
[1901] | 1156 | } |
---|
[3910] | 1157 | #endif |
---|
[0] | 1158 | |
---|
[4326] | 1159 | c = ROAR_CLIENT(g_clients[client]); |
---|
| 1160 | |
---|
[0] | 1161 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
[4326] | 1162 | if ( c->streams[i] == stream ) { |
---|
| 1163 | c->execed = stream; |
---|
[3921] | 1164 | if ( streams_is_ready(stream) == 0 ) { |
---|
[4326] | 1165 | streams_set_fh(stream, c->fh); |
---|
[3920] | 1166 | streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); |
---|
| 1167 | } else { |
---|
[4254] | 1168 | ROAR_DBG("client_stream_exec(client=%i, stream=%i): fh=?", client, stream); |
---|
[4326] | 1169 | if ( (fh = c->fh) != -1 ) { |
---|
[3925] | 1170 | close(fh); |
---|
[4326] | 1171 | c->fh = -1; |
---|
[3925] | 1172 | } |
---|
[3920] | 1173 | } |
---|
[2815] | 1174 | ROAR_DBG("client_stream_exec(client=%i, stream=%i) = 0", client, stream); |
---|
[0] | 1175 | return 0; |
---|
| 1176 | } |
---|
| 1177 | } |
---|
| 1178 | |
---|
[1901] | 1179 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not own stream", client, stream); |
---|
[0] | 1180 | return -1; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[78] | 1183 | int client_stream_set_fh (int client, int stream, int fh) { |
---|
| 1184 | int i; |
---|
| 1185 | |
---|
[4240] | 1186 | ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i) = ?", client, stream, fh); |
---|
| 1187 | |
---|
[3910] | 1188 | _CHECK_CID(client); |
---|
[78] | 1189 | |
---|
| 1190 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
[4326] | 1191 | if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { |
---|
[4240] | 1192 | ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i): stream found, index %i", client, stream, fh, i); |
---|
[4229] | 1193 | return streams_set_fh(stream, fh); |
---|
[78] | 1194 | } |
---|
| 1195 | } |
---|
| 1196 | |
---|
[4240] | 1197 | ROAR_WARN("client_stream_set_fh(client=%i, stream=%i, fh=%i) = -1 // client does not own stream", client, stream, fh); |
---|
[78] | 1198 | return -1; |
---|
| 1199 | } |
---|
| 1200 | |
---|
[0] | 1201 | int client_stream_add (int client, int stream) { |
---|
| 1202 | int i; |
---|
| 1203 | |
---|
[3910] | 1204 | _CHECK_CID(client); |
---|
[0] | 1205 | |
---|
| 1206 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
[4326] | 1207 | if ( ROAR_CLIENT(g_clients[client])->streams[i] == -1 ) { |
---|
| 1208 | ROAR_CLIENT(g_clients[client])->streams[i] = stream; |
---|
[0] | 1209 | streams_set_client(stream, client); |
---|
| 1210 | return 0; |
---|
| 1211 | } |
---|
| 1212 | } |
---|
| 1213 | |
---|
| 1214 | return -1; |
---|
| 1215 | } |
---|
| 1216 | |
---|
| 1217 | int client_stream_delete (int client, int stream) { |
---|
| 1218 | int i; |
---|
| 1219 | |
---|
[3910] | 1220 | _CHECK_CID(client); |
---|
[0] | 1221 | |
---|
| 1222 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
[4326] | 1223 | if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { |
---|
| 1224 | ROAR_CLIENT(g_clients[client])->streams[i] = -1; |
---|
[0] | 1225 | |
---|
[4326] | 1226 | if ( stream == ROAR_CLIENT(g_clients[client])->execed ) { |
---|
[0] | 1227 | ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); |
---|
| 1228 | clients_delete(client); |
---|
| 1229 | } |
---|
| 1230 | |
---|
| 1231 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = 0", client, stream); |
---|
| 1232 | return 0; |
---|
| 1233 | } |
---|
| 1234 | } |
---|
| 1235 | |
---|
| 1236 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = -1", client, stream); |
---|
| 1237 | return -1; |
---|
| 1238 | } |
---|
| 1239 | |
---|
[767] | 1240 | int client_stream_move (int client, int stream) { |
---|
| 1241 | int old_client = streams_get_client(stream); |
---|
| 1242 | |
---|
[771] | 1243 | ROAR_DBG("client_stream_move(client=%i, stream=%i): old_client = %i", client, stream, old_client); |
---|
| 1244 | |
---|
[767] | 1245 | if ( old_client != -1 ) |
---|
| 1246 | if ( client_stream_delete(old_client, stream) == -1 ) |
---|
| 1247 | return -1; |
---|
| 1248 | |
---|
| 1249 | return client_stream_add(client, stream); |
---|
| 1250 | } |
---|
| 1251 | |
---|
[4343] | 1252 | |
---|
| 1253 | // notify thingys |
---|
| 1254 | int clients_wait (int client, struct roar_event * events, size_t num) { |
---|
| 1255 | struct roar_client_server * cs; |
---|
| 1256 | size_t i, c; |
---|
| 1257 | |
---|
| 1258 | ROAR_DBG("clients_wait(client=%i, events=%p, num=%llu) = ?", client, events, (long long unsigned int)num); |
---|
| 1259 | |
---|
| 1260 | _CHECK_CID(client); |
---|
| 1261 | |
---|
| 1262 | cs = g_clients[client]; |
---|
| 1263 | |
---|
| 1264 | if ( cs->waits != NULL ) |
---|
| 1265 | return -1; |
---|
| 1266 | |
---|
| 1267 | cs->waits = roar_mm_malloc((num+1) * sizeof(struct roar_subscriber *)); |
---|
| 1268 | |
---|
| 1269 | if ( cs->waits == NULL ) |
---|
| 1270 | return -1; |
---|
| 1271 | |
---|
| 1272 | if ( clients_block(client, 0) != 0 ) |
---|
| 1273 | return -1; |
---|
| 1274 | |
---|
| 1275 | for (i = 0; i < num; i++) { |
---|
| 1276 | #if defined(DEBUG) && 0 |
---|
| 1277 | dbg_notify_cb(NULL, &(events[i]), cs); |
---|
| 1278 | #endif |
---|
| 1279 | cs->waits[i] = roar_notify_core_subscribe(NULL, &(events[i]), clients_ncb_wait, cs); |
---|
| 1280 | if ( cs->waits[i] == NULL ) { |
---|
| 1281 | for (c = 0; c < i; c++) |
---|
| 1282 | roar_notify_core_unsubscribe(NULL, cs->waits[c]); |
---|
| 1283 | roar_mm_free(cs->waits); |
---|
| 1284 | cs->waits = NULL; |
---|
| 1285 | clients_block(client, 1); |
---|
| 1286 | return -1; |
---|
| 1287 | } |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | cs->waits[num] = NULL; |
---|
| 1291 | |
---|
| 1292 | ROAR_DBG("clients_wait(client=%i, events=%p, num=%llu) = 0", client, events, (long long unsigned int)num); |
---|
| 1293 | return 0; |
---|
| 1294 | } |
---|
| 1295 | |
---|
| 1296 | void clients_ncb_wait(struct roar_notify_core * core, struct roar_event * event, void * userdata) { |
---|
| 1297 | struct roar_client_server * cs = userdata; |
---|
| 1298 | struct roar_message m; |
---|
| 1299 | struct roar_connection con; |
---|
| 1300 | uint16_t * u16 = (uint16_t *) m.data; |
---|
| 1301 | size_t tmp; |
---|
| 1302 | size_t i; |
---|
| 1303 | |
---|
| 1304 | ROAR_DBG("clients_ncb_wait(core=%p, event=%p, userdata=%p) = ?", core, event, userdata); |
---|
| 1305 | |
---|
| 1306 | for (i = 0; cs->waits[i] != NULL; i++) |
---|
| 1307 | roar_notify_core_unsubscribe(NULL, cs->waits[i]); |
---|
| 1308 | |
---|
| 1309 | roar_mm_free(cs->waits); |
---|
| 1310 | cs->waits = NULL; |
---|
| 1311 | |
---|
| 1312 | // protocol depended handling... |
---|
| 1313 | memset(&m, 0, sizeof(m)); |
---|
| 1314 | m.cmd = ROAR_CMD_OK; |
---|
| 1315 | u16[0] = ROAR_HOST2NET16(0); // Version |
---|
| 1316 | u16[1] = ROAR_HOST2NET16(0); // flags |
---|
| 1317 | |
---|
| 1318 | tmp = sizeof(m.data) - 4; |
---|
| 1319 | |
---|
| 1320 | roar_event_to_blob(event, m.data + 4, &tmp); |
---|
| 1321 | |
---|
| 1322 | m.datalen = tmp + 4; |
---|
| 1323 | |
---|
| 1324 | roar_connect_fh(&con, ROAR_CLIENT(cs)->fh); |
---|
| 1325 | roar_send_message(&con, &m, NULL); |
---|
| 1326 | // ...end of protocol depended handling. |
---|
| 1327 | |
---|
| 1328 | // clients_block(, 1); |
---|
| 1329 | // TODO: FIXME: bad hack... |
---|
| 1330 | cs->blockc--; |
---|
| 1331 | } |
---|
| 1332 | |
---|
[4480] | 1333 | |
---|
| 1334 | // acclev: |
---|
| 1335 | static struct { |
---|
| 1336 | const enum roard_client_acclev acclev; |
---|
| 1337 | const char * name; |
---|
| 1338 | } _g_acclevs[] = { |
---|
| 1339 | {ACCLEV_NONE, "none" }, |
---|
| 1340 | {ACCLEV_IDENTED, "idented"}, |
---|
| 1341 | {ACCLEV_CONCTL, "conctl" }, |
---|
| 1342 | {ACCLEV_GUEST, "guest" }, |
---|
| 1343 | {ACCLEV_USER, "user" }, |
---|
| 1344 | {ACCLEV_PWRUSER, "pwruser"}, |
---|
| 1345 | {ACCLEV_ALL, "all" }, |
---|
| 1346 | {-1, NULL} |
---|
| 1347 | }; |
---|
| 1348 | |
---|
| 1349 | enum roard_client_acclev clients_str2acclev(const char * acclev) { |
---|
| 1350 | int i; |
---|
| 1351 | |
---|
| 1352 | for (i = 0; _g_acclevs[i].name != NULL; i++) |
---|
| 1353 | if ( !strcasecmp(_g_acclevs[i].name, acclev) ) |
---|
| 1354 | return _g_acclevs[i].acclev; |
---|
| 1355 | |
---|
[5146] | 1356 | return ACCLEV_ERROR; |
---|
[4480] | 1357 | } |
---|
| 1358 | |
---|
| 1359 | const char * clients_acclev2str(const enum roard_client_acclev acclev) { |
---|
| 1360 | int i; |
---|
| 1361 | |
---|
| 1362 | for (i = 0; _g_acclevs[i].name != NULL; i++) |
---|
| 1363 | if ( _g_acclevs[i].acclev == acclev ) |
---|
| 1364 | return _g_acclevs[i].name; |
---|
| 1365 | |
---|
| 1366 | return NULL; |
---|
| 1367 | } |
---|
| 1368 | |
---|
[0] | 1369 | //ll |
---|