[0] | 1 | //clients.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[0] | 25 | #include "roard.h" |
---|
| 26 | |
---|
| 27 | int clients_init (void) { |
---|
| 28 | int i; |
---|
| 29 | |
---|
| 30 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 31 | g_clients[i] = NULL; |
---|
| 32 | |
---|
| 33 | return 0; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | int clients_free (void) { |
---|
| 37 | int i; |
---|
| 38 | |
---|
| 39 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 40 | if ( g_clients[i] ) |
---|
| 41 | clients_delete(i); |
---|
| 42 | |
---|
| 43 | return 0; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | int clients_new (void) { |
---|
| 47 | int i; |
---|
| 48 | int s; |
---|
| 49 | struct roar_client * n; |
---|
| 50 | |
---|
| 51 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 52 | if ( g_clients[i] == NULL ) { |
---|
| 53 | n = malloc(sizeof(struct roar_client)); |
---|
| 54 | if ( n != NULL ) { |
---|
| 55 | n->pid = -1; |
---|
[437] | 56 | n->uid = -1; |
---|
| 57 | n->gid = -1; |
---|
[0] | 58 | n->fh = -1; |
---|
| 59 | |
---|
| 60 | *n->name = 0; |
---|
| 61 | *n->host = 0; |
---|
| 62 | |
---|
[2614] | 63 | n->proto = ROAR_PROTO_ROARAUDIO; |
---|
| 64 | n->byteorder = ROAR_BYTEORDER_NETWORK; |
---|
[2517] | 65 | |
---|
[346] | 66 | n->acl = NULL; |
---|
| 67 | |
---|
[0] | 68 | n->execed = -1; |
---|
| 69 | for (s = 0; s < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; s++) |
---|
| 70 | n->streams[s] = -1; |
---|
| 71 | |
---|
[2815] | 72 | if ( roar_nnode_new(&(n->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) { |
---|
| 73 | free(n); |
---|
| 74 | return -1; |
---|
| 75 | } |
---|
| 76 | |
---|
[0] | 77 | g_clients[i] = n; |
---|
| 78 | |
---|
| 79 | ROAR_DBG("clients_new(void) = %i", i); |
---|
| 80 | return i; |
---|
| 81 | } else { |
---|
| 82 | ROAR_ERR("clients_new(void): Can not alloc memory for new client: %s", strerror(errno)); |
---|
| 83 | ROAR_ERR("clients_new(void) = -1"); |
---|
| 84 | return -1; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | return -1; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | int clients_delete (int id) { |
---|
| 93 | int i; |
---|
[1164] | 94 | int close_client_fh = 1; |
---|
[0] | 95 | |
---|
[2608] | 96 | ROAR_DBG("clients_delete(id=%i) = ?", id); |
---|
| 97 | |
---|
[0] | 98 | if ( g_clients[id] == NULL ) |
---|
| 99 | return -1; |
---|
| 100 | |
---|
| 101 | if (g_clients[id]->execed != -1) { |
---|
| 102 | // return streams_delete(g_clients[id]->execed); |
---|
| 103 | g_clients[id]->execed = -1; |
---|
[1164] | 104 | close_client_fh = 0; |
---|
[0] | 105 | } |
---|
| 106 | |
---|
| 107 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 108 | streams_delete(g_clients[id]->streams[i]); |
---|
| 109 | } |
---|
| 110 | |
---|
[1164] | 111 | if ( g_clients[id]->fh != -1 && close_client_fh ) |
---|
[0] | 112 | close(g_clients[id]->fh); |
---|
| 113 | |
---|
[2815] | 114 | roar_nnode_free(&(g_clients[id]->nnode)); |
---|
| 115 | |
---|
[0] | 116 | free(g_clients[id]); |
---|
| 117 | g_clients[id] = NULL; |
---|
| 118 | |
---|
| 119 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 120 | return 0; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | int clients_get (int id, struct roar_client ** client) { |
---|
| 124 | *client = g_clients[id]; |
---|
| 125 | |
---|
| 126 | if ( *client == NULL ) |
---|
| 127 | return -1; |
---|
| 128 | |
---|
| 129 | return 0; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | int clients_set_fh (int id, int fh) { |
---|
[501] | 133 | |
---|
[0] | 134 | if ( g_clients[id] == NULL ) |
---|
| 135 | return -1; |
---|
| 136 | |
---|
| 137 | g_clients[id]->fh = fh; |
---|
| 138 | |
---|
| 139 | return 0; |
---|
| 140 | } |
---|
| 141 | |
---|
[755] | 142 | int clients_get_fh (int id) { |
---|
| 143 | if ( g_clients[id] == NULL ) |
---|
| 144 | return -1; |
---|
| 145 | |
---|
| 146 | return g_clients[id]->fh; |
---|
| 147 | } |
---|
| 148 | |
---|
[0] | 149 | int clients_set_pid (int id, int pid) { |
---|
| 150 | if ( g_clients[id] == NULL ) |
---|
| 151 | return -1; |
---|
| 152 | |
---|
| 153 | g_clients[id]->pid = pid; |
---|
| 154 | |
---|
| 155 | return 0; |
---|
| 156 | } |
---|
| 157 | |
---|
[439] | 158 | int clients_set_uid (int id, int uid) { |
---|
| 159 | if ( g_clients[id] == NULL ) |
---|
| 160 | return -1; |
---|
| 161 | |
---|
| 162 | g_clients[id]->uid = uid; |
---|
| 163 | |
---|
| 164 | return 0; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | int clients_set_gid (int id, int gid) { |
---|
| 168 | if ( g_clients[id] == NULL ) |
---|
| 169 | return -1; |
---|
| 170 | |
---|
| 171 | g_clients[id]->gid = gid; |
---|
| 172 | |
---|
| 173 | return 0; |
---|
| 174 | } |
---|
| 175 | |
---|
[2517] | 176 | int clients_set_proto (int id, int proto) { |
---|
[2614] | 177 | int byteorder = ROAR_BYTEORDER_UNKNOWN; |
---|
| 178 | |
---|
[2517] | 179 | if ( g_clients[id] == NULL ) |
---|
| 180 | return -1; |
---|
| 181 | |
---|
[2614] | 182 | switch (proto) { |
---|
| 183 | case ROAR_PROTO_ROARAUDIO: |
---|
| 184 | byteorder = ROAR_BYTEORDER_NETWORK; |
---|
| 185 | break; |
---|
[2619] | 186 | case ROAR_PROTO_ESOUND: |
---|
| 187 | byteorder = ROAR_BYTEORDER_NATIVE; |
---|
| 188 | break; |
---|
[2614] | 189 | } |
---|
| 190 | |
---|
| 191 | g_clients[id]->proto = proto; |
---|
| 192 | g_clients[id]->byteorder = byteorder; |
---|
[2517] | 193 | |
---|
| 194 | return 0; |
---|
| 195 | } |
---|
| 196 | |
---|
[498] | 197 | #define MAX_STREAMLESS 8 |
---|
| 198 | |
---|
[0] | 199 | int clients_check_all (void) { |
---|
[1480] | 200 | #ifdef ROAR_HAVE_SELECT |
---|
[0] | 201 | struct timeval tv; |
---|
| 202 | fd_set r, e; |
---|
[66] | 203 | int i, j; |
---|
[0] | 204 | int ret; |
---|
| 205 | int fh; |
---|
| 206 | int max_fh = -1; |
---|
[71] | 207 | int have = 0; |
---|
[498] | 208 | struct { |
---|
| 209 | int id; |
---|
| 210 | int fh; |
---|
| 211 | } streamless[MAX_STREAMLESS]; |
---|
| 212 | int have_streamless = 0; |
---|
| 213 | int have_stream; |
---|
[0] | 214 | |
---|
| 215 | FD_ZERO(&r); |
---|
| 216 | FD_ZERO(&e); |
---|
| 217 | |
---|
| 218 | tv.tv_sec = 0; |
---|
| 219 | tv.tv_usec = 1; |
---|
| 220 | |
---|
| 221 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 222 | if ( g_clients[i] == NULL ) |
---|
| 223 | continue; |
---|
| 224 | |
---|
[66] | 225 | if ( (fh = g_clients[i]->fh) != -1 ) { |
---|
[71] | 226 | have++; |
---|
| 227 | |
---|
[610] | 228 | ROAR_DBG("clients_check_all(*): fh=%i", fh); |
---|
| 229 | |
---|
[66] | 230 | FD_SET(fh, &r); |
---|
| 231 | FD_SET(fh, &e); |
---|
| 232 | |
---|
| 233 | if ( fh > max_fh ) |
---|
| 234 | max_fh = fh; |
---|
[84] | 235 | } |
---|
[0] | 236 | |
---|
[498] | 237 | have_stream = 0; |
---|
| 238 | |
---|
[84] | 239 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
| 240 | if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2598] | 241 | ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, g_clients[i]->streams[j], fh); |
---|
[1504] | 242 | if ( fh > -1 ) { |
---|
| 243 | FD_SET(fh, &r); |
---|
[0] | 244 | |
---|
[1504] | 245 | if ( fh > max_fh ) |
---|
| 246 | max_fh = fh; |
---|
| 247 | } |
---|
[498] | 248 | |
---|
| 249 | have_stream = 1; |
---|
[66] | 250 | } |
---|
[84] | 251 | //printf("D: client=%i, stream=%i, fh=%i\n", i, j, fh); |
---|
[66] | 252 | } |
---|
| 253 | |
---|
[498] | 254 | if ( !have_stream && have_streamless < MAX_STREAMLESS ) { |
---|
| 255 | streamless[have_streamless ].id = i; |
---|
| 256 | if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 ) |
---|
| 257 | have_streamless--; |
---|
| 258 | } |
---|
[0] | 259 | } |
---|
| 260 | |
---|
[256] | 261 | if ( max_fh == -1 ) |
---|
| 262 | return 0; |
---|
| 263 | |
---|
[0] | 264 | if ( (ret = select(max_fh + 1, &r, NULL, &e, &tv)) < 1 ) { |
---|
[71] | 265 | return ret < 0 ? ret : have; |
---|
[0] | 266 | } |
---|
| 267 | |
---|
| 268 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 269 | if ( g_clients[i] == NULL ) |
---|
| 270 | continue; |
---|
| 271 | |
---|
[66] | 272 | if ( (fh = g_clients[i]->fh) != -1 ) { |
---|
| 273 | if ( FD_ISSET(fh, &r) ) { |
---|
| 274 | if ( g_clients[i]->execed == -1 ) { |
---|
| 275 | clients_check(i); |
---|
[1835] | 276 | if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) { |
---|
[1834] | 277 | FD_CLR(fh, &r); |
---|
| 278 | } |
---|
[255] | 279 | /* |
---|
[66] | 280 | } else { |
---|
| 281 | streams_check(g_clients[i]->execed); |
---|
[255] | 282 | */ |
---|
[66] | 283 | } |
---|
| 284 | } |
---|
[0] | 285 | |
---|
[84] | 286 | if ( FD_ISSET(fh, &e) ) { |
---|
[66] | 287 | clients_delete(i); |
---|
[84] | 288 | continue; |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | if ( g_clients[i] == NULL ) |
---|
| 293 | continue; |
---|
| 294 | |
---|
| 295 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[1611] | 296 | ROAR_DBG("clients_check_all(*): D: client=%i, stream=%i, g_clients[i=%i] = %p", i, j, i, g_clients[i]); |
---|
[136] | 297 | if ( g_clients[i] == NULL ) // streams_check() bellow can delete our client (why?) |
---|
| 298 | break; |
---|
[1611] | 299 | |
---|
| 300 | //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); |
---|
| 301 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]); |
---|
| 302 | |
---|
[84] | 303 | if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[1611] | 304 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); |
---|
[1504] | 305 | if ( fh == -2 ) { |
---|
| 306 | streams_check(g_clients[i]->streams[j]); |
---|
| 307 | } else if ( FD_ISSET(fh, &r) ) { |
---|
[84] | 308 | streams_check(g_clients[i]->streams[j]); |
---|
[66] | 309 | } |
---|
[0] | 310 | } |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
[498] | 314 | if ( have_streamless ) { |
---|
| 315 | FD_ZERO(&r); |
---|
| 316 | |
---|
| 317 | tv.tv_sec = 0; |
---|
| 318 | tv.tv_usec = 1; |
---|
| 319 | |
---|
| 320 | max_fh = -1; |
---|
| 321 | |
---|
| 322 | for (i = 0; i < have_streamless; i++) { |
---|
[607] | 323 | if ( ! g_clients[j = streamless[i].id] ) |
---|
| 324 | continue; |
---|
| 325 | |
---|
| 326 | if ( g_clients[j]->execed != -1 ) |
---|
[601] | 327 | continue; |
---|
| 328 | |
---|
[498] | 329 | fh = streamless[i].fh; |
---|
| 330 | |
---|
| 331 | ROAR_DBG("clients_check_all(void): fh=%i", fh); |
---|
| 332 | FD_SET(fh, &r); |
---|
| 333 | |
---|
| 334 | if ( fh > max_fh ) |
---|
| 335 | max_fh = fh; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | if ( (ret = select(max_fh + 1, &r, NULL, NULL, &tv)) < 0 ) { |
---|
| 339 | return ret; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | for (i = 0; i < have_streamless; i++) { |
---|
| 343 | if ( FD_ISSET(streamless[i].fh, &r) ) { |
---|
| 344 | clients_check(streamless[i].id); |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | |
---|
[71] | 349 | ROAR_DBG("clients_check_all(void) = %i // have value", have); |
---|
| 350 | return have; |
---|
[1480] | 351 | #else |
---|
| 352 | return -1; |
---|
| 353 | #endif |
---|
[0] | 354 | } |
---|
| 355 | |
---|
| 356 | int clients_check (int id) { |
---|
| 357 | struct roar_message m; |
---|
| 358 | struct roar_connection con; |
---|
| 359 | char * data = NULL; |
---|
| 360 | int oldcmd; |
---|
| 361 | int r; |
---|
[498] | 362 | int rv = 0; |
---|
[0] | 363 | |
---|
| 364 | if ( g_clients[id] == NULL ) |
---|
| 365 | return -1; |
---|
| 366 | if ( g_clients[id]->fh == -1 ) |
---|
| 367 | return -1; |
---|
| 368 | |
---|
[1662] | 369 | roar_connect_fh(&con, g_clients[id]->fh); |
---|
[0] | 370 | |
---|
[2517] | 371 | switch (g_clients[id]->proto) { |
---|
| 372 | case ROAR_PROTO_ROARAUDIO: |
---|
| 373 | r = roar_recv_message(&con, &m, &data); |
---|
[0] | 374 | |
---|
[2517] | 375 | if ( r == -1 ) { // should we drop the client? |
---|
| 376 | clients_delete(id); |
---|
| 377 | return -1; |
---|
| 378 | } |
---|
[0] | 379 | |
---|
[2517] | 380 | roar_debug_message_print(&m); |
---|
[0] | 381 | |
---|
[2517] | 382 | oldcmd = m.cmd; |
---|
[0] | 383 | |
---|
[2517] | 384 | if ( (r = command_exec(id, &m, data)) == -1 ) { |
---|
| 385 | m.cmd = ROAR_CMD_ERROR; |
---|
| 386 | m.datalen = 0; |
---|
| 387 | ROAR_DBG("clients_check(*): Exec of command faild!"); |
---|
| 388 | } else { |
---|
| 389 | if ( m.cmd == oldcmd ) { |
---|
| 390 | m.cmd = ROAR_CMD_OK; |
---|
| 391 | m.datalen = 0; |
---|
| 392 | } else if ( m.cmd == ROAR_CMD_OK_STOP ) { |
---|
| 393 | m.cmd = ROAR_CMD_OK; |
---|
| 394 | rv = 1; |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | roar_send_message(&con, &m, NULL); |
---|
| 399 | break; |
---|
[2546] | 400 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD |
---|
[2791] | 401 | #ifdef ROAR_HAVE_H_ESD |
---|
[2523] | 402 | case ROAR_PROTO_ESOUND: |
---|
| 403 | rv = emul_esd_check_client(id, NULL); |
---|
| 404 | break; |
---|
[2546] | 405 | #endif |
---|
| 406 | #endif |
---|
[2517] | 407 | default: |
---|
| 408 | rv = -1; |
---|
[0] | 409 | } |
---|
| 410 | |
---|
| 411 | if ( data ) |
---|
| 412 | free(data); |
---|
| 413 | |
---|
[2517] | 414 | ROAR_DBG("clients_check(id=%i) = %i", id, rv); |
---|
[498] | 415 | return rv; |
---|
[0] | 416 | } |
---|
| 417 | |
---|
| 418 | int clients_send_mon (struct roar_audio_info * sa, uint32_t pos) { |
---|
| 419 | int i; |
---|
[934] | 420 | // int fh; |
---|
| 421 | int j; |
---|
[2715] | 422 | int keep_going; |
---|
[0] | 423 | |
---|
| 424 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 425 | if ( g_clients[i] == NULL ) |
---|
| 426 | continue; |
---|
| 427 | |
---|
[2715] | 428 | keep_going = 1; |
---|
| 429 | |
---|
[934] | 430 | /* |
---|
[0] | 431 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 432 | continue; |
---|
[934] | 433 | */ |
---|
[0] | 434 | |
---|
[1905] | 435 | ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed); |
---|
| 436 | |
---|
[2706] | 437 | /* |
---|
[0] | 438 | if ( g_clients[i]->execed == -1 ) { |
---|
| 439 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
[2706] | 440 | */ |
---|
[2715] | 441 | for (j = 0; keep_going && j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[934] | 442 | //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2715] | 443 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); |
---|
[1905] | 444 | if ( g_clients[i]->streams[j] != -1 ) { |
---|
| 445 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]); |
---|
[934] | 446 | streams_send_mon(g_clients[i]->streams[j]); |
---|
[2715] | 447 | |
---|
| 448 | // the client may be deleted here, check if it still exists: |
---|
| 449 | if ( g_clients[i] == NULL ) |
---|
| 450 | keep_going = 0; |
---|
[1905] | 451 | } |
---|
[934] | 452 | } |
---|
[2706] | 453 | /* |
---|
[0] | 454 | } else { |
---|
| 455 | // streams_check(g_clients[i]->execed); |
---|
| 456 | streams_send_mon(g_clients[i]->execed); |
---|
| 457 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 458 | // clients_delete(i); // delete client in case we could not write |
---|
| 459 | } |
---|
[2706] | 460 | */ |
---|
[0] | 461 | } |
---|
| 462 | |
---|
[1902] | 463 | // TODO: FIXME: should this really be -1? |
---|
[0] | 464 | return -1; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { |
---|
| 468 | int i; |
---|
| 469 | int fh; |
---|
| 470 | |
---|
| 471 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 472 | if ( g_clients[i] == NULL ) |
---|
| 473 | continue; |
---|
| 474 | |
---|
| 475 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 476 | continue; |
---|
| 477 | |
---|
| 478 | if ( g_clients[i]->execed == -1 ) { |
---|
| 479 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
| 480 | } else { |
---|
| 481 | // streams_check(g_clients[i]->execed); |
---|
| 482 | streams_send_filter(g_clients[i]->execed); |
---|
| 483 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 484 | // clients_delete(i); // delete client in case we could not write |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | return -1; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | int client_stream_exec (int client, int stream) { |
---|
| 492 | int i; |
---|
| 493 | |
---|
[1901] | 494 | if ( g_clients[client] == NULL ) { |
---|
| 495 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream); |
---|
[0] | 496 | return -1; |
---|
[1901] | 497 | } |
---|
[0] | 498 | |
---|
| 499 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 500 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 501 | g_clients[client]->execed = stream; |
---|
| 502 | streams_set_fh(stream, g_clients[client]->fh); |
---|
[378] | 503 | streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); |
---|
[2815] | 504 | ROAR_DBG("client_stream_exec(client=%i, stream=%i) = 0", client, stream); |
---|
[0] | 505 | return 0; |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | |
---|
[1901] | 509 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not own stream", client, stream); |
---|
[0] | 510 | return -1; |
---|
| 511 | } |
---|
| 512 | |
---|
[78] | 513 | int client_stream_set_fh (int client, int stream, int fh) { |
---|
| 514 | int i; |
---|
| 515 | |
---|
| 516 | if ( g_clients[client] == NULL ) |
---|
| 517 | return -1; |
---|
| 518 | |
---|
| 519 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 520 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 521 | streams_set_fh(stream, fh); |
---|
| 522 | return 0; |
---|
| 523 | } |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | return -1; |
---|
| 527 | } |
---|
| 528 | |
---|
[0] | 529 | int client_stream_add (int client, int stream) { |
---|
| 530 | int i; |
---|
| 531 | |
---|
| 532 | if ( g_clients[client] == NULL ) |
---|
| 533 | return -1; |
---|
| 534 | |
---|
| 535 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 536 | if ( g_clients[client]->streams[i] == -1 ) { |
---|
| 537 | g_clients[client]->streams[i] = stream; |
---|
| 538 | streams_set_client(stream, client); |
---|
| 539 | return 0; |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | return -1; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | int client_stream_delete (int client, int stream) { |
---|
| 547 | int i; |
---|
| 548 | |
---|
| 549 | if ( g_clients[client] == NULL ) |
---|
| 550 | return -1; |
---|
| 551 | |
---|
| 552 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 553 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 554 | g_clients[client]->streams[i] = -1; |
---|
| 555 | |
---|
| 556 | if ( stream == g_clients[client]->execed ) { |
---|
| 557 | ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); |
---|
| 558 | clients_delete(client); |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = 0", client, stream); |
---|
| 562 | return 0; |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = -1", client, stream); |
---|
| 567 | return -1; |
---|
| 568 | } |
---|
| 569 | |
---|
[767] | 570 | int client_stream_move (int client, int stream) { |
---|
| 571 | int old_client = streams_get_client(stream); |
---|
| 572 | |
---|
[771] | 573 | ROAR_DBG("client_stream_move(client=%i, stream=%i): old_client = %i", client, stream, old_client); |
---|
| 574 | |
---|
[767] | 575 | if ( old_client != -1 ) |
---|
| 576 | if ( client_stream_delete(old_client, stream) == -1 ) |
---|
| 577 | return -1; |
---|
| 578 | |
---|
| 579 | return client_stream_add(client, stream); |
---|
| 580 | } |
---|
| 581 | |
---|
[0] | 582 | //ll |
---|