midgard/parser.h

00001 /* $Id: parser.h,v 1.3 2006/05/30 14:12:48 piotras Exp $
00002  *
00003  * midgard-lib: database access for Midgard clients
00004  *
00005  * Copyright (C) 1999 Jukka Zitting <jukka.zitting@iki.fi>
00006  * Copyright (C) 2000 The Midgard Project ry
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING.  If not, write to
00020  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021  * Boston, MA 02111-1307, USA.
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 /* General callback function that processes addition to format buffer
00034    Each parser shoud have several predefined callbacks:
00035    'd': add integer number
00036    'D': add integer array
00037    'i': add integer number
00038    't': add date
00039    's': add string
00040    'q': add sql query
00041    'h': add html code
00042    'p': add plain text without without HTML conversion
00043    'P': add plain text with HTML conversion
00044    'f': add formatted text
00045    'F': add formatted text with headers
00046    'u': add url-encoded string
00047    By default, they will be initialized to Latin1 parser
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 /* These are use explicit parser */
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 /* Parser API */
00088 
00089 /* Hexadecimal table for conversions */
00090 extern char mgd_parser_HexTable[16];
00091 
00092 /* Add char to format buffer */
00093 extern int mgd_parser_addchar(mgd_parser *parser, char ch);
00094 /* Acc char to format buffer */
00095 extern int mgd_parser_accchar(mgd_parser *parser, char ch);
00096 /* Add number to format buffer */
00097 extern int mgd_parser_addint(mgd_parser *parser, int num);
00098 /* Add date to format buffer */
00099 extern int mgd_parser_adddate(mgd_parser *parser, const char *str);
00100 /* Add string to format buffer */
00101 extern int mgd_parser_addstr(mgd_parser *parser, const char *str);
00102 /* Add sql query to format buffer */
00103 extern int mgd_parser_addsql(mgd_parser *parser, const char *str);
00104 /* Add formatted text to format buffer */
00105 extern int mgd_parser_addtext(mgd_parser *parser, const char *str, int headers);
00106 /* Add url-encoded string to format buffer */
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 /* MIDGARD_RUSSIAN_H */

Generated on Thu Feb 22 06:15:14 2007 for midgard-core by  doxygen 1.4.6