source: roaraudio/libroareio/ff_ssdp.c @ 3205:eade78a7d3fc

Last change on this file since 3205:eade78a7d3fc was 3205:eade78a7d3fc, checked in by phi, 14 years ago

added all but read support for ssdp

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