Browse code

wrapper function for FROM header. ssi

ssi authored on 08/08/2002 17:15:18
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,55 @@
1
+/*
2
+ * @author Stelios Sidiroglou-Douskos <ssi@fokus.gmd.de>
3
+ * $Id$
4
+ */
5
+
6
+#include "parse_from.h"
7
+#include "parse_to.h"
8
+#include <stdlib.h>
9
+#include <string.h>
10
+#include "../dprint.h"
11
+#include "msg_parser.h"
12
+#include "../ut.h"
13
+#include "../mem/mem.h"
14
+
15
+/*
16
+ * This method is used to parse the from header. It was decided not to parse
17
+ * anything in core that is not *needed* so this method gets called by 
18
+ * rad_acc module and any other modules that needs the FROM header.
19
+ *
20
+ * params: hdr : Hook to the from header
21
+ * returns 0 on success,
22
+ *		   -1 on failure.
23
+ */
24
+int parse_from_header(struct hdr_field* hdr) 
25
+{
26
+	struct to_body* from_b;
27
+	
28
+	from_b = pkg_malloc(sizeof(struct to_body));
29
+	if (from_b == 0) {
30
+		LOG(L_ERR, "parse_from_header: out of memory\n");
31
+		goto error;
32
+	}
33
+			
34
+	memset(from_b, 0, sizeof(struct to_body));
35
+	parse_to(hdr->body.s, hdr->body.s + hdr->body.len + 1, from_b);
36
+	if (from_b->error == PARSE_ERROR) {
37
+		LOG(L_ERR, "ERROR: parse_from_header: bad from header\n");
38
+		pkg_free(from_b);
39
+		goto error;
40
+	}
41
+	hdr->parsed = from_b;	
42
+	DBG("DEBUG: parse_from_header: <%s> [%d]; uri=[%.*s] \n",
43
+		hdr->name.s, hdr->body.len, from_b->uri.len, from_b->uri.s);
44
+	DBG("DEBUG: from body [%.*s]\n",from_b->body.len, from_b->body.s);	
45
+
46
+	return 0;
47
+
48
+	error:
49
+	/* more debugging, msg->orig is/should be null terminated*/
50
+	LOG(L_ERR, "ERROR: parse_from_header: \n");
51
+	return -1;
52
+
53
+}
54
+
55
+