source: roaraudio/libroar/vio_dstr.c @ 4746:79232d38c29e

Last change on this file since 4746:79232d38c29e was 4746:79232d38c29e, checked in by phi, 13 years ago

added consts for some generic devices

File size: 24.7 KB
RevLine 
[1321]1//vio_dstr.c:
2
3/*
[4708]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
[1321]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[1321]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
[1365]38#ifndef ROAR_WITHOUT_VIO_DSTR
[3312]39struct _roar_vio_dstr_type {
[1323]40 int    id;
41 char * name;
[3310]42 int (* setdef) (struct roar_vio_dstr_chain * cur,   struct roar_vio_dstr_chain * next);
43 int (* openvio)(struct roar_vio_calls      * calls, struct roar_vio_calls      * dst, struct roar_vio_dstr_chain * cur);
[1323]44 int    pdeftype[16];
45} _roar_vio_dstr_objs[] = {
46/*
47grep '^#define ROAR_VIO_DSTR_OBJT_' vio_dstr.h | cut -d' ' -f2 | while read objt; do name=`cut -d_ -f5,6,7,8,9,10 <<<$objt | tr A-Z a-z`; echo -e " {$objt,\t \"$name\","; echo "      {ROAR_VIO_DEF_TYPE_EOL}},"; done;
48*/
49 {ROAR_VIO_DSTR_OBJT_FILE,       "file",
[3310]50      NULL, NULL,
[1323]51      {ROAR_VIO_DEF_TYPE_EOL}},
52 {ROAR_VIO_DSTR_OBJT_FH,         "fh",
[3310]53      NULL, NULL,
[1323]54      {ROAR_VIO_DEF_TYPE_EOL}},
[1328]55 {ROAR_VIO_DSTR_OBJT_FD,         "fd",
[3310]56      NULL, NULL,
[1328]57      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]58 {ROAR_VIO_DSTR_OBJT_SOCKETFH,   "socketfh",
[3310]59      NULL, NULL,
[1323]60      {ROAR_VIO_DEF_TYPE_EOL}},
61 {ROAR_VIO_DSTR_OBJT_PASS,       "pass",
[3310]62      NULL, NULL,
[1323]63      {ROAR_VIO_DEF_TYPE_EOL}},
64 {ROAR_VIO_DSTR_OBJT_RE,         "re",
[3310]65      NULL, NULL,
[1323]66      {ROAR_VIO_DEF_TYPE_EOL}},
[3309]67 {ROAR_VIO_DSTR_OBJT_JUMBO,      "jumbo", /* TODO */
[3310]68      NULL, NULL,
[3309]69      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]70 {ROAR_VIO_DSTR_OBJT_EXEC,       "exec",
[3310]71      NULL, NULL,
[1323]72      {ROAR_VIO_DEF_TYPE_EOL}},
[4746]73/* special devices */
74 {ROAR_VIO_DSTR_OBJT_NULL,       "null",
75      NULL, NULL,
76      {ROAR_VIO_DEF_TYPE_EOL}},
77 {ROAR_VIO_DSTR_OBJT_ZERO,       "zero",
78      NULL, NULL,
79      {ROAR_VIO_DEF_TYPE_EOL}},
80 {ROAR_VIO_DSTR_OBJT_FULL,       "full",
81      NULL, NULL,
82      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]83
84 {ROAR_VIO_DSTR_OBJT_SOCKET,     "socket",
[3310]85      NULL, NULL,
[1323]86      {ROAR_VIO_DEF_TYPE_EOL}},
87 {ROAR_VIO_DSTR_OBJT_UNIX,       "unix",
[3310]88      NULL, NULL,
[1323]89      {ROAR_VIO_DEF_TYPE_EOL}},
90 {ROAR_VIO_DSTR_OBJT_DECNET,     "decnet",
[3310]91      NULL, NULL,
[1323]92      {ROAR_VIO_DEF_TYPE_EOL}},
93 {ROAR_VIO_DSTR_OBJT_TCP,        "tcp",
[3310]94      NULL, NULL,
[1323]95      {ROAR_VIO_DEF_TYPE_EOL}},
96 {ROAR_VIO_DSTR_OBJT_UDP,        "udp",
[3310]97      NULL, NULL,
[1323]98      {ROAR_VIO_DEF_TYPE_EOL}},
99 {ROAR_VIO_DSTR_OBJT_TCP6,       "tcp6",
[3310]100      NULL, NULL,
[1323]101      {ROAR_VIO_DEF_TYPE_EOL}},
102 {ROAR_VIO_DSTR_OBJT_UDP6,       "udp6",
[3310]103      NULL, NULL,
[1323]104      {ROAR_VIO_DEF_TYPE_EOL}},
105
106 {ROAR_VIO_DSTR_OBJT_SOCKS,      "socks",
[3310]107      NULL, NULL,
[1323]108      {ROAR_VIO_DEF_TYPE_EOL}},
109 {ROAR_VIO_DSTR_OBJT_SOCKS4,     "socks4",
[3310]110      NULL, NULL,
[1323]111      {ROAR_VIO_DEF_TYPE_EOL}},
112 {ROAR_VIO_DSTR_OBJT_SOCKS4A,    "socks4a",
[3310]113      NULL, NULL,
[1323]114      {ROAR_VIO_DEF_TYPE_EOL}},
115 {ROAR_VIO_DSTR_OBJT_SOCKS4D,    "socks4d",
[3310]116      NULL, NULL,
[1323]117      {ROAR_VIO_DEF_TYPE_EOL}},
118 {ROAR_VIO_DSTR_OBJT_SOCKS5,     "socks5",
[3310]119      NULL, NULL,
[1323]120      {ROAR_VIO_DEF_TYPE_EOL}},
121 {ROAR_VIO_DSTR_OBJT_SSH,        "ssh",
[3310]122      NULL, NULL,
[1323]123      {ROAR_VIO_DEF_TYPE_EOL}},
124
125 {ROAR_VIO_DSTR_OBJT_HTTP09,     "http09",
[3310]126      NULL, NULL,
[1323]127      {ROAR_VIO_DEF_TYPE_EOL}},
128 {ROAR_VIO_DSTR_OBJT_HTTP10,     "http10",
[3310]129      NULL, NULL,
[1323]130      {ROAR_VIO_DEF_TYPE_EOL}},
131 {ROAR_VIO_DSTR_OBJT_HTTP11,     "http11",
[3310]132      NULL, NULL,
[1323]133      {ROAR_VIO_DEF_TYPE_EOL}},
134 {ROAR_VIO_DSTR_OBJT_HTTP,       "http",
[3310]135      NULL, NULL,
[1323]136      {ROAR_VIO_DEF_TYPE_EOL}},
137 {ROAR_VIO_DSTR_OBJT_GOPHER,     "gopher",
[3310]138      NULL, NULL,
[1323]139      {ROAR_VIO_DEF_TYPE_EOL}},
[1349]140 {ROAR_VIO_DSTR_OBJT_GOPHER_PLUS,"gopher+",
[3310]141      NULL, NULL,
[1349]142      {ROAR_VIO_DEF_TYPE_EOL}},
[3078]143 {ROAR_VIO_DSTR_OBJT_ICY,        "icy",
[3310]144      NULL, NULL,
[3078]145      {ROAR_VIO_DEF_TYPE_EOL}},
[3277]146 {ROAR_VIO_DSTR_OBJT_RTP2,       "rtp2",
[3310]147      NULL, NULL,
[3277]148      {ROAR_VIO_DEF_TYPE_EOL}},
149 {ROAR_VIO_DSTR_OBJT_RTP,        "rtp",
[3310]150      NULL, NULL,
[3277]151      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]152
153 {ROAR_VIO_DSTR_OBJT_GZIP,       "gzip",
[3310]154      NULL, NULL,
[1323]155      {ROAR_VIO_DEF_TYPE_EOL}},
156 {ROAR_VIO_DSTR_OBJT_BZIP2,      "bzip2",
[3310]157      NULL, NULL,
[1323]158      {ROAR_VIO_DEF_TYPE_EOL}},
159
160 {ROAR_VIO_DSTR_OBJT_PGP,        "pgp",
[3310]161      NULL, NULL,
[1323]162      {ROAR_VIO_DEF_TYPE_EOL}},
163 {ROAR_VIO_DSTR_OBJT_PGP_ENC,    "pgp_enc",
[3310]164      NULL, NULL,
[1323]165      {ROAR_VIO_DEF_TYPE_EOL}},
166 {ROAR_VIO_DSTR_OBJT_PGP_STORE,  "pgp_store",
[3310]167      NULL, NULL,
[1323]168      {ROAR_VIO_DEF_TYPE_EOL}},
169 {ROAR_VIO_DSTR_OBJT_SSL1,       "ssl1",
[3310]170      NULL, NULL,
[1323]171      {ROAR_VIO_DEF_TYPE_EOL}},
172 {ROAR_VIO_DSTR_OBJT_SSL2,       "ssl2",
[3310]173      NULL, NULL,
[1323]174      {ROAR_VIO_DEF_TYPE_EOL}},
175 {ROAR_VIO_DSTR_OBJT_SSL3,       "ssl3",
[3310]176      NULL, NULL,
[1323]177      {ROAR_VIO_DEF_TYPE_EOL}},
178 {ROAR_VIO_DSTR_OBJT_TLS,        "tls",
[3310]179      NULL, NULL,
[1323]180      {ROAR_VIO_DEF_TYPE_EOL}},
181 {ROAR_VIO_DSTR_OBJT_SSLTLS,     "ssltls",
[3310]182      NULL, NULL,
[1323]183      {ROAR_VIO_DEF_TYPE_EOL}},
[4746]184/* Random numbers */
185 {ROAR_VIO_DSTR_OBJT_NRANDOM,    "nrandom",
186      NULL, NULL,
187      {ROAR_VIO_DEF_TYPE_EOL}},
188 {ROAR_VIO_DSTR_OBJT_URANDOM,    "urandom",
189      NULL, NULL,
190      {ROAR_VIO_DEF_TYPE_EOL}},
191 {ROAR_VIO_DSTR_OBJT_SRANDOM,    "srandom",
192      NULL, NULL,
193      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]194
[3309]195 {ROAR_VIO_DSTR_OBJT_TRANSCODE,  "transcode", /* TODO  */
[3310]196      NULL, NULL,
[3309]197      {ROAR_VIO_DEF_TYPE_EOL}},
198
199 {ROAR_VIO_DSTR_OBJT_RAUM,       "raum",      /* TODO */
[3310]200      NULL, NULL,
[3309]201      {ROAR_VIO_DEF_TYPE_EOL}},
202 {ROAR_VIO_DSTR_OBJT_OGG,        "ogg",       /* TODO */
[3310]203      NULL, NULL,
[3309]204      {ROAR_VIO_DEF_TYPE_EOL}},
205 {ROAR_VIO_DSTR_OBJT_TAR,        "tar",       /* TODO */
[3310]206      NULL, NULL,
[3309]207      {ROAR_VIO_DEF_TYPE_EOL}},
208
209
[1323]210 {ROAR_VIO_DSTR_OBJT_MAGIC,      "magic",
[3310]211      NULL, NULL,
[1323]212      {ROAR_VIO_DEF_TYPE_EOL}},
[3116]213 {ROAR_VIO_DSTR_OBJT_TANTALOS,   "tantalos",
[3310]214      NULL, NULL,
[3116]215      {ROAR_VIO_DEF_TYPE_EOL}},
[1323]216
217 {ROAR_VIO_DSTR_OBJT_INTERNAL, "INTERNAL",
[3310]218      NULL, NULL,
[1323]219      {ROAR_VIO_DEF_TYPE_FILE, ROAR_VIO_DEF_TYPE_SOCKET, ROAR_VIO_DEF_TYPE_FH, ROAR_VIO_DEF_TYPE_SOCKETFH,
220       ROAR_VIO_DEF_TYPE_EOL}},
[3310]221 {ROAR_VIO_DSTR_OBJT_EOL, NULL, NULL, NULL, {ROAR_VIO_DEF_TYPE_EOL}}
[1323]222};
223
224int     roar_vio_dstr_get_type(char * str) {
225 int i;
226
227 for (i = 0; _roar_vio_dstr_objs[i].id != ROAR_VIO_DSTR_OBJT_EOL; i++) {
228  if ( strcasecmp(_roar_vio_dstr_objs[i].name, str) == 0 )
229   return _roar_vio_dstr_objs[i].id;
230 }
231
232 return -1;
233}
234
[3312]235struct _roar_vio_dstr_type * roar_vio_dstr_get_by_type (int type) {
[1323]236 int i;
237
238 for (i = 0; _roar_vio_dstr_objs[i].id != ROAR_VIO_DSTR_OBJT_EOL; i++) {
239  if ( _roar_vio_dstr_objs[i].id == type )
[3312]240   return &(_roar_vio_dstr_objs[i]);
[1323]241 }
242
[3312]243 return NULL;
244}
245
246char *  roar_vio_dstr_get_name(int type) {
247 struct _roar_vio_dstr_type * ret;
248
249 if ( (ret = roar_vio_dstr_get_by_type(type)) != NULL )
250  return ret->name;
251
[1325]252 if ( type == ROAR_VIO_DSTR_OBJT_EOL )
253  return "<<EOL>>";
254
[1323]255 return NULL;
256}
[3311]257
[3312]258int     roar_vio_dstr_register_type(int   type,
259                                    char *name,
260                                    int (*setdef) (struct roar_vio_dstr_chain * cur,
261                                                   struct roar_vio_dstr_chain * next),
262                                    int (*openvio)(struct roar_vio_calls      * calls,
263                                                   struct roar_vio_calls      * dst,
264                                                   struct roar_vio_dstr_chain * cur)) {
265 struct _roar_vio_dstr_type * ret;
266
267 if ( (ret = roar_vio_dstr_get_by_type(type)) == NULL ) /* we can currently not register new types */
268  return -1;
269
270
271 // check if things are allready set, we do not want to allow overwrite here.
272 if ( setdef != NULL && ret->setdef != NULL )
273  return -1;
274
275 if ( openvio != NULL && ret->openvio != NULL )
276  return -1;
277
278 if ( setdef != NULL )
279  ret->setdef = setdef;
280
281 if ( openvio != NULL )
282  ret->openvio = openvio;
283
284 return 0;
285}
286
[3311]287static void _roar_vio_dstr_init_otherlibs (void) {
288 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroardsp");
289 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroareio");
290 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarlight");
291 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarmidi");
292}
293
[1365]294#endif
[1323]295
296int     roar_vio_dstr_init_defaults (struct roar_vio_defaults * def, int type, int o_flags, mode_t o_mode) {
297 if ( def == NULL )
298  return -1;
299
300 memset(def, 0, sizeof(struct roar_vio_defaults));
301
302 def->type    = type;
303 def->o_flags = o_flags;
304 def->o_mode  = o_mode;
305
306 return 0;
307}
308
[1353]309int     roar_vio_dstr_init_defaults_c (struct roar_vio_defaults * def, int type, struct roar_vio_defaults * odef, int o_flags) {
310 if ( o_flags < 1 )
311  o_flags = O_RDONLY;
312
313 if ( odef == NULL ) {
314  return roar_vio_dstr_init_defaults(def, type, o_flags, 0644);
315 } else {
316  return roar_vio_dstr_init_defaults(def, type, odef->o_flags, odef->o_mode);
317 }
318}
319
[1365]320#ifndef ROAR_WITHOUT_VIO_DSTR
[3292]321int     roar_vio_open_default (struct roar_vio_calls * calls, struct roar_vio_defaults * def, char * opts) {
322 ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s') = ?", calls, def, opts);
323
[1330]324 if ( calls == NULL || def == NULL )
325  return -1;
326
327 switch (def->type) {
[3118]328  case ROAR_VIO_DEF_TYPE_NONE:
329   break;
[1330]330  case ROAR_VIO_DEF_TYPE_FILE:
331    if ( roar_vio_open_file(calls, def->d.file, def->o_flags, def->o_mode) == -1 )
332     return -1;
333   break;
334  case ROAR_VIO_DEF_TYPE_SOCKET:
[3293]335     if ( roar_vio_open_def_socket(calls, def, opts) == -1 )
[1333]336      return -1;
[1330]337   break;
338  case ROAR_VIO_DEF_TYPE_FH:
339    if ( roar_vio_open_fh(calls, def->d.fh) == -1 )
340     return -1;
341   break;
342  case ROAR_VIO_DEF_TYPE_SOCKETFH:
343    if ( roar_vio_open_fh_socket(calls, def->d.fh) == -1 )
344     return -1;
345   break;
346  default:
347    return -1;
348 }
349
350 return 0;
351}
[1365]352#endif
[1330]353
[1323]354int     roar_vio_open_dstr    (struct roar_vio_calls * calls, char * dstr, struct roar_vio_defaults * def, int dnum) {
355 return roar_vio_open_dstr_vio(calls, dstr, def, dnum, NULL);
356}
357
[3834]358#define _ret(x) roar_mm_free(dstr); return (x)
[1323]359
360int     roar_vio_open_dstr_vio(struct roar_vio_calls * calls,
361                               char * dstr, struct roar_vio_defaults * def, int dnum,
362                               struct roar_vio_calls * vio) {
[1365]363#ifndef ROAR_WITHOUT_VIO_DSTR
[1325]364 struct roar_vio_dstr_chain chain[ROAR_VIO_DSTR_MAX_OBJ_PER_CHAIN];
[1323]365 char * next;
366 char * this;
367 char * name;
368 char * opts;
369 char * dst;
370 char * c;
371 int    inopts;
372 int    type;
[1328]373 int    cc = 1; // current chain element
[1323]374
375 if ( calls == NULL || dstr == NULL )
376  return -1;
377
378 if ( dnum != 0 && def == NULL )
379  return -1;
380
[3834]381 if ( (dstr = roar_mm_strdup(dstr)) == NULL )
[1323]382  return -1;
383
[1325]384 memset(chain, 0, sizeof(chain));
[1323]385
[1328]386 chain[0].type = ROAR_VIO_DSTR_OBJT_INTERNAL;
387
[1323]388 next = dstr;
389
390 while (next != NULL) {
[1325]391  if ( (cc+1) == ROAR_VIO_DSTR_MAX_OBJ_PER_CHAIN ) {
392   _ret(-1);
393  }
394
[1323]395  this = next;
396  next = strstr(next, "##");
397
398  if (next != NULL) {
399   *next = 0;
400   next += 2;
401  }
402
403  // we have the current token in 'this'.
404
405  opts   = NULL;
406  dst    = NULL;
407
408  if ( strstr(this, ":") != NULL ) {
409   name   = this;
410   inopts = 0;
411   for (c = this; *c != 0; c++) {
412    if ( *c == '[' ) {
413     *c     = 0;
414     opts   = c + 1;
415     inopts = 1;
416    } else if ( *c == ']' &&  inopts ) {
417     *c     = 0;
418     inopts = 0;
419    } else if ( *c == ':' && !inopts ) {
420     *c     = 0;
421     dst    = *(c+1) == 0 ? NULL : c + 1;
422     break;
423    }
424   }
425  } else {
426   // we need to guess that this is here...
427   // currently we guess this is a file in all cases
428   name = "file";
429   dst  = this;
430  }
431
[1329]432  ROAR_DBG("roar_vio_open_dstr_vio(*): name='%s', opts='%s', dst='%s'", name, opts, dst);
[1323]433
434  if ( (type = roar_vio_dstr_get_type(name)) == -1 ) {
435   _ret(-1);
436  }
437
[1329]438  ROAR_DBG("roar_vio_open_dstr_vio(*): type=0x%.4x(%s)", type, roar_vio_dstr_get_name(type));
[1323]439
[1325]440  chain[cc].type     = type;
441  chain[cc].opts     = opts;
442  chain[cc].dst      = dst;
443  chain[cc].def      = NULL;
444  chain[cc].vio      = NULL;
445  chain[cc].need_vio = -1;
446  cc++;
447
448 }
449
450 chain[cc].type = ROAR_VIO_DSTR_OBJT_EOL;
451
[1616]452 ROAR_DBG("roar_vio_open_dstr_vio(*): chain=%p", chain);
[1328]453
[1325]454 if ( roar_vio_dstr_parse_opts(chain) == -1 ) {
455  _ret(-1);
456 }
457
458 if ( roar_vio_dstr_set_defaults(chain, cc, def, dnum) == -1 ) {
459  _ret(-1);
460 }
461
462 if ( roar_vio_dstr_build_chain(chain, calls, vio) == -1 ) {
463  _ret(-1);
[1323]464 }
465
[1325]466 _ret(0);
[1365]467#else
468 return -1;
469#endif
[1325]470}
471
472#undef _ret
473
[1365]474#ifndef ROAR_WITHOUT_VIO_DSTR
[1325]475int     roar_vio_dstr_parse_opts(struct roar_vio_dstr_chain * chain) {
476 if ( chain == NULL )
477  return -1;
478
479 // TODO: we should add some code here later...
480
481 return 0;
482}
483
484int     roar_vio_dstr_set_defaults(struct roar_vio_dstr_chain * chain, int len, struct roar_vio_defaults * def, int dnum) {
[3313]485 struct _roar_vio_dstr_type * type;
[1325]486 struct roar_vio_dstr_chain * c, * next;
487 int i;
[1328]488 int tmp[8];
[1325]489
490 if ( chain == NULL )
491  return -1;
492
493 if ( def == NULL && dnum != 0 )
494  return -1;
495
496 if ( dnum > 1 ) /* currently not supported */
497  return -1;
498
499 if ( dnum == 0 )
500  def = NULL;
501
502 chain[len].def = def;
503
504 for (i = len; i >= 0; i--) {
505  c    = &chain[i];
[1329]506
507  if ( i > 0 ) {
508   next = &chain[i-1];
509  } else {
510   next = NULL;
511
512   if ( c->type != ROAR_VIO_DSTR_OBJT_INTERNAL )
513    return -1;
514  }
[1325]515
[1328]516  memset(tmp, 0, sizeof(tmp));
517
[1350]518  ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s)", i, c->type & 0xFFFF, roar_vio_dstr_get_name(c->type));
[1616]519  ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): c->def=%p, c->def->type=%i", i, c->type & 0xFFFF,
[1325]520                   roar_vio_dstr_get_name(c->type), c->def, c->def == NULL ? -1 : c->def->type);
521
522  c->need_vio = 1;
523
524  switch (c->type) {
[1328]525   case ROAR_VIO_DSTR_OBJT_INTERNAL:
526     c->need_vio = 0;
527    break;
528   case ROAR_VIO_DSTR_OBJT_EOL:
529     tmp[0] = 1;
[1325]530   case ROAR_VIO_DSTR_OBJT_PASS:
531   case ROAR_VIO_DSTR_OBJT_RE:
[3277]532   case ROAR_VIO_DSTR_OBJT_RTP2: // we currently only forward the defs
[1325]533   case ROAR_VIO_DSTR_OBJT_GZIP:
534   case ROAR_VIO_DSTR_OBJT_BZIP2:
535   case ROAR_VIO_DSTR_OBJT_PGP:
536   case ROAR_VIO_DSTR_OBJT_PGP_ENC:
537   case ROAR_VIO_DSTR_OBJT_PGP_STORE:
538   case ROAR_VIO_DSTR_OBJT_SSL1:
539   case ROAR_VIO_DSTR_OBJT_SSL2:
540   case ROAR_VIO_DSTR_OBJT_SSL3:
541   case ROAR_VIO_DSTR_OBJT_TLS:
542   case ROAR_VIO_DSTR_OBJT_MAGIC:
[1328]543     if ( tmp[0] )
544      c->need_vio = 0;
545
[1325]546     next->def = c->def;
547    break;
[3118]548   case ROAR_VIO_DSTR_OBJT_TANTALOS:
549     next->def = &(next->store_def);
550     roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_NONE, NULL, -1);
551    break;
[1325]552   case ROAR_VIO_DSTR_OBJT_FILE:
553     if ( c->dst == NULL ) /* should we allow multible cascaed file: objects? */
554      return -1;
555
556     c->need_vio = 0;
557     next->def = &(next->store_def);
[1353]558     roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_FILE, c->def, -1);
[1325]559
560     if ( c->dst[0] == '/' && c->dst[1] == '/' ) {
561      next->def->d.file = c->dst + 1;
562     } else {
563      next->def->d.file = c->dst;
564     }
565    break;
[1328]566   case ROAR_VIO_DSTR_OBJT_FH:
567     tmp[0] = 1;
568   case ROAR_VIO_DSTR_OBJT_SOCKETFH:
569     c->need_vio = 0;
570     next->def = &(next->store_def);
571
572     if ( c->def != NULL ) {
573      tmp[2] = c->def->o_flags;
574      tmp[3] = c->def->o_mode;
575     } else {
576      tmp[2] = O_RDONLY;
577      tmp[3] = 0644;
578     }
579
580     if ( !strcasecmp(c->dst, "stdin") ) {
581      tmp[1] = ROAR_STDIN;
582      tmp[2] = O_RDONLY;
583     } else if ( !strcasecmp(c->dst, "stdout") ) {
584      tmp[1] = ROAR_STDOUT;
585      tmp[2] = O_WRONLY;
586     } else if ( !strcasecmp(c->dst, "stderr") ) {
587      tmp[1] = ROAR_STDERR;
588      tmp[2] = O_WRONLY;
589     } else {
590      if ( sscanf(c->dst, "%i", &tmp[1]) != 1 )
591       return -1;
592     }
593
594     roar_vio_dstr_init_defaults(next->def, tmp[0] ? ROAR_VIO_DEF_TYPE_FH : ROAR_VIO_DEF_TYPE_SOCKETFH, tmp[2], tmp[3]);
595     next->def->d.fh = tmp[1];
596    break;
[1337]597#ifdef ROAR_HAVE_UNIX
[1333]598   case ROAR_VIO_DSTR_OBJT_UNIX:
599     c->need_vio = 0;
600     next->def = &(next->store_def);
601
[1337]602     if ( c->dst == NULL ) { // we don't have a destination? -> slow way
[1353]603      if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
604       return -1;
605
[1337]606      if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_UNIX, SOCK_STREAM, c->def) == -1 )
607       return -1;
608     } else {                // we have a destination? -> fast way
[1353]609      if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
610       return -1;
[1337]611
612      if ( roar_vio_socket_init_unix_def(next->def, c->dst) == -1 )
613       return -1;
[1333]614     }
615    break;
[1337]616#endif
[1335]617   case ROAR_VIO_DSTR_OBJT_SOCKET:
618     c->need_vio = 0;
619     next->def = &(next->store_def);
620
[1353]621     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
622      return -1;
623
[1335]624     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, -1, SOCK_STREAM, c->def) == -1 )
625      return -1;
626    break;
627#ifdef ROAR_HAVE_LIBDNET
628   case ROAR_VIO_DSTR_OBJT_DECNET:
629     c->need_vio = 0;
630     next->def = &(next->store_def);
631
[1353]632     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
633      return -1;
634
[1335]635     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_DECnet, SOCK_STREAM, c->def) == -1 )
636      return -1;
637    break;
638#endif
[1359]639#ifdef ROAR_HAVE_IPV4
[1335]640   case ROAR_VIO_DSTR_OBJT_TCP:
641     c->need_vio = 0;
642     next->def = &(next->store_def);
643
[1353]644     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
645      return -1;
646
[1335]647     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_INET, SOCK_STREAM, c->def) == -1 )
648      return -1;
649    break;
650   case ROAR_VIO_DSTR_OBJT_UDP:
651     c->need_vio = 0;
652     next->def = &(next->store_def);
653
[1353]654     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
655      return -1;
656
[1335]657     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_INET, SOCK_DGRAM, c->def) == -1 )
658      return -1;
659    break;
[1359]660#endif
[1335]661#ifdef ROAR_HAVE_IPV6
662   case ROAR_VIO_DSTR_OBJT_TCP6:
663     c->need_vio = 0;
664     next->def = &(next->store_def);
665
[1353]666     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
667      return -1;
668
[1335]669     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_INET6, SOCK_STREAM, c->def) == -1 )
670      return -1;
671    break;
672   case ROAR_VIO_DSTR_OBJT_UDP6:
673     c->need_vio = 0;
674     next->def = &(next->store_def);
675
[1353]676     if ( roar_vio_dstr_init_defaults_c(next->def, ROAR_VIO_DEF_TYPE_SOCKET, c->def, O_WRONLY) == -1 )
677      return -1;
678
[1335]679     if ( roar_vio_socket_init_dstr_def(next->def, c->dst, AF_INET6, SOCK_DGRAM, c->def) == -1 )
680      return -1;
681    break;
682#endif
[1349]683   case ROAR_VIO_DSTR_OBJT_HTTP09:
684   case ROAR_VIO_DSTR_OBJT_HTTP10:
685   case ROAR_VIO_DSTR_OBJT_HTTP11:
686     c->need_vio = 1;
687     next->def = &(next->store_def);
688
689     if ( roar_vio_proto_init_def(next->def, c->dst, ROAR_VIO_PROTO_P_HTTP, c->def) == -1 )
690      return -1;
691    break;
692   case ROAR_VIO_DSTR_OBJT_GOPHER:
693   case ROAR_VIO_DSTR_OBJT_GOPHER_PLUS:
694     c->need_vio = 1;
695     next->def = &(next->store_def);
696
697     if ( roar_vio_proto_init_def(next->def, c->dst, ROAR_VIO_PROTO_P_GOPHER, c->def) == -1 )
698      return -1;
699    break;
[3078]700   case ROAR_VIO_DSTR_OBJT_ICY:
701     c->need_vio = 1;
702     next->def = &(next->store_def);
703
704     if ( roar_vio_proto_init_def(next->def, c->dst, ROAR_VIO_PROTO_P_ICY, c->def) == -1 )
705      return -1;
706    break;
[1325]707   default:
[3313]708     if ( (type = roar_vio_dstr_get_by_type(c->type)) == NULL ) {
709      return -1;
710     }
711
712     if ( type->setdef == NULL )
713      _roar_vio_dstr_init_otherlibs();
714
715     if ( type->setdef == NULL ) {
716      return -1;
717     }
718
719     if ( type->setdef(c, next) == -1 ) {
720      return -1;
721     }
[1325]722  }
723
[1329]724  if ( next != NULL ) {
[1350]725   ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next->def=%p, next->def->type=%i", i,
[1329]726                    c->type & 0xFFFF, roar_vio_dstr_get_name(c->type),
727                    next->def, next->def == NULL ? -1 : next->def->type);
[1349]728   if ( next->def != NULL ) {
[1616]729    ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next->def->o_flags=%i", i,
[1349]730                     c->type & 0xFFFF, roar_vio_dstr_get_name(c->type),
731                     next->def->o_flags);
732   }
[1329]733  } else {
[1350]734   ROAR_DBG("roar_vio_dstr_set_defaults(*): i=%i, c->type=0x%.4x(%s): next=NULL", i,
[1329]735                    c->type & 0xFFFF, roar_vio_dstr_get_name(c->type));
736  }
[1325]737 }
738
[1616]739 ROAR_DBG("roar_vio_dstr_set_defaults(*) = 0");
[1328]740
[1325]741 return 0;
742}
743
[1616]744#define _ret(x) roar_vio_close(calls); ROAR_DBG("roar_vio_dstr_build_chain(*) = %i", (x)); return (x)
[1328]745
746int     roar_vio_dstr_build_chain(struct roar_vio_dstr_chain * chain, struct roar_vio_calls * calls,
747                                  struct roar_vio_calls * vio) {
[3313]748 struct _roar_vio_dstr_type * type;
[1328]749 struct roar_vio_dstr_chain * c;
750 struct roar_vio_defaults   * def;
751 struct roar_vio_calls      * tc, * prev;
752 int i;
753
[1616]754 ROAR_DBG("roar_vio_dstr_build_chain(*) = ?");
[1328]755
[1325]756 if ( chain == NULL || calls == NULL )
757  return -1;
758
[1328]759 if ( roar_vio_open_stack(calls) == -1 )
760  return -1;
761
[1329]762 ROAR_DBG("roar_vio_dstr_build_chain(*): chain=%p", chain);
[1328]763
764 if ( (def = chain->def) != NULL ) {
765  if ( (tc = malloc(sizeof(struct roar_vio_calls))) == NULL ) {
766   _ret(-1);
767  }
768
[1337]769  if ( roar_vio_init_calls(tc) == -1 ) {
770   free(tc);
771   _ret(-1);
772  }
773
[1328]774  if ( roar_vio_stack_add(calls, tc) == -1 ) {
775   _ret(-1);
776  }
777
[3292]778  if ( chain->opts == NULL ) {
779   if ( chain[1].type != ROAR_VIO_DSTR_OBJT_EOL ) {
780    chain->opts = chain[1].opts;
781   }
782  }
783
784  if ( roar_vio_open_default(tc, def, chain->opts) == -1 ) {
[1330]785   _ret(-1);
[1328]786  }
[1330]787
[1328]788  prev = tc;
789 } else {
790  prev = vio;
791 }
792
793 for (i = 0; (c = &chain[i])->type != ROAR_VIO_DSTR_OBJT_EOL; i++) {
[1353]794  ROAR_DBG("roar_vio_dstr_build_chain(*): i=%i, c->type=0x%.4x(%s): need_vio=%i, def->o_flags=%i", i,
795                   c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), c->need_vio, c->def->o_flags);
[1349]796
[1328]797  if ( c->need_vio ) {
798   if ( (tc = malloc(sizeof(struct roar_vio_calls))) == NULL ) {
799    _ret(-1);
800   }
801
[1337]802   if ( roar_vio_init_calls(tc) == -1 ) {
803    free(tc);
804    _ret(-1);
805   }
806
[1328]807   if ( roar_vio_stack_add(calls, tc) == -1 ) {
808    _ret(-1);
809   }
810
[1349]811
[1328]812   switch (c->type) {
813    case ROAR_VIO_DSTR_OBJT_PASS:
814      if ( roar_vio_open_pass(tc, prev) == -1 ) {
815       _ret(-1);
816      }
817     break;
818    case ROAR_VIO_DSTR_OBJT_RE:
819      if ( roar_vio_open_re(tc, prev) == -1 ) {
820       _ret(-1);
821      }
822     break;
823    case ROAR_VIO_DSTR_OBJT_GZIP:
824      if ( roar_vio_open_gzip(tc, prev, -1) == -1 ) {
825       _ret(-1);
826      }
827     break;
828    case ROAR_VIO_DSTR_OBJT_BZIP2:
829    case ROAR_VIO_DSTR_OBJT_PGP:
830      if ( roar_vio_open_pgp_decrypt(tc, prev, NULL) == -1 ) {
831       _ret(-1);
832      }
833     break;
[1349]834    case ROAR_VIO_DSTR_OBJT_HTTP09:
835    case ROAR_VIO_DSTR_OBJT_HTTP10:
836    case ROAR_VIO_DSTR_OBJT_HTTP11:
[1353]837      if ( roar_vio_open_proto(tc, prev, c->dst, ROAR_VIO_PROTO_P_HTTP, c->def) == -1 ) {
[1349]838       _ret(-1);
839      }
840     break;
841    case ROAR_VIO_DSTR_OBJT_GOPHER:
842    case ROAR_VIO_DSTR_OBJT_GOPHER_PLUS:
[1353]843      if ( roar_vio_open_proto(tc, prev, c->dst, ROAR_VIO_PROTO_P_GOPHER, c->def) == -1 ) {
[1349]844       _ret(-1);
845      }
846     break;
[3078]847    case ROAR_VIO_DSTR_OBJT_ICY:
848      if ( roar_vio_open_proto(tc, prev, c->dst, ROAR_VIO_PROTO_P_ICY, c->def) == -1 ) {
849       _ret(-1);
850      }
851     break;
[3277]852    case ROAR_VIO_DSTR_OBJT_RTP2:
853      if ( roar_vio_open_rtp(tc, prev, c->dst, c->def) == -1 ) {
854       _ret(-1);
855      }
856     break;
[1328]857    case ROAR_VIO_DSTR_OBJT_PGP_ENC:
858    case ROAR_VIO_DSTR_OBJT_PGP_STORE:
859      if ( roar_vio_open_pgp_store(tc, prev, ROAR_VIO_PGP_OPTS_NONE) == -1 ) {
860       _ret(-1);
861      }
862     break;
[3116]863    case ROAR_VIO_DSTR_OBJT_TANTALOS:
864      if ( roar_vio_open_tantalos(tc, prev, c->dst, c->def) == -1 ) {
865       _ret(-1);
866      }
867     break;
[1328]868    case ROAR_VIO_DSTR_OBJT_SSL1:
869    case ROAR_VIO_DSTR_OBJT_SSL2:
870    case ROAR_VIO_DSTR_OBJT_SSL3:
871    case ROAR_VIO_DSTR_OBJT_TLS:
872    case ROAR_VIO_DSTR_OBJT_MAGIC:
873      _ret(-1);
874     break;
875    default:
[3313]876      if ( (type = roar_vio_dstr_get_by_type(c->type)) == NULL ) {
877       _ret(-1);
878      }
879
880      if ( type->openvio == NULL )
881       _roar_vio_dstr_init_otherlibs();
882
883      if ( type->openvio == NULL ) {
884       _ret(-1);
885      }
886
887      if ( type->openvio(tc, prev, c) == -1 ) {
888       _ret(-1);
889      }
[1328]890   }
891
892   prev = tc;
893  } // else we can skip to the next :)
894 }
895
[1616]896 ROAR_DBG("roar_vio_dstr_build_chain(*) = 0");
[1328]897 return 0;
[1323]898}
899
[1328]900#undef _ret
[1365]901#endif
[1328]902
[1321]903//ll
Note: See TracBrowser for help on using the repository browser.