source: roaraudio/roarclients/roarclientpass.c @ 4060:1e8dfc6257bf

Last change on this file since 4060:1e8dfc6257bf was 4060:1e8dfc6257bf, checked in by phi, 14 years ago

added tool roarclientpass

File size: 3.7 KB
Line 
1//roarclientpass.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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#include <roaraudio.h>
27
28void usage (void) {
29 printf("roarclientpass [OPTIONS]...\n");
30
31 printf("\nOptions:\n\n");
32
33 printf("  --server    SERVER    - Set server hostname\n"
34        "  --stdin               - Client is on stdin\n"
35        "  --stdout              - Client is on stdout\n"
36        "  --stdio               - Same as --stdin --stdout\n"
37        "  --stderr              - Client is on stderr\n"
38        "  --client-fh FH        - Client is on FH\n"
39        "  --proto PROTO         - Client uses protocol PROTO (default: RoarAudio)\n"
40        "  --byteorder BO        - Client uses byteorder BO (default: network)\n"
41        "  --listen              - This is a listen mode connection\n"
42        "  --help                - Show this help\n"
43       );
44
45}
46
47#define _BV(x) (1<<(x))
48#define F_STDIN  _BV(ROAR_STDIN)
49#define F_STDOUT _BV(ROAR_STDOUT)
50#define F_STDERR _BV(ROAR_STDERR)
51
52int main (int argc, char * argv[]) {
53 struct roar_connection    con;
54 struct roar_client        client;
55 char * server    = NULL;
56 char * k;
57 int    i;
58 int    clientfh  = -1;
59 int    cflags    = 0;
60 int    flags     = 0;
61 int    proto     = ROAR_PROTO_ROARAUDIO;
62 int    byteorder = ROAR_BYTEORDER_NETWORK;
63
64 for (i = 1; i < argc; i++) {
65  k = argv[i];
66
67  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
68   server = argv[++i];
69  } else if ( !strcmp(k, "--stdin") ) {
70   cflags |= F_STDIN;
71  } else if ( !strcmp(k, "--stdout") ) {
72   cflags |= F_STDOUT;
73  } else if ( !strcmp(k, "--stderr") ) {
74   cflags |= F_STDERR;
75  } else if ( !strcmp(k, "--stdio") ) {
76   cflags |= F_STDIN|F_STDOUT;
77  } else if ( !strcmp(k, "--client-fh") ) {
78   clientfh = atoi(argv[++i]);
79  } else if ( !strcmp(k, "--proto") ) {
80   proto = roar_str2proto(argv[++i]);
81  } else if ( !strcmp(k, "--byteorder") ) {
82   byteorder = roar_str2byteorder(argv[++i]);
83  } else if ( !strcmp(k, "--listen") ) {
84   flags |= ROAR_CLIENTPASS_FLAG_LISTEN;
85  } else {
86   ROAR_ERR("unknown argument: %s", k);
87   usage();
88   return 1;
89  }
90 }
91
92 if ( cflags & F_STDERR ) {
93#ifdef ROAR_HAVE_SYSLOG
94  roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
95#else
96  roar_debug_set_stderr_fh(-1);
97#endif
98 } else {
99  roar_debug_set_stderr_fh(ROAR_STDERR);
100 }
101
102 if ( clientfh == -1 ) {
103  if ( cflags & F_STDIN ) {
104   clientfh = ROAR_STDIN;
105  } else if ( cflags & F_STDOUT ) {
106   clientfh = ROAR_STDOUT;
107  } else if ( cflags & F_STDERR ) {
108   clientfh = ROAR_STDERR;
109  } else {
110   ROAR_ERR("No client socket given");
111  }
112 }
113
114 roar_client_new(&client);
115 roar_client_set_fh(&client, clientfh);
116 roar_client_set_proto(&client, proto, byteorder);
117
118 if ( roar_simple_connect(&con, server, "roarclientpass") == -1 ) {
119  ROAR_ERR("Can not connect to server");
120  return 10;
121 }
122
123 if ( roar_client_pass(&con, &client, flags) == -1 ) {
124  ROAR_ERR("Can not pass client fh to server");
125  roar_disconnect(&con);
126  return 20;
127 }
128
129 roar_disconnect(&con);
130
131 return 0;
132}
133
134//ll
Note: See TracBrowser for help on using the repository browser.