]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/generic_utils.h
altered header includes
[OpenSRF.git] / include / opensrf / generic_utils.h
1 #include <string.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <time.h>
5
6 /* libxml stuff for the config reader */
7 #include <libxml/xmlmemory.h>
8 #include <libxml/parser.h>
9 #include <libxml/xpath.h>
10 #include <libxml/xpathInternals.h>
11 #include <libxml/tree.h>
12
13 #ifndef GENERIC_UTILS_H
14 #define GENERIC_UTILS_H
15
16
17 /** Malloc's, checks for NULL, clears all memory bits and 
18   * returns the pointer
19   * 
20   * @param size How many bytes of memory to allocate
21   */
22 inline void* safe_malloc( int size );
23
24 /* 10M limit on buffers for overflow protection */
25 #define BUFFER_MAX_SIZE 10485760 
26
27 // ---------------------------------------------------------------------------------
28 // Generic growing buffer. Add data all you want
29 // ---------------------------------------------------------------------------------
30 struct growing_buffer_struct {
31         char *buf;
32         int n_used;
33         int size;
34 };
35 typedef struct growing_buffer_struct growing_buffer;
36
37 growing_buffer* buffer_init( int initial_num_bytes);
38 int buffer_addchar(growing_buffer* gb, char c);
39 int buffer_add(growing_buffer* gb, char* c);
40 int buffer_reset( growing_buffer* gb);
41 char* buffer_data( growing_buffer* gb);
42 int buffer_free( growing_buffer* gb );
43
44
45 void log_free(); 
46
47 // Utility method
48 void get_timestamp( char buf_25chars[]);
49
50 // ---------------------------------------------------------------------------------
51 // Error handling interface.
52 // ---------------------------------------------------------------------------------
53
54 void fatal_handler( char* message, ...);
55 void warning_handler( char* message, ... );
56 void info_handler( char* message, ... );
57
58 // ---------------------------------------------------------------------------------
59 // Config file module
60 // ---------------------------------------------------------------------------------
61 struct config_reader_struct {
62         xmlDocPtr config_doc;
63         xmlXPathContextPtr xpathCx;
64 };
65 typedef struct config_reader_struct config_reader;
66 config_reader* conf_reader;
67
68 void config_reader_init( char* config_file );
69
70 void config_reader_free();
71
72 // allocastes a char*. FREE me.
73 char* config_value( const char* xpath_query, ... );
74
75 #endif