source: roaraudio/libroareio/ff_ssdp.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

File size: 2.9 KB
Line 
1//ff_ssdp.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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
28static char * _sd (char * str) {
29 ssize_t len = strlen(str) + 1;
30 char * ret = roar_mm_malloc(len);
31
32 memcpy(ret, str, len);
33
34 return ret;
35}
36
37void roar_ff_ssdp_init (struct roar_ff_ssdp * c) {
38 memset(c, 0, sizeof(struct roar_ff_ssdp));
39
40 c->method        = ROAR_FF_SSDP_M_NOTIFY;
41 c->server        = _sd("RoarAudio libroareio/ff_ssdp.c");
42 c->max_age       = 1800;
43 c->location      = NULL;
44 c->nt            = NULL;
45 c->usn           = NULL;
46 c->usn_nt_suffix = 1;
47 c->host          = _sd(ROAR_FF_SSDP_HOST_UPNP);
48}
49
50void roar_ff_ssdp_free (struct roar_ff_ssdp * c) {
51 if ( c->server != NULL )
52  roar_mm_free(c->server);
53
54 if ( c->location != NULL )
55  roar_mm_free(c->location);
56
57 if ( c->nt != NULL )
58  roar_mm_free(c->nt);
59
60 if ( c->usn != NULL )
61  roar_mm_free(c->usn);
62
63 if ( c->host != NULL )
64  roar_mm_free(c->host);
65
66 memset(c, 0, sizeof(struct roar_ff_ssdp));
67}
68
69int  roar_ff_ssdp_write(struct roar_vio_calls * vio, struct roar_ff_ssdp * c) {
70 char * met;
71 char * nts;
72
73 switch (c->method) {
74  case ROAR_FF_SSDP_M_NOTIFY:   met = ROAR_FF_SSDP_MS_NOTIFY;   break;
75  case ROAR_FF_SSDP_M_M_SEARCH: met = ROAR_FF_SSDP_MS_M_SEARCH; break;
76  default: return -1;
77 }
78
79 switch (c->nst) {
80  case ROAR_FF_SSDP_A_ALIVE:  nts = ROAR_FF_SSDP_AS_ALIVE;  break;
81  case ROAR_FF_SSDP_A_BYEBYE: nts = ROAR_FF_SSDP_AS_BYEBYE; break;
82  default: return -1;
83 }
84
85 roar_vio_printf(vio, "%s * HTTP/1.1\r\n", met);
86 roar_vio_printf(vio, "SERVER: %s\r\n", c->server);
87 roar_vio_printf(vio, "CACHE-CONTROL: max-age=%i\r\n", c->max_age);
88 roar_vio_printf(vio, "LOCATION: %s\r\n", c->location);
89 roar_vio_printf(vio, "NTS: %s\r\n", nts);
90 roar_vio_printf(vio, "NT: %s\r\n", c->nt);
91
92 if ( c->usn_nt_suffix ) {
93  roar_vio_printf(vio, "USN: %s::%s\r\n", c->usn, c->nt);
94 } else {
95  roar_vio_printf(vio, "USN: %s\r\n", c->usn);
96 }
97
98 roar_vio_printf(vio, "HOST: %s\r\n", c->host);
99 roar_vio_printf(vio, "\r\n");
100
101 return 0;
102}
103int  roar_ff_ssdp_read (struct roar_vio_calls * vio, struct roar_ff_ssdp * c) {
104 return -1;
105}
106
107
108//ll
Note: See TracBrowser for help on using the repository browser.