libsyncml  0.5.4
sml_parse.h
1 /*
2  * libsyncml - A syncml protocol implementation
3  * Copyright (C) 2005 Armin Bauer <armin.bauer@opensync.org>
4  * Copyright (C) 2008 Michael Bell <michael.bell@opensync.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _SML_PARSE_H_
23 #define _SML_PARSE_H_
24 
25 typedef enum {
26  SML_PARSER_RESULT_ERROR = 0,
27  SML_PARSER_RESULT_OPEN = 1,
28  SML_PARSER_RESULT_CLOSE = 2,
29  SML_PARSER_RESULT_NORMAL = 3,
30  SML_PARSER_RESULT_STATUS = 4,
31  SML_PARSER_RESULT_OTHER = 5
32 } SmlParserResult;
33 
34 typedef void (* SmlParserFreeFunction) (void *userdata);
35 typedef SmlBool (* SmlParserStartFunction) (void *userdata, const char *data, unsigned int size, SmlError **error);
36 typedef SmlBool (* SmlParserEndFunction) (void *userdata, SmlBool *final, SmlBool *end, SmlError **error);
37 typedef SmlBool (* SmlParserHeaderFunction) (void *userdata, SmlHeader **header, SmlCred **cred, SmlError **error);
38 typedef SmlBool (* SmlParserStatusFunction) (void *userdata, SmlStatus **status, SmlError **error);
39 typedef SmlParserResult (* SmlParserCommandFunction) (void *userdata, SmlCommand **cmd, SmlError **error);
40 
41 typedef struct SmlParserFunctions {
42  SmlParserFreeFunction free;
43  SmlParserStartFunction start;
44  SmlParserEndFunction end;
45  SmlParserHeaderFunction get_header;
46  SmlParserStatusFunction get_status;
47  SmlParserCommandFunction get_cmd;
49 
50 typedef void (* SmlAssemblerFreeFunction) (void *userdata);
51 typedef SmlBool (* SmlAssemblerStartFunction) (void *userdata, SmlSession *session, SmlError **error);
52 typedef SmlBool (* SmlAssemblerEndFunction) (void *userdata, SmlError **error);
53 typedef SmlBool (* SmlAssemblerRunFunction) (void *userdata, char **data, unsigned int *size, SmlBool *end, SmlBool final, unsigned int maxsize, SmlError **error);
54 typedef unsigned int (* SmlAssemblerFlushFunction) (void *userdata);
55 typedef SmlBool (* SmlAssemblerStatusFunction) (void *userdata, SmlStatus *status, SmlError **error);
56 typedef SmlBool (* SmlAssemblerRemStatusFunction) (void *userdata, SmlError **error);
57 typedef SmlBool (* SmlAssemblerReserveStatusFunction) (void *userdata, unsigned int cmdRef, unsigned int msgRef, unsigned int cmdID, SmlError **error);
58 typedef SmlBool (* SmlAssemblerStatusMissingFunction) (void *userdata);
59 typedef SmlBool (* SmlAssemblerStartCommandFunction) (void *userdata, unsigned int parentID, SmlCommand *cmd, SmlError **error);
60 typedef SmlBool (* SmlAssemblerEndCommandFunction) (void *userdata, unsigned int parentID, SmlError **error);
61 typedef SmlBool (* SmlAssemblerRemCommandFunction) (void *userdata, unsigned int parentID, SmlError **error);
62 typedef SmlBool (* SmlAssemblerHeaderFunction) (void *userdata, SmlSession *session, SmlError **error);
63 typedef unsigned int (* SmlAssemblerCheckFunction) (void *userdata, SmlBool headeronly, SmlError **error);
64 typedef SmlBool (* SmlAssemblerNextCmdRefFunction) (void *userdata, unsigned int *cmdRef, unsigned int *msgRef);
65 typedef void (* SmlAssemblerRestoreCommandsFunction) (void *userdata);
66 
67 typedef struct SmlAssemblerFunctions {
68  SmlAssemblerFreeFunction free;
69  SmlAssemblerStartFunction start;
70  SmlAssemblerEndFunction end;
71  SmlAssemblerRunFunction run;
72  SmlAssemblerFlushFunction flush;
73  SmlAssemblerStatusFunction add_status;
74  SmlAssemblerRemStatusFunction rem_status;
75  SmlAssemblerReserveStatusFunction reserve_status;
76  SmlAssemblerStatusMissingFunction missing_status;
77  SmlAssemblerStartCommandFunction start_cmd;
78  SmlAssemblerEndCommandFunction end_cmd;
79  SmlAssemblerRemCommandFunction rem_cmd;
80  SmlAssemblerHeaderFunction add_header;
81  SmlAssemblerCheckFunction check_size;
82  SmlAssemblerNextCmdRefFunction next_cmdref;
83  SmlAssemblerRestoreCommandsFunction restore_cmds;
85 
86 typedef enum {
87  SML_ASSEMBLER_RESULT_ERROR = 0,
88  SML_ASSEMBLER_RESULT_OK = 1,
89  SML_ASSEMBLER_RESULT_MISMATCH =2
90 } SmlAssemblerResult;
91 
92 SmlParser *smlParserNew(SmlMimeType type, unsigned int limit, SmlError **error);
93 void smlParserFree(SmlParser *parser);
94 SmlBool smlParserStart(SmlParser *parser, const char *data, unsigned int size, SmlError **error);
95 SmlBool smlParserGetHeader(SmlParser *parser, SmlHeader **header, SmlCred **cred, SmlError **error);
96 SmlParserResult smlParserGetCommand(SmlParser *parser, SmlCommand **cmd, SmlError **error);
97 SmlBool smlParserGetStatus(SmlParser *parser, SmlStatus **status, SmlError **error);
98 SmlBool smlParserEnd(SmlParser *parser, SmlBool *final, SmlBool *end, SmlError **error);
99 
100 SmlAssembler *smlAssemblerNew(SmlMimeType type, unsigned int limit, SmlError **error);
101 void smlAssemblerFree(SmlAssembler *assm);
102 SmlBool smlAssemblerStart(SmlAssembler *assm, SmlSession *session, SmlError **error);
103 unsigned int smlAssemblerFlush(SmlAssembler *assm);
104 void smlAssemblerRestoreCommands(SmlAssembler *assm);
105 SmlBool smlAssemblerRun(SmlAssembler *assm, char **data, unsigned int *size, SmlBool *end, SmlBool final, SmlError **error);
106 SmlAssemblerResult smlAssemblerAddStatus(SmlAssembler *assm, SmlStatus *status, SmlError **error);
107 SmlAssemblerResult smlAssemblerAddStatusFull(SmlAssembler *assm, SmlStatus *status, SmlBool force, SmlError **error);
108 SmlAssemblerResult smlAssemblerReserveStatus(SmlAssembler *assm, unsigned int cmdRef, unsigned int msgRef, unsigned int cmdID, SmlError **error);
109 SmlBool smlAssemblerAddHeader(SmlAssembler *assm, SmlSession *session, SmlError **error);
110 SmlAssemblerResult smlAssemblerStartCommand(SmlAssembler *assm, SmlCommand *parent, SmlCommand *cmd, SmlError **error);
111 SmlBool smlAssemblerEndCommand(SmlAssembler *assm, SmlCommand *parent, SmlError **error);
112 unsigned int smlAssemblerCheckSize(SmlAssembler *assm, SmlBool headeronly, SmlError **error);
113 void smlAssemblerSetOption(SmlAssembler *assm, const char *optionname, const char *value);
114 const char *smlAssemblerGetOption(SmlAssembler *assm, const char *optionname);
115 
116 unsigned int smlAssemblerSetRemoteMaxMsgSize(SmlAssembler *assm, unsigned int limit);
117 unsigned int smlAssemblerGetRemoteMaxMsgSize(SmlAssembler *assm);
118 SmlBool smlAssemblerGetSpace(SmlAssembler *assm, int *space, SmlCommand *parent, SmlCommand *cmd, SmlError **error);
119 
120 unsigned int smlAssemblerGetRemoteMaxObjSize(SmlAssembler *assm);
121 unsigned int smlAssemblerSetRemoteMaxObjSize(SmlAssembler *assm, unsigned int limit);
122 
123 SmlBool smlAssemblerIsEmpty(SmlAssembler *assm);
125 SmlBool smlAssemblerGetNextCmdRef(SmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef);
126 
127 /* expire date: 20090626 */
128 void smlAssemblerSetRequestedLimit(SmlAssembler *assm, unsigned int limit) LIBSYNCML_DEPRECATED;
129 void smlAssemblerSetLimit(SmlAssembler *assm, unsigned int limit) LIBSYNCML_DEPRECATED;
130 unsigned int smlAssemblerGetLimit(SmlAssembler *assm) LIBSYNCML_DEPRECATED;
131 void smlAssemblerSetRequestedMaxObjSize(SmlAssembler *assm, int limit) LIBSYNCML_DEPRECATED;
132 void smlAssemblerSetSendingMaxObjSize(SmlAssembler *assm, int limit) LIBSYNCML_DEPRECATED;
133 int smlAssemblerGetSendingMaxObjSize(SmlAssembler *assm) LIBSYNCML_DEPRECATED;
134 int smlAssemblerGetRequestedMaxObjSize(SmlAssembler *assm) LIBSYNCML_DEPRECATED;
135 
136 /* If you want to parse OMA DS 1.2 SANs then the manager is required. */
137 void smlParserSetManager(SmlParser *parser, SmlManager *manager);
138 
139 #endif //_SML_PARSE_H_