XMMS2
|
00001 /* XMMS2 - X Music Multiplexer System 00002 * Copyright (C) 2003-2011 XMMS2 Team 00003 * 00004 * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!! 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 */ 00016 00017 #include <stdlib.h> 00018 #include <string.h> 00019 00020 #include "xmmsc/xmmsc_util.h" 00021 #include "xmmsc/xmmsc_ipc_transport.h" 00022 #include "socket_unix.h" 00023 #include "socket_tcp.h" 00024 #include "url.h" 00025 00026 void 00027 xmms_ipc_transport_destroy (xmms_ipc_transport_t *ipct) 00028 { 00029 x_return_if_fail (ipct); 00030 00031 ipct->destroy_func (ipct); 00032 00033 free (ipct); 00034 } 00035 00036 int 00037 xmms_ipc_transport_read (xmms_ipc_transport_t *ipct, char *buffer, int len) 00038 { 00039 return ipct->read_func (ipct, buffer, len); 00040 } 00041 00042 int 00043 xmms_ipc_transport_write (xmms_ipc_transport_t *ipct, char *buffer, int len) 00044 { 00045 return ipct->write_func (ipct, buffer, len); 00046 } 00047 00048 xmms_socket_t 00049 xmms_ipc_transport_fd_get (xmms_ipc_transport_t *ipct) 00050 { 00051 x_return_val_if_fail (ipct, -1); 00052 return ipct->fd; 00053 } 00054 00055 xmms_ipc_transport_t * 00056 xmms_ipc_server_accept (xmms_ipc_transport_t *ipct) 00057 { 00058 x_return_val_if_fail (ipct, NULL); 00059 00060 if (!ipct->accept_func) 00061 return NULL; 00062 00063 return ipct->accept_func (ipct); 00064 } 00065 00066 char * 00067 xmms_ipc_hostname (const char *path) 00068 { 00069 xmms_url_t *url; 00070 char* ret = NULL; 00071 00072 url = parse_url (path); 00073 if (!strcasecmp (url->protocol, "tcp")) { 00074 if (strlen (url->host)) { 00075 ret = strdup (url->host); 00076 } 00077 } 00078 free_url (url); 00079 00080 return ret; 00081 } 00082