parse.c
changeset 5 2155c65c7455
parent 2 a48121a74017
child 6 a035ec60dc7f
equal deleted inserted replaced
4:0ac09410a684 5:2155c65c7455
     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    = g_strdup(lm_message_node_get_attribute(node, "action"));
    15   ij->initiator = attrcpy(lm_message_node_get_attribute(node, "initiator"));
    15   ij->initiator = g_strdup(lm_message_node_get_attribute(node, "initiator"));
    16   ij->responder = attrcpy(lm_message_node_get_attribute(node, "responder"));
    16   ij->responder = g_strdup(lm_message_node_get_attribute(node, "responder"));
    17   ij->sid       = attrcpy(lm_message_node_get_attribute(node, "sid"));
    17   ij->sid       = g_strdup(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     
    41 }
    41 }
    42 
    42 
    43 
    43 
    44 void free_jingle(struct info_jingle *ij)
    44 void free_jingle(struct info_jingle *ij)
    45 {
    45 {
    46   free(ij->action);
    46   g_free(ij->action);
    47   free(ij->initiator);
    47   g_free(ij->initiator);
    48   free(ij->responder);
    48   g_free(ij->responder);
    49   free(ij->sid);
    49   g_free(ij->sid);
    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     = g_strdup(lm_message_node_get_attribute(node, "creator"));
    59   ic->disposition = attrcpy(lm_message_node_get_attribute(node, "disposition"));
    59   ic->disposition = g_strdup(lm_message_node_get_attribute(node, "disposition"));
    60   ic->name        = attrcpy(lm_message_node_get_attribute(node, "name"));
    60   ic->name        = g_strdup(lm_message_node_get_attribute(node, "name"));
    61   ic->senders     = attrcpy(lm_message_node_get_attribute(node, "senders"));
    61   ic->senders     = g_strdup(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 = g_strdup("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 
    78 }
    78 }
    79 
    79 
    80 
    80 
    81 void free_content(struct info_content *ic)
    81 void free_content(struct info_content *ic)
    82 {
    82 {
    83   free(ic->creator);
    83   g_free(ic->creator);
    84   free(ic->disposition);
    84   g_free(ic->disposition);
    85   free(ic->name);
    85   g_free(ic->name);
    86   free(ic->senders);
    86   g_free(ic->senders);
    87 }
    87 }
    88 
    88 
    89 
    89 
    90 int check_restriction(const char* name, const char** values)
    90 int check_restriction(const gchar* name, const gchar** values)
    91 {
    91 {
    92   const char* value;
    92   const char* value;
    93   int found = 0;
    93   int found = 0;
    94   value = values[0];
    94   value = values[0];
    95   while (value && !found) {
    95   while (value && !found) {
    97       found = 1;
    97       found = 1;
    98     value++;
    98     value++;
    99   }
    99   }
   100   return found;
   100   return found;
   101 }
   101 }
   102 
       
   103 
       
   104 char* attrcpy(const char* attr)
       
   105 {
       
   106   char *tmp = NULL;
       
   107   if (attr != NULL) {
       
   108     tmp = (char*) malloc((strlen(attr)+1) * sizeof(char));
       
   109     strcpy(tmp, attr);
       
   110   }
       
   111   return tmp;
       
   112 }