source: roaraudio/roard/clients.c @ 5576:a98545bcc3f1

Last change on this file since 5576:a98545bcc3f1 was 5576:a98545bcc3f1, checked in by phi, 12 years ago

Support a common protocol interface (Closes: #257)

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