1 | //ff_ssdp.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 |
---|
5 | * |
---|
6 | * This file is part of libroareio 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 | * libroardsp 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 |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "libroareio.h" |
---|
27 | |
---|
28 | void roar_ff_ssdp_init (struct roar_ff_ssdp * c) { |
---|
29 | memset(c, 0, sizeof(struct roar_ff_ssdp)); |
---|
30 | |
---|
31 | c->method = ROAR_FF_SSDP_M_NOTIFY; |
---|
32 | c->server = roar_mm_strdup("RoarAudio libroareio/ff_ssdp.c"); |
---|
33 | c->max_age = 1800; |
---|
34 | c->location = NULL; |
---|
35 | c->nt = NULL; |
---|
36 | c->usn = NULL; |
---|
37 | c->usn_nt_suffix = 1; |
---|
38 | c->host = roar_mm_strdup(ROAR_FF_SSDP_HOST_UPNP); |
---|
39 | } |
---|
40 | |
---|
41 | void roar_ff_ssdp_free (struct roar_ff_ssdp * c) { |
---|
42 | if ( c->server != NULL ) |
---|
43 | roar_mm_free(c->server); |
---|
44 | |
---|
45 | if ( c->location != NULL ) |
---|
46 | roar_mm_free(c->location); |
---|
47 | |
---|
48 | if ( c->nt != NULL ) |
---|
49 | roar_mm_free(c->nt); |
---|
50 | |
---|
51 | if ( c->usn != NULL ) |
---|
52 | roar_mm_free(c->usn); |
---|
53 | |
---|
54 | if ( c->host != NULL ) |
---|
55 | roar_mm_free(c->host); |
---|
56 | |
---|
57 | memset(c, 0, sizeof(struct roar_ff_ssdp)); |
---|
58 | } |
---|
59 | |
---|
60 | int roar_ff_ssdp_write(struct roar_vio_calls * vio, struct roar_ff_ssdp * c) { |
---|
61 | char * met; |
---|
62 | char * nts; |
---|
63 | |
---|
64 | switch (c->method) { |
---|
65 | case ROAR_FF_SSDP_M_NOTIFY: met = ROAR_FF_SSDP_MS_NOTIFY; break; |
---|
66 | case ROAR_FF_SSDP_M_M_SEARCH: met = ROAR_FF_SSDP_MS_M_SEARCH; break; |
---|
67 | default: return -1; |
---|
68 | } |
---|
69 | |
---|
70 | switch (c->nst) { |
---|
71 | case ROAR_FF_SSDP_A_ALIVE: nts = ROAR_FF_SSDP_AS_ALIVE; break; |
---|
72 | case ROAR_FF_SSDP_A_BYEBYE: nts = ROAR_FF_SSDP_AS_BYEBYE; break; |
---|
73 | default: return -1; |
---|
74 | } |
---|
75 | |
---|
76 | roar_vio_printf(vio, "%s * HTTP/1.1\r\n", met); |
---|
77 | roar_vio_printf(vio, "SERVER: %s\r\n", c->server); |
---|
78 | roar_vio_printf(vio, "CACHE-CONTROL: max-age=%i\r\n", c->max_age); |
---|
79 | roar_vio_printf(vio, "LOCATION: %s\r\n", c->location); |
---|
80 | roar_vio_printf(vio, "NTS: %s\r\n", nts); |
---|
81 | roar_vio_printf(vio, "NT: %s\r\n", c->nt); |
---|
82 | |
---|
83 | if ( c->usn_nt_suffix ) { |
---|
84 | roar_vio_printf(vio, "USN: %s::%s\r\n", c->usn, c->nt); |
---|
85 | } else { |
---|
86 | roar_vio_printf(vio, "USN: %s\r\n", c->usn); |
---|
87 | } |
---|
88 | |
---|
89 | roar_vio_printf(vio, "HOST: %s\r\n", c->host); |
---|
90 | roar_vio_printf(vio, "\r\n"); |
---|
91 | |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | int roar_ff_ssdp_read (struct roar_vio_calls * vio, struct roar_ff_ssdp * c) { |
---|
96 | roar_err_set(ROAR_ERROR_NOSYS); |
---|
97 | return -1; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | //ll |
---|