XMMS2
transport.c
Go to the documentation of this file.
1 /* XMMS2 - X Music Multiplexer System
2  * Copyright (C) 2003-2011 XMMS2 Team
3  *
4  * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  */
16 
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "xmmsc/xmmsc_util.h"
22 #include "socket_unix.h"
23 #include "socket_tcp.h"
24 #include "url.h"
25 
26 void
28 {
29  x_return_if_fail (ipct);
30 
31  ipct->destroy_func (ipct);
32 
33  free (ipct);
34 }
35 
36 int
37 xmms_ipc_transport_read (xmms_ipc_transport_t *ipct, char *buffer, int len)
38 {
39  return ipct->read_func (ipct, buffer, len);
40 }
41 
42 int
43 xmms_ipc_transport_write (xmms_ipc_transport_t *ipct, char *buffer, int len)
44 {
45  return ipct->write_func (ipct, buffer, len);
46 }
47 
50 {
51  x_return_val_if_fail (ipct, -1);
52  return ipct->fd;
53 }
54 
57 {
58  x_return_val_if_fail (ipct, NULL);
59 
60  if (!ipct->accept_func)
61  return NULL;
62 
63  return ipct->accept_func (ipct);
64 }
65 
66 char *
67 xmms_ipc_hostname (const char *path)
68 {
69  xmms_url_t *url;
70  char* ret = NULL;
71 
72  url = parse_url (path);
73  if (!strcasecmp (url->protocol, "tcp")) {
74  if (strlen (url->host)) {
75  ret = strdup (url->host);
76  }
77  }
78  free_url (url);
79 
80  return ret;
81 }
82