File: rpldslp.c

package info (click to toggle)
roarplaylistd 0.1.9-7
  • links: PTS
  • area: main
  • in suites: buster
  • size: 848 kB
  • sloc: ansic: 9,489; sh: 695; perl: 500; makefile: 82
file content (95 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//rpldslp.c:

/*
 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
 *
 *  This file is part of RoarAudio PlayList Daemon,
 *  a playlist management daemon for RoarAudio.
 *  See README for details.
 *
 *  This file is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  RoarAudio is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#include "rpld.h"

#ifdef HAVE_LIB_SLP
void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
 (void)hslp;

 /* return the error code in the cookie */
 *(SLPError*)cookie = errcode;
}


int register_slp (int unreg, const char * sockname) {
 static int regged = 0;
 static const char * sn = NULL;
 SLPError err;
 SLPError callbackerr;
 SLPHandle hslp;
 char addr[1024];

 if ( sockname != NULL )
  sn = sockname;

 snprintf(addr, sizeof(addr), RPLD_SLP_TYPE_RPLD "://%s", sn);

 err = SLPOpen("en", SLP_FALSE, &hslp);

 if (err != SLP_OK) {
  ROAR_ERR("Error opening slp handle: Error #%i", err);
  return -1;
 }

 if (!unreg) {
  err = SLPReg(hslp,
               addr,
               SLP_LIFETIME_MAXIMUM,
               NULL,
               "", /* attributes */
               SLP_TRUE,
               register_slp_callback,
               &callbackerr);
  regged = 1;
 } else if ( unreg && regged ) {
  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
  regged = 0;
 } else {
  SLPClose(hslp);
  return -1;
 }

 /* err may contain an error code that occurred as the slp library    */
 /* _prepared_ to make the call.                                     */
 if ( err != SLP_OK ) {
  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
  return -1;
 }

 /* callbackerr may contain an error code (that was assigned through */
 /* the callback cookie) that occurred as slp packets were sent on    */
 /* the wire */
 if (callbackerr != SLP_OK) {
  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
  return -1;
 }

 SLPClose(hslp);
 return 0;
}
#endif

//ll