1 /* util.h: libshout utility/portability functions
2  *
3  *  Copyright 2002-2004 the Icecast team <team@icecast.org>,
4  *  Copyright 2012-2015 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 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  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public
17  *  License along with this library; if not, write to the Free
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * $Id$
21  */
22 
23 #ifndef __LIBSHOUT_UTIL_H__
24 #define __LIBSHOUT_UTIL_H__
25 
26 /* String dictionary type, without support for NULL keys, or multiple
27  * instances of the same key
28  */
29 typedef struct _util_dict {
30     char *key;
31     char *val;
32     struct _util_dict *next;
33 } util_dict;
34 
35 char 		*_shout_util_strdup(const char *s);
36 
37 util_dict 	*_shout_util_dict_new(void);
38 void 		 _shout_util_dict_free(util_dict *dict);
39 
40 /* dict, key must not be NULL. */
41 int 		 _shout_util_dict_set(util_dict *dict, const char *key, const char *val);
42 const char 	*_shout_util_dict_get(util_dict *dict, const char *key);
43 char 		*_shout_util_dict_urlencode(util_dict *dict, char delim);
44 
45 const char *_shout_util_dict_next(util_dict **dict, const char **key, const char **val);
46 
47 #define _SHOUT_DICT_FOREACH(init, var, keyvar, valvar) for ((var) = (init), (keyvar) = (var)->key ? (var)->key : _shout_util_dict_next(& (var), & (keyvar), & (valvar)), (valvar) = (var)->val; (var); _shout_util_dict_next(& (var), & (keyvar), & (valvar)))
48 
49 char 	*_shout_util_base64_encode(char *data);
50 char 	*_shout_util_url_encode(const char *data);
51 char 	*_shout_util_url_encode_resource(const char *data);
52 int  	 _shout_util_read_header(int sock, char *buff, unsigned long len);
53 
54 #endif /* __LIBSHOUT_UTIL_H__ */
55