]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/generic_utils.h
added a debug_handler for verbose output
[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 #define equals(a,b) !strcmp(a,b) 
17
18 /** Malloc's, checks for NULL, clears all memory bits and 
19   * returns the pointer
20   * 
21   * @param size How many bytes of memory to allocate
22   */
23 inline void* safe_malloc( int size );
24
25 /* 10M limit on buffers for overflow protection */
26 #define BUFFER_MAX_SIZE 10485760 
27
28 // ---------------------------------------------------------------------------------
29 // Generic growing buffer. Add data all you want
30 // ---------------------------------------------------------------------------------
31 struct growing_buffer_struct {
32         char *buf;
33         int n_used;
34         int size;
35 };
36 typedef struct growing_buffer_struct growing_buffer;
37
38 growing_buffer* buffer_init( int initial_num_bytes);
39 int buffer_addchar(growing_buffer* gb, char c);
40 int buffer_add(growing_buffer* gb, char* c);
41 int buffer_reset( growing_buffer* gb);
42 char* buffer_data( growing_buffer* gb);
43 int buffer_free( growing_buffer* gb );
44
45
46 void log_free(); 
47
48 // Utility method
49 void get_timestamp( char buf_25chars[]);
50
51 // ---------------------------------------------------------------------------------
52 // Error handling interface.
53 // ---------------------------------------------------------------------------------
54
55 void fatal_handler( char* message, ...);
56 void warning_handler( char* message, ... );
57 void info_handler( char* message, ... );
58 void debug_handler( char* message, ... );
59
60 // ---------------------------------------------------------------------------------
61 // Config file module
62 // ---------------------------------------------------------------------------------
63 struct config_reader_struct {
64         xmlDocPtr config_doc;
65         xmlXPathContextPtr xpathCx;
66 };
67 typedef struct config_reader_struct config_reader;
68 config_reader* conf_reader;
69
70 void config_reader_init( char* config_file );
71
72 void config_reader_free();
73
74 // allocastes a char*. FREE me.
75 char* config_value( const char* xpath_query, ... );
76
77 #endif