source: roaraudio/libroar/basic.c @ 5792:bfe694357a8a

Last change on this file since 5792:bfe694357a8a was 5792:bfe694357a8a, checked in by phi, 11 years ago

hopefully fix win32 bug with execed workaround

File size: 18.8 KB
Line 
1//basic.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
5 *
6 *  This file is part of libroar 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 *  libroar 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 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38static int _start_server(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) {
39#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
40 enum {
41  NORMAL = 0,
42  SYSTEM = 1
43 } mode = NORMAL;
44 const char * daemonimage = NULL;
45 int socks[2];
46 int r;
47 char fhstr[12];
48
49 if ( !strncmp(server, "+fork=", 6) ) {
50  server += 6;
51  if ( server[0] == 0 ) {
52   // no special case, we just ignore it.
53  } else if ( server[0] == 'd' && server[1] == ':' ) {
54   server += 2;
55   daemonimage = server;
56  } else if ( server[0] == '!' ) {
57   server += 1;
58   daemonimage = server;
59   mode = SYSTEM;
60  } else {
61   roar_err_set(ROAR_ERROR_ILLSEQ);
62   return -1;
63  }
64 }
65
66 if ( daemonimage == NULL )
67  daemonimage = roar_libroar_get_config()->daemonimage;
68
69 // we keep this step to be compatible with older versions.
70 if ( daemonimage == NULL || *daemonimage == 0 ) {
71  daemonimage = roar_env_get("ROAR_DAEMONIMAGE");
72  if ( daemonimage != NULL ) {
73   ROAR_WARN("_start_server(*): Usage of $ROAR_DAEMONIMAGE is obsolete. Use ROAR_OPTIONS=daemonimage:...");
74  }
75 }
76
77 if ( daemonimage == NULL || *daemonimage == 0 )
78  daemonimage = "roard";
79
80 if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) {
81  roar_err_from_errno();
82  return -1;
83 }
84
85 r = roar_fork(NULL);
86
87 if ( r == -1 ) { // error!
88  ROAR_ERR("_start_server(*): Can not fork: %s", roar_error2str(roar_error));
89  close(socks[0]);
90  close(socks[1]);
91  return -1;
92 } else if ( r == 0 ) { // we are the child
93  roar_watchdog_stop();
94
95  close(socks[0]);
96
97  close(ROAR_STDIN ); // we do not want roard to have any standard input
98  close(ROAR_STDOUT); // STDOUT is also not needed, so we close it,
99                      // but STDERR we keep open for error messages.
100
101  snprintf(fhstr, sizeof(fhstr), "%i", socks[1]);
102
103  switch (mode) {
104   case NORMAL:
105     execlp(daemonimage, daemonimage, "--no-listen", "--client-fh", fhstr, (_LIBROAR_GOOD_CAST char*)NULL);
106    break;
107   case SYSTEM:
108     dup2(socks[1], ROAR_STDIN );
109     dup2(socks[1], ROAR_STDOUT);
110     execl("/bin/sh", "/bin/sh", "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL);
111     execlp("sh", "sh", "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL);
112    break;
113  }
114
115  // we are still alive?
116  ROAR_ERR("_start_server(*): alive after exec(), that's bad!");
117  ROAR_U_EXIT(1);
118 } else { // we are the parent
119  close(socks[1]);
120  if ( roar_vio_open_fh_socket(con->viocon, socks[0]) == -1 ) {
121   close(socks[0]);
122   return -1;
123  } else {
124   con->flags |= ROAR_CON_FLAGS_VIO;
125  }
126  return 0;
127 }
128
129 return -1;
130#else
131 ROAR_ERR("_start_server(*): There is no UNIX Domain Socket support in win32, download a real OS.");
132 return -1;
133#endif
134}
135
136static int _connect_internal(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) {
137 struct roar_libroar_config * config = roar_libroar_get_config();
138 struct roar_vio_calls * vio;
139
140 if ( config->connect_internal != NULL ) {
141  vio = config->connect_internal(con, server, type, flags, timeout);
142  if ( vio == NULL )
143   return -1;
144
145  con->viocon = vio;
146  con->flags |= ROAR_CON_FLAGS_VIO;
147
148  return 0;
149 }
150
151 roar_err_set(ROAR_ERROR_BADHOST);
152 return -1;
153}
154
155static int _connect_server(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) {
156#if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT)
157 struct stat sockstat;
158#endif
159 const char * obj = NULL;
160 char user_sock[128];
161 int is_decnet = 0;
162 int port = 0;
163 int i = 0;
164 int fh = -1;
165 int err;
166
167 if ( con == NULL || server == NULL ) {
168  roar_err_set(ROAR_ERROR_FAULT);
169  return -1;
170 }
171
172 if ( !strcmp(server, "+invalid") ) {
173  roar_err_set(ROAR_ERROR_CANCELED);
174  return -1;
175 } else if ( !strncmp(server, "+dstr=", 6) ) {
176  if ( roar_vio_open_dstr_simple(con->viocon, server+6, ROAR_VIOF_READWRITE) == -1 )
177   return -1;
178  con->flags |= ROAR_CON_FLAGS_VIO;
179  return 0;
180 } else if ( !strcmp(server, "+fork") || !strncmp(server, "+fork=", 6) ) {
181  return _start_server(con, server, type, flags, timeout);
182 } else if ( !strcmp(server, "+internal") || !strncmp(server, "+internal=", 10) ) {
183  return _connect_internal(con, server, type, flags, timeout);
184 }
185
186 strncpy(user_sock, server, sizeof(user_sock)-1);
187 user_sock[sizeof(user_sock)-1] = 0;
188
189
190 if ( *user_sock != '/' ) { // don't test AF_UNIX sockets for ports
191  for (i = 0; user_sock[i] != 0; i++) {
192   if ( user_sock[i] == ':' ) {
193    if ( user_sock[i+1] == ':' ) { // DECnet, leave unchanged
194     is_decnet = 1;
195     obj = &user_sock[i+2];
196     break;
197    }
198
199    port = atoi(&(user_sock[i+1]));
200    user_sock[i] = 0;
201    break;
202   }
203  }
204 }
205
206 if ( is_decnet ) {
207  if ( *user_sock == ':' ) {
208   if ( roar_socket_get_local_nodename() != NULL ) {
209    strncpy(user_sock, roar_socket_get_local_nodename(), sizeof(user_sock)-1);
210    user_sock[sizeof(user_sock)-1] = 0;
211    roar_mm_strlcat(user_sock, server, sizeof(user_sock)-1);
212    user_sock[sizeof(user_sock)-1] = 0;
213    obj  = strstr(user_sock, "::");
214    obj += 2;
215   }
216  }
217
218  if ( *obj == 0 ) {
219#ifdef DN_MAXOBJL
220   roar_mm_strlcat(user_sock, ROAR_DEFAULT_OBJECT, sizeof(user_sock)-1);
221   user_sock[sizeof(user_sock)-1] = 0;
222#else
223   ROAR_ERR("roar_connect_raw(*): size of DECnet object unknown.");
224#endif
225  }
226   ROAR_DBG("roar_connect_raw(*): user_sock='%s'", user_sock);
227 }
228
229 if ( port || is_decnet ) {
230  fh = roar_socket_connect(type, user_sock, port);
231  // restore the original string
232  user_sock[i] = ':';
233 } else {
234#if defined(ROAR_HAVE_STAT) && defined(ROAR_HAVE_H_SYS_STAT)
235  if ( user_sock[0] == '/' ) {
236   if ( stat(user_sock, &sockstat) == 0 ) {
237    if ( S_ISCHR(sockstat.st_mode) ) {
238#ifdef O_NOCTTY
239     fh = open(user_sock, O_RDWR|O_NOCTTY, 0666);
240#else
241     fh = open(user_sock, O_RDWR, 0666);
242#endif
243    }
244   }
245  }
246#endif
247  if ( fh == -1 )
248   fh = roar_socket_connect(type, user_sock, ROAR_DEFAULT_PORT);
249 }
250
251 if ( fh == -1 )
252  return -1;
253
254 if ( roar_vio_open_fh_socket(con->viocon, fh) == -1 ) {
255  err = roar_error;
256#ifdef ROAR_TARGET_WIN32
257  closesocket(fh);
258#else
259  close(fh);
260#endif
261  roar_error = err;
262  return -1;
263 } else {
264  con->flags |= ROAR_CON_FLAGS_VIO;
265 }
266
267 roar_err_set(ROAR_ERROR_NONE);
268 return 0;
269}
270
271static int roar_connect_raw (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) {
272#ifdef ROAR_HAVE_LIBSLP
273 struct roar_libroar_config * config = roar_libroar_get_config();
274#endif
275#if defined(ROAR_HAVE_UNIX)
276 char user_sock[128];
277 const char * roar_server;
278#endif
279#if defined(ROAR_HAVE_LIBSLP) || !defined(ROAR_TARGET_MICROCONTROLLER)
280 int i = 0;
281#endif
282#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
283 struct passwd * pwd;
284#endif
285#ifdef ROAR_HAVE_LIBDNET
286 struct stat decnet_stat;
287#endif
288#ifdef ROAR_HAVE_LIBX11
289 struct roar_x11_connection * x11con;
290#endif
291#ifdef ROAR_HAVE_LIBSLP
292 struct roar_server * list;
293 int workarounds_store;
294#endif
295
296 roar_err_set(ROAR_ERROR_UNKNOWN);
297
298 if ( timeout != 0 ) {
299  roar_err_set(ROAR_ERROR_INVAL);
300  return -1;
301 }
302
303 if ( flags & ROAR_ENUM_FLAG_HARDNONBLOCK )
304  flags |= ROAR_ENUM_FLAG_NONBLOCK;
305
306
307 if ( server == NULL || *server == 0 )
308  server = roar_libroar_get_server();
309
310 if ( server == NULL || *server == 0 )
311  server = roar_env_get("ROAR_SERVER");
312
313#ifdef ROAR_HAVE_LIBX11
314 if ( server == NULL || *server == 0 ) {
315  if ( (x11con = roar_x11_connect(NULL)) != NULL ) {
316   server = roar_x11_get_prop(x11con, "ROAR_SERVER");
317   roar_x11_disconnect(x11con);
318  }
319 }
320#endif
321
322#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
323 if ( (server == NULL || *server == 0) && (i = readlink("/etc/roarserver", user_sock, sizeof(user_sock)-1)) != -1 ) {
324   user_sock[i] = 0;
325   server = user_sock;
326 }
327#endif
328
329 if ( server != NULL && !strcasecmp(server, "+slp") ) {
330  server = roar_slp_find_roard(0);
331  if ( server == NULL ) {
332   return -1;
333  }
334 }
335
336 // "+default" is an alias for NULL.
337 if ( server != NULL && !strcasecmp(server, "+default") ) {
338  server = NULL;
339 }
340
341 if ( server == NULL || *server == 0 ) {
342  /* connect via defaults */
343
344#ifdef ROAR_HAVE_UNIX
345#ifndef ROAR_TARGET_MICROCONTROLLER
346  roar_server = roar_env_get("HOME");
347#else
348  roar_server = NULL;
349#endif
350
351  if ( roar_server == NULL ) {
352#if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
353   if ( (pwd = getpwuid(getuid())) == NULL ) {
354    roar_server = "/NX-HOME-DIR";
355   } else {
356    roar_server = pwd->pw_dir;
357   }
358#else
359   roar_server = "/WIN32-SUCKS";
360#endif
361  }
362
363  snprintf(user_sock, sizeof(user_sock)-1, "%s/%s", roar_server, ROAR_DEFAULT_SOCK_USER);
364  user_sock[sizeof(user_sock)-1] = 0;
365
366  if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 )
367   return 0;
368
369  if ( _connect_server(con, ROAR_DEFAULT_SOCK_GLOBAL, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 )
370   return 0;
371#endif
372
373  if ( _connect_server(con, ROAR_DEFAULT_HOSTPORT, ROAR_SOCKET_TYPE_TCP, flags, timeout) == 0 )
374   return 0;
375
376#ifdef ROAR_HAVE_LIBDNET
377  if ( stat(ROAR_PROC_NET_DECNET, &decnet_stat) == 0 ) {
378   if ( roar_socket_get_local_nodename() ) {
379    snprintf(user_sock, 79, "%s::%s", roar_socket_get_local_nodename(), ROAR_DEFAULT_OBJECT);
380    if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_DECNET, flags, timeout) == 0 )
381     return 0;
382   }
383  }
384#endif
385
386  if ( _connect_server(con, "+abstract", ROAR_SOCKET_TYPE_UNKNOWN, flags, timeout) == 0 )
387   return 0;
388
389#ifdef ROAR_HAVE_LIBSLP
390 if ( !(config->workaround.workarounds & ROAR_LIBROAR_CONFIG_WAS_NO_SLP) &&
391      !(flags & ROAR_ENUM_FLAG_NONBLOCK) &&
392      !(flags & ROAR_ENUM_FLAG_LOCALONLY)
393    ) {
394  if ( (server = roar_slp_find_roard(0)) != NULL ) {
395   if ( _connect_server(con, server, ROAR_SOCKET_TYPE_UNKNOWN, 0, 0) == 0 )
396    return 0;
397
398   /* in case we can not connect to the server given this may be a cache problem,
399      we do a new lookup with the cache disabled in this case                     */
400   ROAR_WARN("roar_connect_raw(*): Can not connect to SLP located server, disabling cache");
401   if ( (server = roar_slp_find_roard(1)) != NULL )
402    if ( _connect_server(con, server, ROAR_SOCKET_TYPE_UNKNOWN, 0, 0) == 0 )
403     return 0;
404  }
405 }
406
407 workarounds_store = config->workaround.workarounds;
408 config->workaround.workarounds |= ROAR_LIBROAR_CONFIG_WAS_NO_SLP;
409 list = roar_enum_servers(flags, -1, -1);
410 config->workaround.workarounds = workarounds_store;
411 if ( list != NULL ) {
412  for (i = 0; list[i].server != NULL; i++) {
413   if ( _connect_server(con, list[i].server, ROAR_SOCKET_TYPE_UNKNOWN, 0, 0) == 0 ) {
414    roar_enum_servers_free(list);
415    return 0;
416   }
417  }
418  roar_enum_servers_free(list);
419 }
420#endif
421
422 return -1;
423
424 } else {
425  /* connect via (char*)server */
426  if ( _connect_server(con, server, ROAR_SOCKET_TYPE_UNKNOWN, flags, timeout) != 0 )
427   return -1;
428  return 0;
429 }
430
431 roar_err_set(ROAR_ERROR_NODEV);
432 ROAR_DBG("roar_connect_raw(*) = -1 // error=NODEV");
433 return -1;
434}
435
436int roar_connect     (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) {
437 struct roar_libroar_config * config = roar_libroar_get_config();
438
439 if ( con == NULL ) {
440  roar_err_set(ROAR_ERROR_FAULT);
441  return -1;
442 }
443
444 if ( roar_connect_none(con) == -1 )
445  return -1;
446
447 roar_err_set(ROAR_ERROR_UNKNOWN);
448 if ( roar_connect_raw(con, server, flags | config->serverflags, timeout) == -1 )
449  return -1;
450
451 // TODO: this should be moved to be within _connect_server() so it also stores server names of auto located servers.
452 if ( server != NULL ) {
453  con->server_name = roar_mm_strdup(server);
454 }
455
456 return 0;
457}
458
459int roar_connect_none (struct roar_connection * con) {
460 struct roar_libroar_config * config = roar_libroar_get_config();
461
462 if ( con == NULL ) {
463  roar_err_set(ROAR_ERROR_INVAL);
464  return -1;
465 }
466
467 memset(con, 0, sizeof(struct roar_connection));
468 con->refc        = 1;
469 con->flags       = ROAR_CON_FLAGS_ISCLIENT;
470 con->version     = _ROAR_MESSAGE_VERSION;
471 con->cb_userdata = NULL;
472 con->cb          = NULL;
473 con->server_stds = NULL;
474 con->server_name = NULL;
475
476 roar_err_init(&(con->errorframe));
477
478 con->viocon = &(con->viocon_store);
479
480// con->flags |= ROAR_CON_FLAGS_VIO;
481
482 if ( config->protocolversion != -1 )
483  roar_set_connection_version(con, config->protocolversion);
484
485 roar_err_set(ROAR_ERROR_NONE);
486 return 0;
487}
488
489int roar_connect_vio (struct roar_connection * con, struct roar_vio_calls * vio) {
490 if ( con == NULL || vio == NULL ) {
491  roar_err_set(ROAR_ERROR_INVAL);
492  return -1;
493 }
494
495 if ( roar_connect_none(con) == -1 )
496  return -1;
497
498 con->viocon = vio;
499 con->flags |= ROAR_CON_FLAGS_VIO;
500
501 return -1;
502}
503
504int roar_connect_fh (struct roar_connection * con, int fh) {
505
506 if ( con == NULL || fh == -1 ) {
507  roar_err_set(ROAR_ERROR_INVAL);
508  return -1;
509 }
510
511 if ( roar_connect_none(con) == -1 )
512  return -1;
513
514 // special hack to set an illegal value used internally in libroar:
515 if ( fh == -2 )
516  fh = -1;
517
518 if ( roar_vio_open_fh_socket(con->viocon, fh) != -1 ) {
519  con->flags |= ROAR_CON_FLAGS_VIO;
520 } else {
521  return -1;
522 }
523
524 roar_err_set(ROAR_ERROR_NONE);
525 return 0;
526}
527
528int roar_get_connection_fh (struct roar_connection * con) {
529 int fh;
530
531 ROAR_DBG("roar_get_connection_fh(con=%p) = ?", con);
532
533 roar_debug_warn_sysio("roar_get_connection_fh", "roar_get_connection_vio2", NULL);
534
535 if ( con == NULL )
536  return -1;
537
538 ROAR_DBG("roar_get_connection_fh(con=%p) = ?", con);
539
540 if ( roar_vio_ctl(con->viocon, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
541#ifdef ROAR_TARGET_WIN32
542  if ( roar_vio_ctl(con->viocon, ROAR_VIO_CTL_GET_SELECT_FH, &fh) == -1 )
543   return -1;
544#else
545  return -1;
546#endif
547 }
548
549 ROAR_DBG("roar_get_connection_fh(con=%p) = %i", con, fh);
550
551 return fh;
552}
553
554struct roar_vio_calls * roar_get_connection_vio2 (struct roar_connection * con) {
555 if ( con == NULL ) {
556  roar_err_set(ROAR_ERROR_FAULT);
557  return NULL;
558 }
559
560 if ( con->flags & ROAR_CON_FLAGS_VIO )
561  return con->viocon;
562
563// TODO: try to open the VIO.
564
565 roar_err_set(ROAR_ERROR_BADFH);
566 return NULL;
567}
568
569const char * roar_get_connection_server(struct roar_connection * con) {
570 if ( con == NULL ) {
571  roar_err_set(ROAR_ERROR_FAULT);
572  return NULL;
573 }
574
575 return con->server_name;
576}
577
578int roar_connectionref(struct roar_connection * con) {
579 if ( con == NULL ) {
580  roar_err_set(ROAR_ERROR_FAULT);
581  return -1;
582 }
583
584 con->refc++;
585
586 return 0;
587}
588
589int roar_connectionunref(struct roar_connection * con) {
590 struct roar_vio_calls * vio;
591 struct roar_message m;
592
593 if ( con == NULL ) {
594  roar_err_set(ROAR_ERROR_FAULT);
595  return -1;
596 }
597
598 con->refc--;
599
600 if ( con->refc )
601  return 0;
602
603 memset(&m, 0, sizeof(m));
604
605 m.datalen =  0;
606 m.stream  = -1;
607 m.pos     =  0;
608 m.cmd     = ROAR_CMD_QUIT;
609
610 roar_req(con, &m, NULL);
611
612 if ( (vio = roar_get_connection_vio2(con)) != NULL ) {
613  roar_vio_close(vio);
614 }
615
616 if ( con->server_stds != NULL ) {
617  roar_stds_free(con->server_stds);
618  con->server_stds = NULL;
619 }
620
621 if ( con->server_name != NULL ) {
622  roar_mm_free(con->server_name);
623  con->server_name = NULL;
624 }
625
626 if ( con->flags & ROAR_CON_FLAGS_FREESELF ) {
627  roar_mm_free(con);
628 } else {
629  roar_connect_fh(con, -2);
630 }
631
632 return 0;
633}
634
635int roar_set_connection_callback(struct roar_connection * con,
636                                 void (*cb)(struct roar_connection * con,
637                                            struct roar_message    * mes,
638                                            void                   * data,
639                                            void                   * userdata),
640                                 void * userdata) {
641 if ( con == NULL ) {
642  roar_err_set(ROAR_ERROR_FAULT);
643  return -1;
644 }
645
646 con->cb       = cb;
647 con->cb_userdata = userdata;
648
649 return 0;
650}
651
652int roar_set_connection_version(struct roar_connection * con, int version) {
653 if ( con == NULL ) {
654  roar_err_set(ROAR_ERROR_FAULT);
655  return -1;
656 }
657
658 if ( version == -1 )
659  version = _ROAR_MESSAGE_VERSION;
660
661 if ( version < 0 ) {
662  roar_err_set(ROAR_ERROR_INVAL);
663  return -1;
664 }
665
666 con->version = version;
667
668 if ( version == 2 ) {
669  con->flags |= ROAR_CON_FLAGS_SUPPORT_V2;
670 }
671
672 return 0;
673}
674
675int16_t roar_message_genseq(struct roar_connection * con, int is_client) {
676 static int16_t store = 0;
677 int16_t ret = 0;
678
679 ret = store++;
680
681 if ( ret == 0 )
682  ret = store++;
683
684 if ( is_client == -1 ) {
685  if ( con != NULL ) {
686   is_client = con->flags & ROAR_CON_FLAGS_ISCLIENT ? 1 : 0;
687  }
688 }
689
690 if ( is_client == -1 )
691  is_client = 1;
692
693 ret |= 0x8000U;
694 if ( !is_client )
695  ret -= 0x8000U;
696
697 return ret;
698}
699
700int roar_sync         (struct roar_connection * con) {
701 // wait for any non-client reqs
702 return roar_wait_msg(con, 0x0000, 0x8000);
703}
704
705int roar_wait_msg     (struct roar_connection * con, int16_t seq, int16_t seqmask) {
706 roar_err_set(ROAR_ERROR_NOSYS);
707 return -1;
708}
709
710int roar_noop         (struct roar_connection * con) {
711 struct roar_message mes;
712
713 if ( con == NULL ) {
714  roar_err_set(ROAR_ERROR_FAULT);
715  return -1;
716 }
717
718 memset(&mes, 0, sizeof(mes));
719
720 mes.cmd = ROAR_CMD_NOOP;
721 mes.stream = -1;
722
723 return roar_req3(con, &mes, NULL);
724}
725
726int roar_identify   (struct roar_connection * con, const char * name) {
727 struct roar_message mes;
728 uint32_t pid;
729 int max_len;
730
731 roar_err_set(ROAR_ERROR_UNKNOWN);
732
733 ROAR_DBG("roar_identify(*): try to identify myself...");
734
735 memset(&mes, 0, sizeof(mes));
736
737 mes.cmd    = ROAR_CMD_IDENTIFY;
738 mes.stream = -1;
739 mes.pos    =  0;
740
741 ROAR_DBG("roar_identify(*): name=%p", name);
742
743 if ( name == NULL )
744  name = "libroar client";
745
746 ROAR_DBG("roar_identify(*): name=%p", name);
747
748 max_len = roar_mm_strlen(name);
749 ROAR_DBG("roar_identify(*): strlen(name) = %i", max_len);
750
751 if ( max_len > (LIBROAR_BUFFER_MSGDATA - 5) )
752  max_len = LIBROAR_BUFFER_MSGDATA - 5;
753
754 mes.datalen = 5 + max_len;
755 mes.data[0] = 1;
756
757 pid = getpid();
758 mes.data[1] = (pid & 0xFF000000UL) >> 24;
759 mes.data[2] = (pid & 0x00FF0000UL) >> 16;
760 mes.data[3] = (pid & 0x0000FF00UL) >>  8;
761 mes.data[4] = (pid & 0x000000FFUL) >>  0;
762 ROAR_DBG("roar_identify(*): pid = %i", (int)pid);
763
764 strncpy(mes.data+5, name, max_len);
765
766 return roar_req3(con, &mes, NULL);
767}
768
769//ll
Note: See TracBrowser for help on using the repository browser.