]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/generic_utils.h
e81f76f8beb46330f54d114a4941111bacad547c
[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 #include "utils.h"
14
15 #ifndef GENERIC_UTILS_H
16 #define GENERIC_UTILS_H
17
18 #define LOG_ERROR 1
19 #define LOG_WARNING 2
20 #define LOG_INFO 3
21 #define LOG_DEBUG 4
22
23
24 #define equals(a,b) !strcmp(a,b) 
25
26
27 /*
28 inline void* safe_malloc( int size );
29
30 #define BUFFER_MAX_SIZE 10485760 
31
32 struct growing_buffer_struct {
33         char *buf;
34         int n_used;
35         int size;
36 };
37 typedef struct growing_buffer_struct growing_buffer;
38
39 growing_buffer* buffer_init( int initial_num_bytes);
40 int buffer_addchar(growing_buffer* gb, char c);
41 int buffer_add(growing_buffer* gb, char* c);
42 int buffer_reset( growing_buffer* gb);
43 char* buffer_data( growing_buffer* gb);
44 int buffer_free( growing_buffer* gb );
45 int buffer_fadd(growing_buffer* gb, const char* format, ... );
46 */
47
48
49 void log_free(); 
50
51 // Utility method
52 void get_timestamp( char buf_36chars[]);
53 double get_timestamp_millis();
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 void debug_handler( char* message, ... );
63
64 /** If we return 0 either the log level is less than LOG_ERROR  
65   * or we could not open the log file
66   */
67 int log_init( int log_level, char* log_file );
68
69 // ---------------------------------------------------------------------------------
70 // Config file module
71 // ---------------------------------------------------------------------------------
72 struct config_reader_struct {
73         xmlDocPtr config_doc;
74         xmlXPathContextPtr xpathCx;
75         char* name;
76         struct config_reader_struct* next;
77 };
78 typedef struct config_reader_struct config_reader;
79 config_reader* conf_reader;
80
81 //void config_reader_init( char* config_file );
82 void config_reader_init( char* name, char* config_file );
83
84 void config_reader_free();
85
86 // allocastes a char*. FREE me.
87 char* config_value( const char* config_name, const char* xp_query, ... );
88
89 #endif