1 | //connection.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
5 | * |
---|
6 | * The code (may) include prototypes and comments (and maybe |
---|
7 | * other code fragements) from the yiff sound system. |
---|
8 | * According to the debian/copyright file upstream author is |
---|
9 | * Tara Milana <learfox@twu.net>. Also copyright is listed as: |
---|
10 | * Copyright (C) 1997-2003 WolfPack Entertainment |
---|
11 | * |
---|
12 | * This file is part of libroaryiff a part of RoarAudio, |
---|
13 | * a cross-platform sound system for both, home and professional use. |
---|
14 | * See README for details. |
---|
15 | * |
---|
16 | * This file is free software; you can redistribute it and/or modify |
---|
17 | * it under the terms of the GNU General Public License version 3 |
---|
18 | * as published by the Free Software Foundation. |
---|
19 | * |
---|
20 | * libroaryiff is distributed in the hope that it will be useful, |
---|
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
23 | * GNU General Public License for more details. |
---|
24 | * |
---|
25 | * You should have received a copy of the GNU General Public License |
---|
26 | * along with this software; see the file COPYING. If not, write to |
---|
27 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
28 | * Boston, MA 02110-1301, USA. |
---|
29 | * |
---|
30 | * NOTE: code fragments (like prototypes) taken from the yiff package |
---|
31 | * are 'GPLv2 or later' and are upgraded to GPLv3 by being used |
---|
32 | * within this document. |
---|
33 | * |
---|
34 | */ |
---|
35 | |
---|
36 | #include <libroaryiff.h> |
---|
37 | |
---|
38 | YConnection *YOpenConnection (const char *start_arg, const char *con_arg) { |
---|
39 | YConnection * ycon = roar_mm_malloc(sizeof(YConnection)); |
---|
40 | struct roar_connection con; |
---|
41 | char * server = (char *)con_arg; |
---|
42 | char * name = "libroaryiff client"; |
---|
43 | |
---|
44 | memset(ycon, 0, sizeof(YConnection)); |
---|
45 | |
---|
46 | // there is no symbolic value for default con_arg |
---|
47 | // in the heder files. So we use a hard coded value from the docs |
---|
48 | |
---|
49 | if ( server != NULL ) { |
---|
50 | if ( strcmp(server, "127.0.0.1:9433") == 0 || |
---|
51 | strcmp(server, "127.0.0.1") == 0 || // \\ // |
---|
52 | strcmp(server, "localhost") == 0 || // => Don't know if this is valid for libY // |
---|
53 | strcmp(server, "localhost:9433") == 0 ) { // // but we support it. // |
---|
54 | |
---|
55 | server = NULL; // try default locations |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | if (roar_simple_connect(&con, server, name) == -1) { |
---|
60 | // Handle start_arg here! |
---|
61 | roar_mm_free(ycon); |
---|
62 | return NULL; |
---|
63 | } |
---|
64 | |
---|
65 | if ( (ycon->fd = roar_get_connection_fh(&con)) == -1 ) { |
---|
66 | roar_disconnect(&con); |
---|
67 | roar_mm_free(ycon); |
---|
68 | return NULL; |
---|
69 | } |
---|
70 | |
---|
71 | return ycon; |
---|
72 | } |
---|
73 | |
---|
74 | void YCloseConnection (YConnection *connection, Boolean no_shutdown) { |
---|
75 | if ( connection == NULL ) |
---|
76 | return; |
---|
77 | |
---|
78 | roar_simple_close(connection->fd); // roard will clean up all other sockets if the close the main one. |
---|
79 | |
---|
80 | |
---|
81 | roar_mm_free(connection); |
---|
82 | } |
---|
83 | |
---|
84 | //ll |
---|