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
26void
28{
29 x_return_if_fail (ipct);
30
31 ipct->destroy_func (ipct);
32
33 free (ipct);
34}
35
36int
37xmms_ipc_transport_read (xmms_ipc_transport_t *ipct, char *buffer, int len)
38{
39 return ipct->read_func (ipct, buffer, len);
40}
41
42int
43xmms_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
66char *
67xmms_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
xmms_ipc_accept_func accept_func
xmms_ipc_read_func read_func
xmms_ipc_destroy_func destroy_func
xmms_ipc_write_func write_func
char * protocol
Definition url.h:5
char * host
Definition url.h:9
void xmms_ipc_transport_destroy(xmms_ipc_transport_t *ipct)
Definition transport.c:27
int xmms_ipc_transport_read(xmms_ipc_transport_t *ipct, char *buffer, int len)
Definition transport.c:37
xmms_socket_t xmms_ipc_transport_fd_get(xmms_ipc_transport_t *ipct)
Definition transport.c:49
int xmms_ipc_transport_write(xmms_ipc_transport_t *ipct, char *buffer, int len)
Definition transport.c:43
xmms_ipc_transport_t * xmms_ipc_server_accept(xmms_ipc_transport_t *ipct)
Definition transport.c:56
char * xmms_ipc_hostname(const char *path)
Definition transport.c:67
void free_url(xmms_url_t *url)
Definition url.c:94
xmms_url_t * parse_url(const char *url)
Split a URL into its respective parts.
Definition url.c:17
int xmms_socket_t
#define x_return_val_if_fail(expr, val)
Definition xmmsc_util.h:13
#define x_return_if_fail(expr)
Definition xmmsc_util.h:12