[0] | 1 | //clients.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[3358] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[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 | |
---|
[0] | 26 | #include "roard.h" |
---|
| 27 | |
---|
| 28 | int clients_init (void) { |
---|
| 29 | int i; |
---|
| 30 | |
---|
| 31 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 32 | g_clients[i] = NULL; |
---|
| 33 | |
---|
| 34 | return 0; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int clients_free (void) { |
---|
| 38 | int i; |
---|
| 39 | |
---|
| 40 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) |
---|
| 41 | if ( g_clients[i] ) |
---|
| 42 | clients_delete(i); |
---|
| 43 | |
---|
| 44 | return 0; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | int clients_new (void) { |
---|
| 48 | int i; |
---|
| 49 | int s; |
---|
| 50 | struct roar_client * n; |
---|
| 51 | |
---|
| 52 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 53 | if ( g_clients[i] == NULL ) { |
---|
[3063] | 54 | n = roar_mm_malloc(sizeof(struct roar_client)); |
---|
[0] | 55 | if ( n != NULL ) { |
---|
| 56 | n->pid = -1; |
---|
[437] | 57 | n->uid = -1; |
---|
| 58 | n->gid = -1; |
---|
[0] | 59 | n->fh = -1; |
---|
| 60 | |
---|
| 61 | *n->name = 0; |
---|
| 62 | *n->host = 0; |
---|
| 63 | |
---|
[2614] | 64 | n->proto = ROAR_PROTO_ROARAUDIO; |
---|
| 65 | n->byteorder = ROAR_BYTEORDER_NETWORK; |
---|
[2517] | 66 | |
---|
[346] | 67 | n->acl = NULL; |
---|
| 68 | |
---|
[0] | 69 | n->execed = -1; |
---|
| 70 | for (s = 0; s < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; s++) |
---|
| 71 | n->streams[s] = -1; |
---|
| 72 | |
---|
[2815] | 73 | if ( roar_nnode_new(&(n->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) { |
---|
[3063] | 74 | roar_mm_free(n); |
---|
[2815] | 75 | return -1; |
---|
| 76 | } |
---|
| 77 | |
---|
[0] | 78 | g_clients[i] = n; |
---|
| 79 | |
---|
| 80 | ROAR_DBG("clients_new(void) = %i", i); |
---|
| 81 | return i; |
---|
| 82 | } else { |
---|
| 83 | ROAR_ERR("clients_new(void): Can not alloc memory for new client: %s", strerror(errno)); |
---|
| 84 | ROAR_ERR("clients_new(void) = -1"); |
---|
| 85 | return -1; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | return -1; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | int clients_delete (int id) { |
---|
| 94 | int i; |
---|
[1164] | 95 | int close_client_fh = 1; |
---|
[0] | 96 | |
---|
[2608] | 97 | ROAR_DBG("clients_delete(id=%i) = ?", id); |
---|
| 98 | |
---|
[0] | 99 | if ( g_clients[id] == NULL ) |
---|
| 100 | return -1; |
---|
| 101 | |
---|
| 102 | if (g_clients[id]->execed != -1) { |
---|
| 103 | // return streams_delete(g_clients[id]->execed); |
---|
| 104 | g_clients[id]->execed = -1; |
---|
[1164] | 105 | close_client_fh = 0; |
---|
[0] | 106 | } |
---|
| 107 | |
---|
| 108 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 109 | streams_delete(g_clients[id]->streams[i]); |
---|
| 110 | } |
---|
| 111 | |
---|
[1164] | 112 | if ( g_clients[id]->fh != -1 && close_client_fh ) |
---|
[0] | 113 | close(g_clients[id]->fh); |
---|
| 114 | |
---|
[2815] | 115 | roar_nnode_free(&(g_clients[id]->nnode)); |
---|
| 116 | |
---|
[3063] | 117 | roar_mm_free(g_clients[id]); |
---|
[0] | 118 | g_clients[id] = NULL; |
---|
| 119 | |
---|
| 120 | ROAR_DBG("clients_delete(id=%i) = 0", id); |
---|
| 121 | return 0; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | int clients_get (int id, struct roar_client ** client) { |
---|
| 125 | *client = g_clients[id]; |
---|
| 126 | |
---|
| 127 | if ( *client == NULL ) |
---|
| 128 | return -1; |
---|
| 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | int clients_set_fh (int id, int fh) { |
---|
[501] | 134 | |
---|
[0] | 135 | if ( g_clients[id] == NULL ) |
---|
| 136 | return -1; |
---|
| 137 | |
---|
| 138 | g_clients[id]->fh = fh; |
---|
| 139 | |
---|
| 140 | return 0; |
---|
| 141 | } |
---|
| 142 | |
---|
[755] | 143 | int clients_get_fh (int id) { |
---|
| 144 | if ( g_clients[id] == NULL ) |
---|
| 145 | return -1; |
---|
| 146 | |
---|
| 147 | return g_clients[id]->fh; |
---|
| 148 | } |
---|
| 149 | |
---|
[0] | 150 | int clients_set_pid (int id, int pid) { |
---|
| 151 | if ( g_clients[id] == NULL ) |
---|
| 152 | return -1; |
---|
| 153 | |
---|
| 154 | g_clients[id]->pid = pid; |
---|
| 155 | |
---|
| 156 | return 0; |
---|
| 157 | } |
---|
| 158 | |
---|
[439] | 159 | int clients_set_uid (int id, int uid) { |
---|
| 160 | if ( g_clients[id] == NULL ) |
---|
| 161 | return -1; |
---|
| 162 | |
---|
| 163 | g_clients[id]->uid = uid; |
---|
| 164 | |
---|
| 165 | return 0; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | int clients_set_gid (int id, int gid) { |
---|
| 169 | if ( g_clients[id] == NULL ) |
---|
| 170 | return -1; |
---|
| 171 | |
---|
| 172 | g_clients[id]->gid = gid; |
---|
| 173 | |
---|
| 174 | return 0; |
---|
| 175 | } |
---|
| 176 | |
---|
[2517] | 177 | int clients_set_proto (int id, int proto) { |
---|
[2614] | 178 | int byteorder = ROAR_BYTEORDER_UNKNOWN; |
---|
| 179 | |
---|
[2517] | 180 | if ( g_clients[id] == NULL ) |
---|
| 181 | return -1; |
---|
| 182 | |
---|
[2614] | 183 | switch (proto) { |
---|
| 184 | case ROAR_PROTO_ROARAUDIO: |
---|
[2828] | 185 | case ROAR_PROTO_ESOUND: |
---|
[3255] | 186 | case ROAR_PROTO_SIMPLE: |
---|
[2614] | 187 | byteorder = ROAR_BYTEORDER_NETWORK; |
---|
| 188 | break; |
---|
| 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; |
---|
[3579] | 247 | } else if ( fh == -2 ) { |
---|
| 248 | streams_check(g_clients[i]->streams[j]); |
---|
[1504] | 249 | } |
---|
[498] | 250 | |
---|
| 251 | have_stream = 1; |
---|
[66] | 252 | } |
---|
[84] | 253 | //printf("D: client=%i, stream=%i, fh=%i\n", i, j, fh); |
---|
[66] | 254 | } |
---|
| 255 | |
---|
[498] | 256 | if ( !have_stream && have_streamless < MAX_STREAMLESS ) { |
---|
| 257 | streamless[have_streamless ].id = i; |
---|
| 258 | if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 ) |
---|
| 259 | have_streamless--; |
---|
| 260 | } |
---|
[0] | 261 | } |
---|
| 262 | |
---|
[256] | 263 | if ( max_fh == -1 ) |
---|
| 264 | return 0; |
---|
| 265 | |
---|
[0] | 266 | if ( (ret = select(max_fh + 1, &r, NULL, &e, &tv)) < 1 ) { |
---|
[71] | 267 | return ret < 0 ? ret : have; |
---|
[0] | 268 | } |
---|
| 269 | |
---|
| 270 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 271 | if ( g_clients[i] == NULL ) |
---|
| 272 | continue; |
---|
| 273 | |
---|
[66] | 274 | if ( (fh = g_clients[i]->fh) != -1 ) { |
---|
| 275 | if ( FD_ISSET(fh, &r) ) { |
---|
| 276 | if ( g_clients[i]->execed == -1 ) { |
---|
| 277 | clients_check(i); |
---|
[1835] | 278 | if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) { |
---|
[1834] | 279 | FD_CLR(fh, &r); |
---|
| 280 | } |
---|
[255] | 281 | /* |
---|
[66] | 282 | } else { |
---|
| 283 | streams_check(g_clients[i]->execed); |
---|
[255] | 284 | */ |
---|
[66] | 285 | } |
---|
| 286 | } |
---|
[0] | 287 | |
---|
[84] | 288 | if ( FD_ISSET(fh, &e) ) { |
---|
[66] | 289 | clients_delete(i); |
---|
[84] | 290 | continue; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | if ( g_clients[i] == NULL ) |
---|
| 295 | continue; |
---|
| 296 | |
---|
| 297 | for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[1611] | 298 | ROAR_DBG("clients_check_all(*): D: client=%i, stream=%i, g_clients[i=%i] = %p", i, j, i, g_clients[i]); |
---|
[136] | 299 | if ( g_clients[i] == NULL ) // streams_check() bellow can delete our client (why?) |
---|
| 300 | break; |
---|
[1611] | 301 | |
---|
| 302 | //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); |
---|
| 303 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]); |
---|
| 304 | |
---|
[84] | 305 | if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[1611] | 306 | ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); |
---|
[3579] | 307 | if ( fh > -1 && 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 |
---|
[3684] | 407 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD |
---|
| 408 | case ROAR_PROTO_RSOUND: |
---|
| 409 | rv = clients_delete(id); |
---|
| 410 | break; |
---|
| 411 | #endif |
---|
[2517] | 412 | default: |
---|
| 413 | rv = -1; |
---|
[0] | 414 | } |
---|
| 415 | |
---|
| 416 | if ( data ) |
---|
| 417 | free(data); |
---|
| 418 | |
---|
[2517] | 419 | ROAR_DBG("clients_check(id=%i) = %i", id, rv); |
---|
[498] | 420 | return rv; |
---|
[0] | 421 | } |
---|
| 422 | |
---|
| 423 | int clients_send_mon (struct roar_audio_info * sa, uint32_t pos) { |
---|
| 424 | int i; |
---|
[934] | 425 | // int fh; |
---|
| 426 | int j; |
---|
[2715] | 427 | int keep_going; |
---|
[0] | 428 | |
---|
| 429 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 430 | if ( g_clients[i] == NULL ) |
---|
| 431 | continue; |
---|
| 432 | |
---|
[2715] | 433 | keep_going = 1; |
---|
| 434 | |
---|
[934] | 435 | /* |
---|
[0] | 436 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 437 | continue; |
---|
[934] | 438 | */ |
---|
[0] | 439 | |
---|
[1905] | 440 | ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed); |
---|
| 441 | |
---|
[2706] | 442 | /* |
---|
[0] | 443 | if ( g_clients[i]->execed == -1 ) { |
---|
| 444 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
[2706] | 445 | */ |
---|
[2715] | 446 | for (j = 0; keep_going && j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { |
---|
[934] | 447 | //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { |
---|
[2715] | 448 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); |
---|
[1905] | 449 | if ( g_clients[i]->streams[j] != -1 ) { |
---|
| 450 | ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]); |
---|
[934] | 451 | streams_send_mon(g_clients[i]->streams[j]); |
---|
[2715] | 452 | |
---|
| 453 | // the client may be deleted here, check if it still exists: |
---|
| 454 | if ( g_clients[i] == NULL ) |
---|
| 455 | keep_going = 0; |
---|
[1905] | 456 | } |
---|
[934] | 457 | } |
---|
[2706] | 458 | /* |
---|
[0] | 459 | } else { |
---|
| 460 | // streams_check(g_clients[i]->execed); |
---|
| 461 | streams_send_mon(g_clients[i]->execed); |
---|
| 462 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 463 | // clients_delete(i); // delete client in case we could not write |
---|
| 464 | } |
---|
[2706] | 465 | */ |
---|
[0] | 466 | } |
---|
| 467 | |
---|
[1902] | 468 | // TODO: FIXME: should this really be -1? |
---|
[0] | 469 | return -1; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { |
---|
| 473 | int i; |
---|
| 474 | int fh; |
---|
| 475 | |
---|
| 476 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 477 | if ( g_clients[i] == NULL ) |
---|
| 478 | continue; |
---|
| 479 | |
---|
| 480 | if ( (fh = g_clients[i]->fh) == -1 ) |
---|
| 481 | continue; |
---|
| 482 | |
---|
| 483 | if ( g_clients[i]->execed == -1 ) { |
---|
| 484 | // TODO: add some code to send a message to the client insetd of the raw data. |
---|
| 485 | } else { |
---|
| 486 | // streams_check(g_clients[i]->execed); |
---|
| 487 | streams_send_filter(g_clients[i]->execed); |
---|
| 488 | // if ( streams_send_mon(g_clients[i]->execed) == -1 ) |
---|
| 489 | // clients_delete(i); // delete client in case we could not write |
---|
| 490 | } |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | return -1; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | int client_stream_exec (int client, int stream) { |
---|
| 497 | int i; |
---|
| 498 | |
---|
[1901] | 499 | if ( g_clients[client] == NULL ) { |
---|
| 500 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream); |
---|
[0] | 501 | return -1; |
---|
[1901] | 502 | } |
---|
[0] | 503 | |
---|
| 504 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 505 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 506 | g_clients[client]->execed = stream; |
---|
| 507 | streams_set_fh(stream, g_clients[client]->fh); |
---|
[378] | 508 | streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); |
---|
[2815] | 509 | ROAR_DBG("client_stream_exec(client=%i, stream=%i) = 0", client, stream); |
---|
[0] | 510 | return 0; |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
[1901] | 514 | ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not own stream", client, stream); |
---|
[0] | 515 | return -1; |
---|
| 516 | } |
---|
| 517 | |
---|
[78] | 518 | int client_stream_set_fh (int client, int stream, int fh) { |
---|
| 519 | int i; |
---|
| 520 | |
---|
| 521 | if ( g_clients[client] == NULL ) |
---|
| 522 | return -1; |
---|
| 523 | |
---|
| 524 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 525 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 526 | streams_set_fh(stream, fh); |
---|
| 527 | return 0; |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | return -1; |
---|
| 532 | } |
---|
| 533 | |
---|
[0] | 534 | int client_stream_add (int client, int stream) { |
---|
| 535 | int i; |
---|
| 536 | |
---|
| 537 | if ( g_clients[client] == NULL ) |
---|
| 538 | return -1; |
---|
| 539 | |
---|
| 540 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 541 | if ( g_clients[client]->streams[i] == -1 ) { |
---|
| 542 | g_clients[client]->streams[i] = stream; |
---|
| 543 | streams_set_client(stream, client); |
---|
| 544 | return 0; |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | return -1; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | int client_stream_delete (int client, int stream) { |
---|
| 552 | int i; |
---|
| 553 | |
---|
| 554 | if ( g_clients[client] == NULL ) |
---|
| 555 | return -1; |
---|
| 556 | |
---|
| 557 | for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { |
---|
| 558 | if ( g_clients[client]->streams[i] == stream ) { |
---|
| 559 | g_clients[client]->streams[i] = -1; |
---|
| 560 | |
---|
| 561 | if ( stream == g_clients[client]->execed ) { |
---|
| 562 | ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); |
---|
| 563 | clients_delete(client); |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = 0", client, stream); |
---|
| 567 | return 0; |
---|
| 568 | } |
---|
| 569 | } |
---|
| 570 | |
---|
| 571 | ROAR_DBG("client_stream_delete(client=%i, stream=%i) = -1", client, stream); |
---|
| 572 | return -1; |
---|
| 573 | } |
---|
| 574 | |
---|
[767] | 575 | int client_stream_move (int client, int stream) { |
---|
| 576 | int old_client = streams_get_client(stream); |
---|
| 577 | |
---|
[771] | 578 | ROAR_DBG("client_stream_move(client=%i, stream=%i): old_client = %i", client, stream, old_client); |
---|
| 579 | |
---|
[767] | 580 | if ( old_client != -1 ) |
---|
| 581 | if ( client_stream_delete(old_client, stream) == -1 ) |
---|
| 582 | return -1; |
---|
| 583 | |
---|
| 584 | return client_stream_add(client, stream); |
---|
| 585 | } |
---|
| 586 | |
---|
[0] | 587 | //ll |
---|