source: roaraudio/roarclients/roarclientpass.c @ 4911:d5d79a1a14db

Last change on this file since 4911:d5d79a1a14db was 4911:d5d79a1a14db, checked in by phi, 13 years ago

use new ckport's ignore-symbol command

File size: 5.2 KB
Line 
1//roarclientpass.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
5 *
6 *  This file is part of roarclients 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_socket_open -- Used to get a clientfh.
28 */
29
30#include <roaraudio.h>
31
32void usage (void) {
33 printf("roarclientpass [OPTIONS]...\n");
34
35 printf("\nOptions:\n\n");
36
37 printf("  --server    SERVER    - Set server hostname\n"
38        "  --stdin               - Client is on stdin\n"
39        "  --stdout              - Client is on stdout\n"
40        "  --stdio               - Same as --stdin --stdout\n"
41        "  --stderr              - Client is on stderr\n"
42        "  --client-fh FH        - Client is on FH\n"
43        "  --proto PROTO         - Client uses protocol PROTO (default: RoarAudio)\n"
44        "  --byteorder BO        - Client uses byteorder BO (default: network)\n"
45        "  --listen              - This is a listen mode connection\n"
46        "  --mode MODE           - Set mode of operation: none, listen, connect (default: none)\n"
47        "  --bind BIND           - Set host/node/path for mode listen and connect\n"
48        "  --port PORT           - Set port for mode listen and connect\n"
49//        "  --type TYPE           - Set type for mode listen and connect (default: unknown)\n"
50        "  --help                - Show this help\n"
51       );
52
53}
54
55#define _BV(x) (1<<(x))
56#define F_STDIN  _BV(ROAR_STDIN)
57#define F_STDOUT _BV(ROAR_STDOUT)
58#define F_STDERR _BV(ROAR_STDERR)
59
60int main (int argc, char * argv[]) {
61 struct roar_connection    con;
62 struct roar_client        client;
63 char * server    = NULL;
64 char * k;
65 int    i;
66 int    clientfh  = -1;
67 int    cflags    = 0;
68 int    flags     = 0;
69 int    proto     = ROAR_PROTO_ROARAUDIO;
70 int    byteorder = ROAR_BYTEORDER_NETWORK;
71 int    mode      = ROAR_SOCKET_MODE_NONE;
72 int    type      = ROAR_SOCKET_TYPE_UNKNOWN;
73 char * host      = NULL;
74 int    port      = -1;
75
76 for (i = 1; i < argc; i++) {
77  k = argv[i];
78
79  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
80   server = argv[++i];
81  } else if ( !strcmp(k, "--stdin") ) {
82   cflags |= F_STDIN;
83  } else if ( !strcmp(k, "--stdout") ) {
84   cflags |= F_STDOUT;
85  } else if ( !strcmp(k, "--stderr") ) {
86   cflags |= F_STDERR;
87  } else if ( !strcmp(k, "--stdio") ) {
88   cflags |= F_STDIN|F_STDOUT;
89  } else if ( !strcmp(k, "--client-fh") ) {
90   clientfh = atoi(argv[++i]);
91  } else if ( !strcmp(k, "--proto") ) {
92   proto = roar_str2proto(argv[++i]);
93  } else if ( !strcmp(k, "--byteorder") ) {
94   byteorder = roar_str2byteorder(argv[++i]);
95  } else if ( !strcmp(k, "--listen") ) {
96   flags |= ROAR_CLIENTPASS_FLAG_LISTEN;
97  } else if ( !strcmp(k, "--mode") ) {
98   k = argv[++i];
99   if ( !strcasecmp(k, "none") ) {
100    mode = ROAR_SOCKET_MODE_NONE;
101   } else if ( !strcasecmp(k, "listen") ) {
102    mode = ROAR_SOCKET_MODE_LISTEN;
103    flags |= ROAR_CLIENTPASS_FLAG_LISTEN;
104   } else if ( !strcasecmp(k, "connect") ) {
105    mode = ROAR_SOCKET_MODE_CONNECT;
106    flags -= ROAR_CLIENTPASS_FLAG_LISTEN;
107   } else {
108    ROAR_ERR("unknown mode: %s", k);
109    return 1;
110   }
111  } else if ( !strcmp(k, "--bind") ) {
112   host = argv[++i];
113  } else if ( !strcmp(k, "--port") ) {
114   port = atoi(argv[++i]);
115  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
116   usage();
117   return 0;
118  } else {
119   ROAR_ERR("unknown argument: %s", k);
120   usage();
121   return 1;
122  }
123 }
124
125 if ( cflags & F_STDERR ) {
126#ifdef ROAR_HAVE_SYSLOG
127  roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
128#else
129  roar_debug_set_stderr_vio(roar_stderr);
130#endif
131 } else {
132  roar_debug_set_stderr_vio(roar_stderr);
133 }
134
135 if ( mode != ROAR_SOCKET_MODE_NONE ) {
136  if ( clientfh != -1 ) {
137   ROAR_ERR("Too may socket types given");
138   return 30;
139  }
140
141  clientfh = roar_socket_open(mode, type, host, port);
142
143  if ( clientfh == -1 ) {
144   ROAR_ERR("Unabled to open socket");
145   return 31;
146  }
147 }
148
149 if ( clientfh == -1 ) {
150  if ( cflags & F_STDIN ) {
151   clientfh = ROAR_STDIN;
152  } else if ( cflags & F_STDOUT ) {
153   clientfh = ROAR_STDOUT;
154  } else if ( cflags & F_STDERR ) {
155   clientfh = ROAR_STDERR;
156  } else {
157   ROAR_ERR("No client socket given");
158   return 32;
159  }
160 }
161
162 roar_client_new(&client);
163 roar_client_set_fh(&client, clientfh);
164 roar_client_set_proto(&client, proto, byteorder);
165
166 if ( roar_simple_connect(&con, server, "roarclientpass") == -1 ) {
167  ROAR_ERR("Can not connect to server");
168  return 10;
169 }
170
171 if ( roar_client_pass(&con, &client, flags) == -1 ) {
172  ROAR_ERR("Can not pass client fh to server");
173  roar_disconnect(&con);
174  return 20;
175 }
176
177 roar_disconnect(&con);
178
179 return 0;
180}
181
182//ll
Note: See TracBrowser for help on using the repository browser.