Browse code

- Really commited the allow parser now

Jan Janak authored on 13/08/2004 21:46:27
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,83 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (c) 2004 Juha Heinanen
4
+ *
5
+ * This file is part of ser, a free SIP server.
6
+ *
7
+ * ser is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version
11
+ *
12
+ * For a license to use the ser software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * ser is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License 
23
+ * along with this program; if not, write to the Free Software 
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ */
26
+
27
+#include <stdlib.h>
28
+#include <string.h>
29
+#include "../dprint.h"
30
+#include "../mem/mem.h"
31
+#include "parse_allow.h"
32
+#include "parse_methods.h"
33
+#include "msg_parser.h"
34
+
35
+ 
36
+/*
37
+ * This method is used to parse Allow header.
38
+ *
39
+ * params: msg : sip msg
40
+ * returns 0 on success,
41
+ *        -1 on failure.
42
+ */
43
+int parse_allow_header(struct hdr_field* _hf)
44
+{
45
+	unsigned int* methods;
46
+	
47
+	if (!_hf) {
48
+		LOG(L_ERR, "parse_allow_header: Invalid parameter value\n");
49
+		return -1;
50
+	}
51
+	
52
+	     /* maybe the header is already parsed! */
53
+ 	if (_hf->parsed) {
54
+ 		return 0;
55
+	}
56
+
57
+	     /* bad luck! :-( - we have to parse it */
58
+	methods = pkg_malloc(sizeof(unsigned int));
59
+ 	if (methods == 0) {
60
+ 		LOG(L_ERR, "ERROR:parse_allow_header: Out of pkg_memory\n");
61
+ 		return -1;
62
+ 	}
63
+
64
+	if (!parse_methods(&(_hf->body), methods)) {
65
+ 		LOG(L_ERR, "ERROR:parse_allow_header: Bad allow header\n"); 
66
+ 		pkg_free(methods);
67
+		return -1;
68
+ 	}
69
+
70
+ 	_hf->parsed = methods;
71
+ 	return 0;
72
+}
73
+
74
+
75
+/*
76
+ * Release memory
77
+ */
78
+void free_allow(unsigned int** _methods)
79
+{
80
+	if (_methods && *_methods) pkg_free(*_methods);
81
+	*_methods = 0;
82
+}
0 83
new file mode 100644
... ...
@@ -0,0 +1,51 @@
0
+/*
1
+ * $Id$
2
+ *
3
+ * Copyright (c) 2004 Juha Heinanen
4
+ *
5
+ * This file is part of ser, a free SIP server.
6
+ *
7
+ * ser is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; either version 2 of the License, or
10
+ * (at your option) any later version
11
+ *
12
+ * For a license to use the ser software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * ser is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License 
23
+ * along with this program; if not, write to the Free Software 
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ */
26
+ 
27
+#ifndef PARSE_ALLOW_H
28
+#define PARSE_ALLOW_H
29
+ 
30
+#include "hf.h"
31
+
32
+ 
33
+/* 
34
+ * casting macro for accessing RPID body 
35
+ */
36
+#define get_allow_methods(p_msg) (unsigned int)(p_msg)->allow->parsed)
37
+
38
+
39
+/*
40
+ * Parse Allow HF body
41
+ */
42
+int parse_allow(struct hdr_field* _h);
43
+
44
+
45
+/*
46
+ * Release memory
47
+ */
48
+void free_allow(unsigned int** _methods);
49
+
50
+#endif /* PARSE_ALLOW_H */