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