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