00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MIDGARD_PARSER_H
00024 #define MIDGARD_PARSER_H
00025 #include <ctype.h>
00026 #include <stdarg.h>
00027 #include <assert.h>
00028 #include <stdlib.h>
00029 #include "midgard/midgard_defs.h"
00030 #include "midgard/pool.h"
00031
00032 typedef struct _mgd_parser mgd_parser;
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 typedef int (*mgd_parser_callback)(mgd_parser *parser, void *data);
00050
00051 typedef enum {
00052 MGD_CHAR,
00053 MGD_INT,
00054 MGD_INTPTR,
00055 MGD_STR,
00056 MGD_PTR
00057 } mgd_parser_type;
00058
00059 typedef struct {
00060 mgd_parser_callback func;
00061 mgd_parser_type ptype;
00062 } mgd_parser_callback_info;
00063
00064 struct _mgd_parser {
00065 mgd_parser *next;
00066 char *name, *encoding;
00067 int need_qp;
00068 midgard_pool *pool;
00069 mgd_parser_callback_info *callbacks;
00070 };
00071
00072 extern mgd_parser* mgd_parser_create(const char *name, const char *encoding, int need_qp);
00073 extern void mgd_parser_free(mgd_parser *parser);
00074 extern void mgd_parser_free_all();
00075 extern void mgd_parser_setcallback(mgd_parser *parser, char symbol,
00076 mgd_parser_type ptype,
00077 mgd_parser_callback callback);
00078 extern void mgd_parser_clearcallback(mgd_parser *parser, char symbol);
00079 extern mgd_parser* mgd_parser_get(const char *name);
00080 extern mgd_parser* mgd_parser_list();
00081 extern int mgd_parser_activate(midgard *mgd, const char *name);
00082
00083
00084 extern char *mgd_format_ext(mgd_parser *parser, midgard_pool *pool, const char *fmt, ...);
00085 extern char *mgd_vformat_ext(mgd_parser *parser, midgard_pool *pool, const char *fmt, va_list args);
00086
00087
00088
00089
00090 extern char mgd_parser_HexTable[16];
00091
00092
00093 extern int mgd_parser_addchar(mgd_parser *parser, char ch);
00094
00095 extern int mgd_parser_accchar(mgd_parser *parser, char ch);
00096
00097 extern int mgd_parser_addint(mgd_parser *parser, int num);
00098
00099 extern int mgd_parser_adddate(mgd_parser *parser, const char *str);
00100
00101 extern int mgd_parser_addstr(mgd_parser *parser, const char *str);
00102
00103 extern int mgd_parser_addsql(mgd_parser *parser, const char *str);
00104
00105 extern int mgd_parser_addtext(mgd_parser *parser, const char *str, int headers);
00106
00107 extern int mgd_parser_addurl(mgd_parser *parser, const char *str);
00108
00109 #define MGD_ADDPLAIN(p, s, h) p->callbacks[h ? 'P':'p'].func(p,(void*)(s))
00110
00111 #endif