1 | //connection.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - August 2008 |
---|
5 | * |
---|
6 | * This file is part of libroaryiff 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 | * libroaryiff 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
22 | * |
---|
23 | */ |
---|
24 | |
---|
25 | #include <libroaryiff.h> |
---|
26 | |
---|
27 | YConnection *YOpenConnection (const char *start_arg, const char *con_arg) { |
---|
28 | YConnection * ycon = malloc(sizeof(YConnection)); |
---|
29 | struct roar_connection con; |
---|
30 | char * server = (char *)con_arg; |
---|
31 | char * name = "libroaryiff client"; |
---|
32 | |
---|
33 | memset(ycon, 0, sizeof(YConnection)); |
---|
34 | |
---|
35 | // there is no symbolic value for default con_arg |
---|
36 | // in the heder files. So we use a hard coded value from the docs |
---|
37 | |
---|
38 | if ( server != NULL ) { |
---|
39 | if ( strcmp(server, "127.0.0.1:9433") == 0 || |
---|
40 | strcmp(server, "127.0.0.1") == 0 || // \\ // |
---|
41 | strcmp(server, "localhost") == 0 || // => Don't know if this is valid for libY // |
---|
42 | strcmp(server, "localhost:9433") == 0 ) { // // but we support it. // |
---|
43 | |
---|
44 | server = NULL; // try default locations |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | if (roar_simple_connect(&con, server, name) == -1) { |
---|
49 | // Handle start_arg here! |
---|
50 | free(ycon); |
---|
51 | return NULL; |
---|
52 | } |
---|
53 | |
---|
54 | if ( (ycon->fd = roar_get_connection_fh(&con)) == -1 ) { |
---|
55 | roar_disconnect(&con); |
---|
56 | free(ycon); |
---|
57 | return NULL; |
---|
58 | } |
---|
59 | |
---|
60 | return ycon; |
---|
61 | } |
---|
62 | |
---|
63 | void YCloseConnection (YConnection *connection, Boolean no_shutdown) { |
---|
64 | if ( !connection ) |
---|
65 | return; |
---|
66 | |
---|
67 | roar_simple_close(connection->fd); // roard will clean up all other sockets if the close the main one. |
---|
68 | |
---|
69 | |
---|
70 | free(connection); |
---|
71 | } |
---|
72 | |
---|
73 | //ll |
---|