1 #include <loudmouth/loudmouth.h> |
1 #include <loudmouth/loudmouth.h> |
2 #include <string.h> |
2 #include <string.h> |
3 |
3 |
4 #include "parse.h" |
4 #include "parse.h" |
5 |
5 |
6 int parse_jingle (LmMessageNode *node, struct info_jingle *ij) |
6 int parse_jingle(LmMessageNode *node, struct info_jingle *ij) |
7 { |
7 { |
8 int nb_reason = 0; |
8 int nb_reason = 0; |
9 LmMessageNode *child = NULL; |
9 LmMessageNode *child = NULL; |
10 |
10 |
11 if(!strcmp(ij->name, "jingle")) |
11 if (!strcmp(ij->name, "jingle")) |
12 return PARSE_ERROR_NAME; |
12 return PARSE_ERROR_NAME; |
13 |
13 |
14 ij->action = attrcpy(lm_message_node_get_attribute(node, "action")); |
14 ij->action = attrcpy(lm_message_node_get_attribute(node, "action")); |
15 ij->initiator = attrcpy(lm_message_node_get_attribute(node, "initiator")); |
15 ij->initiator = attrcpy(lm_message_node_get_attribute(node, "initiator")); |
16 ij->responder = attrcpy(lm_message_node_get_attribute(node, "responder")); |
16 ij->responder = attrcpy(lm_message_node_get_attribute(node, "responder")); |
17 ij->sid = attrcpy(lm_message_node_get_attribute(node, "sid")); |
17 ij->sid = attrcpy(lm_message_node_get_attribute(node, "sid")); |
18 |
18 |
19 // check required |
19 // check required |
20 if(ij->action == NULL || ij->sid == NULL) |
20 if (ij->action == NULL || ij->sid == NULL) |
21 return PARSE_ERROR_REQUIRED; |
21 return PARSE_ERROR_REQUIRED; |
22 |
22 |
23 // check restrictions |
23 // check restrictions |
24 if(!check_restriction(ij->action, {"content-accept", "content-add", |
24 if (!check_restriction(ij->action, {"content-accept", "content-add", |
25 "content-modify", "content-reject", "content-remove", "description-info", |
25 "content-modify", "content-reject", "content-remove", "description-info", |
26 "security-info", "session-accept", "session-info", "session-initiate", |
26 "security-info", "session-accept", "session-info", "session-initiate", |
27 "session-terminate", "transport-accept", "transport-info", "transport-reject", |
27 "session-terminate", "transport-accept", "transport-info", "transport-reject", |
28 "transport-replace", NULL})) |
28 "transport-replace", NULL})) |
29 return PARSE_ERROR_RESTRICTION; |
29 return PARSE_ERROR_RESTRICTION; |
30 |
30 |
31 // check childs |
31 // check childs |
32 for(child = node->children; child; child = child->next) { |
32 for (child = node->children; child; child = child->next) { |
33 if(!strcmp(child->name, "reason")) |
33 if (!strcmp(child->name, "reason")) |
34 nb_reason++; |
34 nb_reason++; |
35 } |
35 } |
36 |
36 |
37 if(reason > 1) |
37 if (reason > 1) |
38 return PARSE_ERROR_TOO_MANY_CHILDS; |
38 return PARSE_ERROR_TOO_MANY_CHILDS; |
39 |
39 |
40 return PARSE_OK; |
40 return PARSE_OK; |
41 } |
41 } |
42 |
42 |
50 } |
50 } |
51 |
51 |
52 |
52 |
53 int parse_content(LmMessageNode* node, struct info_content* ic) |
53 int parse_content(LmMessageNode* node, struct info_content* ic) |
54 { |
54 { |
55 if(!strcmp(ic->name, "content")) |
55 if (!strcmp(ic->name, "content")) |
56 return PARSE_ERROR_NAME; |
56 return PARSE_ERROR_NAME; |
57 |
57 |
58 ic->creator = attrcpy(lm_message_node_get_attribute(node, "creator")); |
58 ic->creator = attrcpy(lm_message_node_get_attribute(node, "creator")); |
59 ic->disposition = attrcpy(lm_message_node_get_attribute(node, "disposition")); |
59 ic->disposition = attrcpy(lm_message_node_get_attribute(node, "disposition")); |
60 ic->name = attrcpy(lm_message_node_get_attribute(node, "name")); |
60 ic->name = attrcpy(lm_message_node_get_attribute(node, "name")); |
61 ic->senders = attrcpy(lm_message_node_get_attribute(node, "senders")); |
61 ic->senders = attrcpy(lm_message_node_get_attribute(node, "senders")); |
62 |
62 |
63 // Put default if none |
63 // Put default if none |
64 if(ic->disposition == NULL) |
64 if (ic->disposition == NULL) |
65 ic->disposition = attrcpy("session"); |
65 ic->disposition = attrcpy("session"); |
66 |
66 |
67 // check required |
67 // check required |
68 if(ic->creator == NULL || ic->name == NULL) |
68 if (ic->creator == NULL || ic->name == NULL) |
69 return PARSE_ERROR_REQUIRED; |
69 return PARSE_ERROR_REQUIRED; |
70 |
70 |
71 // check restrictions |
71 // check restrictions |
72 if(!check_restriction(ic->creator, {"initiator", "responder", NULL})) |
72 if (!check_restriction(ic->creator, {"initiator", "responder", NULL})) |
73 return PARSE_ERROR_RESTRICTION; |
73 return PARSE_ERROR_RESTRICTION; |
74 if(!check_restriction(ic->senders, {"both", "initiator", "none", "responder", NULL})) |
74 if (!check_restriction(ic->senders, {"both", "initiator", "none", "responder", NULL})) |
75 ic->senders = NULL; // because it's optional |
75 ic->senders = NULL; // because it's optional |
76 |
76 |
77 return PARSE_OK; |
77 return PARSE_OK; |
78 } |
78 } |
79 |
79 |