config.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * config.h
  3. * Functions for the manipulation of configuration files.
  4. *
  5. * Matej Pfajfar <mp292@cam.ac.uk>
  6. */
  7. /*
  8. * Changes :
  9. * $Log$
  10. * Revision 1.1 2002/06/26 22:45:50 arma
  11. * Initial revision
  12. *
  13. * Revision 1.7 2002/04/02 14:27:11 badbytes
  14. * Final finishes.
  15. *
  16. * Revision 1.6 2002/01/26 18:42:15 mp292
  17. * Reviewed according to Secure-Programs-HOWTO.
  18. *
  19. * Revision 1.5 2002/01/21 21:07:56 mp292
  20. * Parameter checking was missing in some functions.
  21. *
  22. * Revision 1.4 2001/12/18 10:37:47 badbytes
  23. * Header files now only apply if they were not previously included from somewhere else.
  24. *
  25. * Revision 1.3 2001/12/07 09:38:03 badbytes
  26. * Tested.
  27. *
  28. * Revision 1.2 2001/12/06 15:43:50 badbytes
  29. * config.c compiles. Proceeding to test it.
  30. *
  31. * Revision 1.1 2001/11/22 01:20:27 mp292
  32. * Functions for dealing with configuration files.
  33. *
  34. *
  35. */
  36. #ifndef __CONFIG_H
  37. # include <stdio.h>
  38. /* enumeration of types which option values can take */
  39. #define CONFIG_TYPE_STRING 0
  40. #define CONFIG_TYPE_CHAR 1
  41. #define CONFIG_TYPE_INT 2
  42. #define CONFIG_TYPE_LONG 3
  43. #define CONFIG_TYPE_DOUBLE 4
  44. /* max. length of an option keyword */
  45. #define CONFIG_KEYWORD_MAXLEN 255
  46. /* max. length (in characters) of an option value */
  47. #define CONFIG_VALUE_MAXLEN 255
  48. /* legal characters in a filename */
  49. #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
  50. typedef struct
  51. {
  52. unsigned char *keyword; /* option keyword */
  53. unsigned int r_type; /* return type as defined above */
  54. union /* return value */
  55. {
  56. char *str;
  57. char c;
  58. int i;
  59. long l;
  60. double d;
  61. } r;
  62. int err; /* 1 OK
  63. * 0 keyword not found
  64. * -1 error while parsing */
  65. } config_opt_t;
  66. /* open configuration file for reading */
  67. FILE *open_config(const unsigned char *filename);
  68. /* close configuration file */
  69. int close_config(FILE *f);
  70. /* parse the config file and obtain required option values */
  71. int parse_config(FILE *f, config_opt_t *option);
  72. #define __CONFIG_H
  73. #endif