mptsd reads mpegts streams from udp/multicast or http and combines them into one multiple program stream that is suitable for outputting to DVB-C modulator. Tested with Dektec DTE-3114 Quad QAM Modulator and used in production in small DVB-C networks. https://georgi.unixsol.org/programs/mptsd/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iniparser.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. Copyright (c) 2000-2007 by Nicolas Devillard.
  3. MIT License
  4. Permission is hereby granted, free of charge, to any person obtaining a
  5. copy of this software and associated documentation files (the "Software"),
  6. to deal in the Software without restriction, including without limitation
  7. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. and/or sell copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. DEALINGS IN THE SOFTWARE.
  19. */
  20. /*-------------------------------------------------------------------------*/
  21. /**
  22. @file iniparser.h
  23. @author N. Devillard
  24. @date Sep 2007
  25. @version 3.0
  26. @brief Parser for ini files.
  27. */
  28. /*--------------------------------------------------------------------------*/
  29. /*
  30. Id: iniparser.h,v 1.24 2007-11-23 21:38:19 ndevilla Exp
  31. Revision: 1.24
  32. */
  33. #ifndef _INIPARSER_H_
  34. #define _INIPARSER_H_
  35. /*---------------------------------------------------------------------------
  36. Includes
  37. ---------------------------------------------------------------------------*/
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. /*
  42. * The following #include is necessary on many Unixes but not Linux.
  43. * It is not needed for Windows platforms.
  44. * Uncomment it if needed.
  45. */
  46. #include <unistd.h>
  47. #include "inidict.h"
  48. /* Local extras */
  49. char * ini_get_string (dictionary *d, char *def , const char *keyfmt, ...);
  50. char * ini_get_string_copy (dictionary *d, char *def , const char *keyfmt, ...);
  51. int ini_get_int (dictionary *d, int def , const char *keyfmt, ...);
  52. double ini_get_double (dictionary *d, double def, const char *keyfmt, ...);
  53. int ini_get_bool (dictionary *d, int def , const char *keyfmt, ...);
  54. /*---------------------------------------------------------------------------
  55. Macros
  56. ---------------------------------------------------------------------------*/
  57. /** For backwards compatibility only */
  58. #define iniparser_getstr(d, k) iniparser_getstring(d, k, NULL)
  59. #define iniparser_setstr iniparser_setstring
  60. /*-------------------------------------------------------------------------*/
  61. /**
  62. @brief Get number of sections in a dictionary
  63. @param d Dictionary to examine
  64. @return int Number of sections found in dictionary
  65. This function returns the number of sections found in a dictionary.
  66. The test to recognize sections is done on the string stored in the
  67. dictionary: a section name is given as "section" whereas a key is
  68. stored as "section:key", thus the test looks for entries that do not
  69. contain a colon.
  70. This clearly fails in the case a section name contains a colon, but
  71. this should simply be avoided.
  72. This function returns -1 in case of error.
  73. */
  74. /*--------------------------------------------------------------------------*/
  75. int iniparser_getnsec(dictionary * d);
  76. /*-------------------------------------------------------------------------*/
  77. /**
  78. @brief Get name for section n in a dictionary.
  79. @param d Dictionary to examine
  80. @param n Section number (from 0 to nsec-1).
  81. @return Pointer to char string
  82. This function locates the n-th section in a dictionary and returns
  83. its name as a pointer to a string statically allocated inside the
  84. dictionary. Do not free or modify the returned string!
  85. This function returns NULL in case of error.
  86. */
  87. /*--------------------------------------------------------------------------*/
  88. char * iniparser_getsecname(dictionary * d, int n);
  89. /*-------------------------------------------------------------------------*/
  90. /**
  91. @brief Save a dictionary to a loadable ini file
  92. @param d Dictionary to dump
  93. @param f Opened file pointer to dump to
  94. @return void
  95. This function dumps a given dictionary into a loadable ini file.
  96. It is Ok to specify @c stderr or @c stdout as output files.
  97. */
  98. /*--------------------------------------------------------------------------*/
  99. void iniparser_dump_ini(dictionary * d, FILE * f);
  100. /*-------------------------------------------------------------------------*/
  101. /**
  102. @brief Dump a dictionary to an opened file pointer.
  103. @param d Dictionary to dump.
  104. @param f Opened file pointer to dump to.
  105. @return void
  106. This function prints out the contents of a dictionary, one element by
  107. line, onto the provided file pointer. It is OK to specify @c stderr
  108. or @c stdout as output files. This function is meant for debugging
  109. purposes mostly.
  110. */
  111. /*--------------------------------------------------------------------------*/
  112. void iniparser_dump(dictionary * d, FILE * f);
  113. /*-------------------------------------------------------------------------*/
  114. /**
  115. @brief Get the string associated to a key
  116. @param d Dictionary to search
  117. @param key Key string to look for
  118. @param def Default value to return if key not found.
  119. @return pointer to statically allocated character string
  120. This function queries a dictionary for a key. A key as read from an
  121. ini file is given as "section:key". If the key cannot be found,
  122. the pointer passed as 'def' is returned.
  123. The returned char pointer is pointing to a string allocated in
  124. the dictionary, do not free or modify it.
  125. */
  126. /*--------------------------------------------------------------------------*/
  127. char * iniparser_getstring(dictionary * d, const char * key, char * def);
  128. /*-------------------------------------------------------------------------*/
  129. /**
  130. @brief Get the string associated to a key, convert to an int
  131. @param d Dictionary to search
  132. @param key Key string to look for
  133. @param notfound Value to return in case of error
  134. @return integer
  135. This function queries a dictionary for a key. A key as read from an
  136. ini file is given as "section:key". If the key cannot be found,
  137. the notfound value is returned.
  138. Supported values for integers include the usual C notation
  139. so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
  140. are supported. Examples:
  141. - "42" -> 42
  142. - "042" -> 34 (octal -> decimal)
  143. - "0x42" -> 66 (hexa -> decimal)
  144. Warning: the conversion may overflow in various ways. Conversion is
  145. totally outsourced to strtol(), see the associated man page for overflow
  146. handling.
  147. Credits: Thanks to A. Becker for suggesting strtol()
  148. */
  149. /*--------------------------------------------------------------------------*/
  150. int iniparser_getint(dictionary * d, const char * key, int notfound);
  151. /*-------------------------------------------------------------------------*/
  152. /**
  153. @brief Get the string associated to a key, convert to a double
  154. @param d Dictionary to search
  155. @param key Key string to look for
  156. @param notfound Value to return in case of error
  157. @return double
  158. This function queries a dictionary for a key. A key as read from an
  159. ini file is given as "section:key". If the key cannot be found,
  160. the notfound value is returned.
  161. */
  162. /*--------------------------------------------------------------------------*/
  163. double iniparser_getdouble(dictionary * d, char * key, double notfound);
  164. /*-------------------------------------------------------------------------*/
  165. /**
  166. @brief Get the string associated to a key, convert to a boolean
  167. @param d Dictionary to search
  168. @param key Key string to look for
  169. @param notfound Value to return in case of error
  170. @return integer
  171. This function queries a dictionary for a key. A key as read from an
  172. ini file is given as "section:key". If the key cannot be found,
  173. the notfound value is returned.
  174. A true boolean is found if one of the following is matched:
  175. - A string starting with 'y'
  176. - A string starting with 'Y'
  177. - A string starting with 't'
  178. - A string starting with 'T'
  179. - A string starting with '1'
  180. A false boolean is found if one of the following is matched:
  181. - A string starting with 'n'
  182. - A string starting with 'N'
  183. - A string starting with 'f'
  184. - A string starting with 'F'
  185. - A string starting with '0'
  186. The notfound value returned if no boolean is identified, does not
  187. necessarily have to be 0 or 1.
  188. */
  189. /*--------------------------------------------------------------------------*/
  190. int iniparser_getboolean(dictionary * d, const char * key, int notfound);
  191. /*-------------------------------------------------------------------------*/
  192. /**
  193. @brief Set an entry in a dictionary.
  194. @param ini Dictionary to modify.
  195. @param entry Entry to modify (entry name)
  196. @param val New value to associate to the entry.
  197. @return int 0 if Ok, -1 otherwise.
  198. If the given entry can be found in the dictionary, it is modified to
  199. contain the provided value. If it cannot be found, -1 is returned.
  200. It is Ok to set val to NULL.
  201. */
  202. /*--------------------------------------------------------------------------*/
  203. int iniparser_setstring(dictionary * ini, char * entry, char * val);
  204. /*-------------------------------------------------------------------------*/
  205. /**
  206. @brief Delete an entry in a dictionary
  207. @param ini Dictionary to modify
  208. @param entry Entry to delete (entry name)
  209. @return void
  210. If the given entry can be found, it is deleted from the dictionary.
  211. */
  212. /*--------------------------------------------------------------------------*/
  213. void iniparser_unset(dictionary * ini, char * entry);
  214. /*-------------------------------------------------------------------------*/
  215. /**
  216. @brief Finds out if a given entry exists in a dictionary
  217. @param ini Dictionary to search
  218. @param entry Name of the entry to look for
  219. @return integer 1 if entry exists, 0 otherwise
  220. Finds out if a given entry exists in the dictionary. Since sections
  221. are stored as keys with NULL associated values, this is the only way
  222. of querying for the presence of sections in a dictionary.
  223. */
  224. /*--------------------------------------------------------------------------*/
  225. int iniparser_find_entry(dictionary * ini, char * entry) ;
  226. /*-------------------------------------------------------------------------*/
  227. /**
  228. @brief Parse an ini file and return an allocated dictionary object
  229. @param ininame Name of the ini file to read.
  230. @return Pointer to newly allocated dictionary
  231. This is the parser for ini files. This function is called, providing
  232. the name of the file to be read. It returns a dictionary object that
  233. should not be accessed directly, but through accessor functions
  234. instead.
  235. The returned dictionary must be freed using iniparser_freedict().
  236. */
  237. /*--------------------------------------------------------------------------*/
  238. dictionary * iniparser_load(const char * ininame);
  239. /*-------------------------------------------------------------------------*/
  240. /**
  241. @brief Free all memory associated to an ini dictionary
  242. @param d Dictionary to free
  243. @return void
  244. Free all memory associated to an ini dictionary.
  245. It is mandatory to call this function before the dictionary object
  246. gets out of the current context.
  247. */
  248. /*--------------------------------------------------------------------------*/
  249. void iniparser_freedict(dictionary **d);
  250. #endif