ggz.h

Go to the documentation of this file.
00001 
00027 #ifndef __GGZ_H__
00028 #define __GGZ_H__
00029 
00030 #define LIBGGZ_VERSION_MAJOR 0
00031 #define LIBGGZ_VERSION_MINOR 0
00032 #define LIBGGZ_VERSION_MICRO 14
00033 #define LIBGGZ_VERSION_IFACE "5:0:3"
00034 
00035 #include <sys/types.h>
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00049 #ifdef __GNUC__
00050 #  define ggz__attribute(att)  __attribute__(att)
00051 #else
00052 #  define ggz__attribute(att)
00053 #endif
00054 
00055 #if defined __GNUC__ && (__GNUC__ >= 3)
00056 #  define _GGZFUNCTION_ ""
00057 #elif defined(__sun)
00058 #  define _GGZFUNCTION_ ""
00059 #else
00060 #  ifndef __cplusplus
00061 #    define _GGZFUNCTION_ __FUNCTION__
00062 #  else
00063 #    define _GGZFUNCTION_ ""
00064 #  endif
00065 #endif
00066 
00085 #define GGZ_MEM_DEBUG "ggz_mem"
00086 
00094 #define ggz_malloc(size) _ggz_malloc(size, _GGZFUNCTION_ " in " __FILE__, __LINE__)
00095                                                    
00096 
00105 #define ggz_realloc(mem, size) _ggz_realloc(mem, size, _GGZFUNCTION_ " in " __FILE__, __LINE__)
00106                                                        
00107 
00115 #define ggz_free(mem) _ggz_free(mem, _GGZFUNCTION_ " in " __FILE__,  __LINE__)
00116                                                  
00117 
00127 #define ggz_strdup(string) _ggz_strdup(string, _GGZFUNCTION_ " in " __FILE__,  __LINE__)
00128                                                  
00129 
00130 
00141 void * _ggz_malloc(const size_t size, const char * tag, int line);
00142 
00154 void * _ggz_realloc(const void * ptr, const size_t size,
00155                     const char * tag, int line)
00156                     ggz__attribute((warn_unused_result));
00157 
00168 int _ggz_free(const void * ptr, const char * tag, int line);
00169 
00182 char * _ggz_strdup(const char * ptr, const char * tag, int line)
00183                    ggz__attribute((warn_unused_result));
00184 
00199 char * ggz_strncpy(char * dst, const char * src, size_t n);
00200 
00201 
00208 int ggz_memory_check(void);
00209 
00267 #define GGZ_CONF_DEBUG "ggz_conf"
00268 
00273 typedef enum {
00274         GGZ_CONF_RDONLY = ((unsigned char) 0x01), 
00275         GGZ_CONF_RDWR = ((unsigned char) 0x02),   
00276         GGZ_CONF_CREATE = ((unsigned char) 0x04)  
00277 } GGZConfType;
00278 
00279 
00285 void ggz_conf_cleanup (void);
00286 
00291 void ggz_conf_close (int handle);
00292 
00301 int ggz_conf_parse              (const char *path,
00302                                  const GGZConfType options);
00303 
00310 int ggz_conf_commit             (int handle);
00311 
00320 int ggz_conf_write_string       (int    handle,
00321                          const char     *section,
00322                          const char     *key,
00323                          const char     *value);
00324 
00333 int ggz_conf_write_int  (int    handle,
00334                          const char     *section,
00335                          const char     *key,
00336                          int    value);
00337 
00348 int ggz_conf_write_list (int    handle,
00349                          const char     *section,
00350                          const char     *key,
00351                          int    argc,
00352                          char   **argv);
00353 
00368 char * ggz_conf_read_string     (int    handle,
00369                          const char     *section,
00370                          const char     *key,
00371                          const char     *def);
00372 
00382 int ggz_conf_read_int   (int    handle,
00383                          const char     *section,
00384                          const char     *key,
00385                          int    def);
00386 
00405 int ggz_conf_read_list(int      handle,
00406                          const char     *section,
00407                          const char     *key,
00408                          int    *argcp,
00409                          char   ***argvp);
00410 
00418 int ggz_conf_remove_section     (int    handle,
00419                          const char     *section);
00420 
00428 int ggz_conf_remove_key (int    handle,
00429                          const char     *section,
00430                          const char     *key);
00431 
00446 int ggz_conf_get_sections (int handle,
00447                          int    *argcp,
00448                          char   ***argvp);
00449 
00465 int ggz_conf_get_keys (int handle,
00466                          const char *section,
00467                          int    *argcp,
00468                          char   ***argvp);
00469 
00486 typedef int (*ggzEntryCompare)(const void *a, const void *b);
00487 
00488 
00497 typedef void *  (*ggzEntryCreate)       (void *data);
00498 
00499 
00506 typedef void    (*ggzEntryDestroy)      (void *data);
00507 
00508 
00515 typedef struct _GGZListEntry {
00516         void                 *data;     
00517         struct _GGZListEntry *next, 
00518                              *prev;     
00519 } GGZListEntry;
00520 
00521 
00526 typedef struct _GGZList {
00527         GGZListEntry    *head,         
00528                         *tail;         
00529         ggzEntryCompare compare_func;  
00530         ggzEntryCreate  create_func;   
00531         ggzEntryDestroy destroy_func;  
00532         int             options;       
00533         int             entries;       
00534 } GGZList;
00535 
00536 
00537 
00538 #define GGZ_LIST_REPLACE_DUPS 0x00 
00539 #define GGZ_LIST_ALLOW_DUPS   0x01 
00578 GGZList *ggz_list_create (ggzEntryCompare compare_func,
00579                           ggzEntryCreate create_func,
00580                           ggzEntryDestroy destroy_func,
00581                           int options);
00582 
00583 
00593 int ggz_list_insert            (GGZList *list, void *data);
00594 
00595 
00601 GGZListEntry *ggz_list_head     (GGZList *list);
00602 
00603 
00609 GGZListEntry *ggz_list_tail     (GGZList *list);
00610 
00611 
00617 GGZListEntry *ggz_list_next     (GGZListEntry *entry);
00618 
00619 
00625 GGZListEntry *ggz_list_prev     (GGZListEntry *entry);
00626 
00627 
00633 void *ggz_list_get_data         (GGZListEntry *entry);
00634 
00635 
00649 GGZListEntry *ggz_list_search   (GGZList *list, void *data);
00650 
00651 
00664 GGZListEntry *ggz_list_search_alt(GGZList *list, void *data,
00665                                   ggzEntryCompare compare_func);
00666 
00677 void ggz_list_delete_entry      (GGZList *list, GGZListEntry *entry);
00678 
00679 
00689 void ggz_list_free              (GGZList *list);
00690 
00691 
00697 int ggz_list_count              (GGZList *list);
00698 
00699 
00700 /* String list functions */
00701 
00712 int ggz_list_compare_str        (void *a, void *b);
00713 
00714 
00724 void * ggz_list_create_str      (void *data);
00725 
00726 
00735 void ggz_list_destroy_str       (void *data);
00736 
00750 typedef struct _GGZList GGZStack;
00751 
00752 
00757 GGZStack* ggz_stack_new(void);
00758 
00759 
00765 void ggz_stack_push(GGZStack *stack, void *data);
00766 
00767 
00773 void* ggz_stack_pop(GGZStack *stack);
00774 
00775 
00781 void* ggz_stack_top(GGZStack *stack);
00782 
00783 
00790 void ggz_stack_free(GGZStack *stack);
00791 
00814 struct _GGZXMLElement {
00815         
00816         char *tag;           
00817         char *text;          
00818         GGZList *attributes; 
00819         void *data;          
00820         void (*free)(struct _GGZXMLElement*); 
00821         void (*process)(void*, struct _GGZXMLElement*); 
00822 };
00823 
00824 
00827 typedef struct _GGZXMLElement GGZXMLElement;
00828 
00829 
00841 GGZXMLElement* ggz_xmlelement_new(const char *tag, const char * const *attrs,
00842         void (*process)(void*, GGZXMLElement*), void (*free)(GGZXMLElement*));
00843 
00844 
00857 void ggz_xmlelement_init(GGZXMLElement *element, const char *tag,
00858         const char * const *attrs,
00859         void (*process)(void*, GGZXMLElement*), void (*free)(GGZXMLElement*));
00860 
00861 
00870 void ggz_xmlelement_set_data(GGZXMLElement *element, void *data);
00871 
00872 
00878 const char *ggz_xmlelement_get_tag(GGZXMLElement *element);
00879 
00880 
00888 const char *ggz_xmlelement_get_attr(GGZXMLElement *element, const char *attr);
00889 
00890 
00896 void* ggz_xmlelement_get_data(GGZXMLElement *element);
00897 
00898 
00904 char* ggz_xmlelement_get_text(GGZXMLElement *element);
00905 
00906 
00913 void ggz_xmlelement_add_text(GGZXMLElement *element, const char *text, int len);
00914 
00915 
00920 void ggz_xmlelement_free(GGZXMLElement *element);
00921 
00936 typedef enum {
00937         GGZ_CHECK_NONE = 0x00, 
00938         GGZ_CHECK_MEM = 0x01   
00939 } GGZCheckType;
00940 
00953 typedef void (*GGZDebugHandlerFunc)(int priority, const char *msg);
00954 
00963 void ggz_debug_init(const char **types, const char* file);
00964 
00976 GGZDebugHandlerFunc ggz_debug_set_func(GGZDebugHandlerFunc func);
00977 
00985 void ggz_debug_enable(const char *type);
00986 
00995 void ggz_debug_disable(const char *type);
00996 
01007 void ggz_debug(const char *type, const char *fmt, ...)
01008                ggz__attribute((format(printf, 2, 3)));
01009 
01020 void ggz_log(const char *type, const char *fmt, ...)
01021              ggz__attribute((format(printf, 2, 3)));
01022 
01033 void ggz_error_sys(const char *fmt, ...)
01034                    ggz__attribute((format(printf, 1, 2)));
01035 
01043 void ggz_error_sys_exit(const char *fmt, ...)
01044                         ggz__attribute((format(printf, 1, 2)))
01045                         ggz__attribute((noreturn));
01046 
01056 void ggz_error_msg(const char *fmt, ...)
01057                    ggz__attribute((format(printf, 1, 2)));
01058 
01066 void ggz_error_msg_exit(const char *fmt, ...)
01067                         ggz__attribute((format(printf, 1, 2)))
01068                         ggz__attribute((noreturn));
01069 
01078 void ggz_debug_cleanup(GGZCheckType check);
01079 
01099 char * ggz_xml_escape(const char *str);
01100 
01114 char * ggz_xml_unescape(const char *str);
01115 
01118 typedef struct _GGZFile GGZFile;
01119 
01128 GGZFile * ggz_get_file_struct(int fdes);
01129 
01136 int ggz_make_path(const char *full);
01137 
01146 char * ggz_read_line(GGZFile *file);
01147 
01154 void ggz_free_file_struct(GGZFile *file);
01155 
01156 
01167 int ggz_strcmp(const char *s1, const char *s2);
01168 
01169 
01179 int ggz_strcasecmp(const char *s1, const char *s2);
01180  
01197 #define GGZ_SOCKET_DEBUG "socket"
01198 
01204 typedef enum {
01205         GGZ_IO_CREATE,  
01206         GGZ_IO_READ,    
01207         GGZ_IO_WRITE,   
01208         GGZ_IO_ALLOCATE 
01209 } GGZIOType;
01210 
01216 typedef enum {
01217         GGZ_DATA_NONE,   
01218         GGZ_DATA_CHAR,   
01219         GGZ_DATA_INT,    
01220         GGZ_DATA_STRING, 
01221         GGZ_DATA_FD      
01222 } GGZDataType;
01223 
01234 typedef void (*ggzIOError) (const char * msg,
01235                             const GGZIOType type,
01236                             const int fd,
01237                             const GGZDataType data);
01238 
01249 int ggz_set_io_error_func(ggzIOError func);
01250 
01261 ggzIOError ggz_remove_io_error_func(void);
01262 
01263 
01269 typedef void (*ggzIOExit) (int status);
01270 
01279 int ggz_set_io_exit_func(ggzIOExit func);
01280 
01287 ggzIOExit ggz_remove_io_exit_func(void);
01288 
01294 unsigned int ggz_get_io_alloc_limit(void);
01295 
01309 unsigned int ggz_set_io_alloc_limit(const unsigned int limit);
01310 
01311 
01322 int ggz_init_network(void);
01323 
01324 
01332 typedef void (*ggzNetworkNotify) (const char *address, int socket);
01333 
01342 int ggz_set_network_notify_func(ggzNetworkNotify func);
01343 
01360 const char *ggz_resolvename(const char *name);
01361 
01362 
01374 const char *ggz_getpeername(int fd, int resolve);
01375 
01376 
01377 /****************************************************************************
01378  * Creating a socket.
01379  * 
01380  * type  :  one of GGZ_SERVER or GGZ_CLIENT
01381  * port  :  tcp port number 
01382  * server:  hostname to connect to (only relevant for client)
01383  * 
01384  * Returns socket fd or -1 on error
01385  ***************************************************************************/
01386 
01392 typedef enum {
01393         GGZ_SOCK_SERVER, 
01394         GGZ_SOCK_CLIENT  
01395 } GGZSockType;
01396 
01414 int ggz_make_socket(const GGZSockType type, 
01415                     const unsigned short port, 
01416                     const char *server);
01417 
01422 int ggz_make_socket_or_die(const GGZSockType type,
01423                            const unsigned short port, 
01424                            const char *server);
01425 
01439 int ggz_make_unix_socket(const GGZSockType type, const char* name);
01440 
01445 int ggz_make_unix_socket_or_die(const GGZSockType type, const char* name);
01446 
01447 
01457 int ggz_write_char(const int sock, const char data);
01458 
01465 void ggz_write_char_or_die(const int sock, const char data);
01466 
01477 int ggz_read_char(const int sock, char *data);
01478 
01485 void ggz_read_char_or_die(const int sock, char *data);
01486 
01499 int ggz_write_int(const int sock, const int data);
01500 
01506 void ggz_write_int_or_die(const int sock, const int data);
01507 
01516 int ggz_read_int(const int sock, int *data);
01517 
01523 void ggz_read_int_or_die(const int sock, int *data);
01524 
01534 int ggz_write_string(const int sock, const char *data);
01535 
01541 void ggz_write_string_or_die(const int sock, const char *data);
01542 
01554 int ggz_va_write_string(const int sock, const char *fmt, ...)
01555                         ggz__attribute((format(printf, 2, 3)));
01556 
01562 void ggz_va_write_string_or_die(const int sock, const char *fmt, ...)
01563                                 ggz__attribute((format(printf, 2, 3)));
01564 
01577 int ggz_read_string(const int sock, char *data, const unsigned int len);
01578 
01584 void ggz_read_string_or_die(const int sock, char *data, const unsigned int len);
01585 
01606 int ggz_read_string_alloc(const int sock, char **data);
01607 
01613 void ggz_read_string_alloc_or_die(const int sock, char **data);
01614 
01615 /* ggz_write_fd/ggz_read_fd are not supported on all systems. */
01616 
01629 int ggz_write_fd(const int sock, int sendfd);
01630 
01639 int ggz_read_fd(const int sock, int *recvfd);
01640 
01653 int ggz_writen(const int sock, const void *vdata, size_t n);
01654 
01665 int ggz_readn(const int sock, void *data, size_t n);
01666 
01685 typedef struct
01686 {
01687         char *hash;             
01688         int hashlen;    
01689 } hash_t;
01690 
01700 hash_t ggz_hash_create(const char *algo, const char *text);
01701 
01712 hash_t ggz_hmac_create(const char *algo, const char *text, const char *secret);
01713 
01724 char *ggz_base16_encode(const char *text, int length);
01725 
01736 char *ggz_base64_encode(const char *text, int length);
01737 
01747 char *ggz_base64_decode(const char *text, int length);
01748 
01756 typedef enum {
01757         GGZ_TLS_CLIENT,         
01758         GGZ_TLS_SERVER          
01759 } GGZTLSType;
01760 
01769 typedef enum {
01770         GGZ_TLS_VERIFY_NONE,            
01771         GGZ_TLS_VERIFY_PEER                     
01772 } GGZTLSVerificationType;
01773 
01785 void ggz_tls_init(const char *certfile, const char *keyfile, const char *password);
01786 
01797 int ggz_tls_support_query(void);
01798 
01807 const char *ggz_tls_support_name(void);
01808 
01819 int ggz_tls_enable_fd(int fdes, GGZTLSType whoami, GGZTLSVerificationType verify);
01820 
01829 int ggz_tls_disable_fd(int fdes);
01830 
01840 size_t ggz_tls_write(int fd, void *ptr, size_t n);
01841 
01851 size_t ggz_tls_read(int fd, void *ptr, size_t n);
01852 
01855 #ifdef __cplusplus
01856 }
01857 #endif
01858 
01859 #endif  /* __GGZ_H__ */

Generated on Fri Nov 30 14:58:02 2007 for LibGGZ by  doxygen 1.5.1