OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / user / ser / parser / parse_param.h
1 /* 
2  * $Id: parse_param.h,v 1.11 2004/09/01 11:56:59 janakj Exp $
3  *
4  * Generic Parameter Parser
5  *
6  * Copyright (C) 2001-2003 FhG Fokus
7  *
8  * This file is part of ser, a free SIP server.
9  *
10  * ser is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * For a license to use the ser software under conditions
16  * other than those described here, or to purchase support for this
17  * software, please contact iptel.org by e-mail at the following addresses:
18  *    info@iptel.org
19  *
20  * ser is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License 
26  * along with this program; if not, write to the Free Software 
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  *
29  * History:
30  * -------
31  * 2003-03-24 Created by janakj
32  * 2003-04-07 shm duplication support (janakj)
33  * 2003-04-07 URI class added (janakj)
34  */
35
36 #ifndef PARSE_PARAM_H
37 #define PARSE_PARAM_H
38
39 #include <stdio.h>
40
41
42 /*
43  * Supported types of parameters
44  */
45 typedef enum ptype {
46         P_OTHER = 0, /* Unknown parameter */
47         P_Q,         /* Contact: q parameter */
48         P_EXPIRES,   /* Contact: expires parameter */
49         P_METHOD,    /* Contact: method parameter */
50         P_RECEIVED,  /* Contact: received parameter */
51         P_TRANSPORT, /* URI: transport parameter */
52         P_LR,        /* URI: lr parameter */
53         P_R2,        /* URI: r2 parameter (ser specific) */
54         P_MADDR,     /* URI: maddr parameter */
55         P_TTL,       /* URI: ttl parameter */
56 } ptype_t;
57
58
59 /*
60  * Class of parameters
61  */
62 typedef enum pclass {
63         CLASS_ANY = 0,  /* Any parameters, well-known hooks will be not used */
64         CLASS_CONTACT,  /* Contact parameters */
65         CLASS_URI       /* URI parameters */
66 } pclass_t;
67
68
69 /*
70  * Structure representing a parameter
71  */
72 typedef struct param {
73         ptype_t type;         /* Type of the parameter */
74         str name;             /* Parameter name */
75         str body;             /* Parameter body */
76         int len;              /* Total length of the parameter including = and quotes */
77         struct param* next;   /* Next parameter in the list */
78 } param_t;
79
80
81 /*
82  * Hooks to well known parameters for contact class of parameters
83  */
84 struct contact_hooks {
85         struct param* expires;  /* expires parameter */
86         struct param* q;        /* q parameter */
87         struct param* method;   /* method parameter */
88         struct param* received; /* received parameter */
89 };
90
91
92 /*
93  * Hooks to well known parameter for URI class of parameters
94  */
95 struct uri_hooks {
96         struct param* transport; /* transport parameter */
97         struct param* lr;        /* lr parameter */
98         struct param* r2;        /* r2 parameter */
99         struct param* maddr;     /* maddr parameter */
100         struct param* ttl;       /* ttl parameter */
101 };
102
103
104 /*
105  * Union of hooks structures for all classes
106  */
107 typedef union param_hooks {
108         struct contact_hooks contact; /* Contact hooks */
109         struct uri_hooks uri;         /* URI hooks */
110 } param_hooks_t;
111
112
113 /*
114  * Parse parameters
115  * _s is string containing parameters
116  * _c is class of parameters
117  * _h is pointer to structure that will be filled with pointer to well known parameters
118  * linked list of parsed parameters will be stored in
119  * the variable _p is pointing to
120  * The function returns 0 on success and negative number
121  * on an error
122  */
123 int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p);
124
125
126 /*
127  * Free linked list of parameters
128  */
129 void free_params(param_t* _p);
130
131
132 /*
133  * Free linked list of parameters from shared memory
134  */
135 void shm_free_params(param_t* _p);
136
137
138 /*
139  * Print linked list of parameters, just for debugging
140  */
141 void print_params(FILE* _o, param_t* _p);
142
143
144 /*
145  * Duplicate linked list of parameters
146  */
147 int duplicate_params(param_t** _n, param_t* _p);
148
149
150 /*
151  * Duplicate linked list of parameters
152  */
153 int shm_duplicate_params(param_t** _n, param_t* _p);
154
155
156 #endif /* PARSE_PARAM_H */