int pres_apply_auth(str* notify_body, subs_t* subs, str** final_nbody) { xmlDocPtr doc= NULL; xmlNodePtr node= NULL; str* n_body= NULL; *final_nbody= NULL; if(force_active) return 0; if(subs->auth_rules_doc== NULL) { LM_ERR("NULL rules doc\n"); return -1; } doc= xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len); if(doc== NULL) { LM_ERR("parsing xml doc\n"); return -1; } node= get_rule_node(subs, doc); if(node== NULL) { LM_DBG("The subscriber didn't match the conditions\n"); xmlFreeDoc(doc); return 0; } n_body= get_final_notify_body(subs, notify_body, node); if(n_body== NULL) { LM_ERR("in function get_final_notify_body\n"); xmlFreeDoc(doc); return -1; } xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); *final_nbody= n_body; return 1; }
int pres_watcher_allowed(subs_t* subs) { xmlDocPtr xcap_tree= NULL; xmlNodePtr node= NULL, actions_node = NULL; xmlNodePtr sub_handling_node = NULL; char* sub_handling = NULL; subs->status= PENDING_STATUS; subs->reason.s= NULL; subs->reason.len= 0; if (subs->auth_rules_doc== NULL) return 0; xcap_tree= xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len); if (xcap_tree== NULL) { LM_ERR("parsing xml memory\n"); return -1; } node= get_rule_node(subs, xcap_tree); if (node== NULL) { xmlFreeDoc(xcap_tree); return 0; } /* process actions */ actions_node = xmlNodeGetChildByName(node, "actions"); if (actions_node == NULL) { LM_DBG("actions_node NULL\n"); xmlFreeDoc(xcap_tree); return 0; } LM_DBG("actions_node->name= %s\n", actions_node->name); sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling"); if (sub_handling_node== NULL) { LM_DBG("sub_handling_node NULL\n"); xmlFreeDoc(xcap_tree); return 0; } sub_handling = (char*)xmlNodeGetContent(sub_handling_node); LM_DBG("sub_handling_node->name= %s\n", sub_handling_node->name); LM_DBG("sub_handling_node->content= %s\n", sub_handling); if (sub_handling == NULL) { LM_ERR("Couldn't get sub-handling content\n"); xmlFreeDoc(xcap_tree); return -1; } if (strncmp((char*)sub_handling, "block", 5) == 0) { subs->status = TERMINATED_STATUS;; subs->reason.s= "rejected"; subs->reason.len = 8; } else if (strncmp((char*)sub_handling, "confirm", 7) == 0) { subs->status = PENDING_STATUS; } else if (strncmp((char*)sub_handling , "polite-block", 12) == 0) { subs->status = ACTIVE_STATUS; subs->reason.s= "polite-block"; subs->reason.len = 12; } else if (strncmp((char*)sub_handling, "allow", 5) == 0) { subs->status = ACTIVE_STATUS; subs->reason.s = NULL; } else { LM_ERR("unknown subscription handling action\n"); xmlFreeDoc(xcap_tree); xmlFree(sub_handling); return -1; } xmlFreeDoc(xcap_tree); xmlFree(sub_handling); return 0; }
int pres_watcher_allowed(subs_t* subs) { xmlDocPtr xcap_tree= NULL; xmlNodePtr node= NULL, actions_node = NULL; xmlNodePtr sub_handling_node = NULL; char* sub_handling = NULL; int ret = 0; /* if force_active set status to active*/ if(force_active) { subs->status= ACTIVE_STATUS; subs->reason.s= NULL; subs->reason.len= 0; return 0; } if(subs->auth_rules_doc== NULL) { subs->status= PENDING_STATUS; subs->reason.s= NULL; subs->reason.len= 0; return 0; } xcap_tree= xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len); if(xcap_tree== NULL) { LM_ERR("parsing xml memory\n"); return -1; } node= get_rule_node(subs, xcap_tree); if(node== NULL) { /* if no rule node was found and the previous state was active -> set the * state to terminated with reason xcapauth_userdel_reason (default "probation") */ if(subs->status != PENDING_STATUS) { subs->status= TERMINATED_STATUS; subs->reason= xcapauth_userdel_reason; } goto done; } subs->status= PENDING_STATUS; subs->reason.s= NULL; subs->reason.len= 0; /* process actions */ actions_node = xmlNodeGetChildByName(node, "actions"); if(actions_node == NULL) { LM_DBG("actions_node NULL\n"); goto done; } LM_DBG("actions_node->name= %s\n", actions_node->name); sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling"); if(sub_handling_node== NULL) { LM_DBG("sub_handling_node NULL\n"); goto done; } sub_handling = (char*)xmlNodeGetContent(sub_handling_node); LM_DBG("sub_handling_node->name= %s\n", sub_handling_node->name); LM_DBG("sub_handling_node->content= %s\n", sub_handling); if(sub_handling== NULL) { LM_ERR("Couldn't get sub-handling content\n"); ret = -1; goto done; } if( strncmp((char*)sub_handling, "block",5 )==0) { subs->status = TERMINATED_STATUS;; subs->reason.s= "rejected"; subs->reason.len = 8; } else if( strncmp((char*)sub_handling, "confirm",7 )==0) { subs->status = PENDING_STATUS; } else if( strncmp((char*)sub_handling , "polite-block",12 )==0) { subs->status = ACTIVE_STATUS; subs->reason.s= "polite-block"; subs->reason.len = 12; } else if( strncmp((char*)sub_handling , "allow",5 )==0) { subs->status = ACTIVE_STATUS; } else { LM_ERR("unknown subscription handling action\n"); ret = -1; } done: if(sub_handling) xmlFree(sub_handling); xmlFreeDoc(xcap_tree); return ret; }
int pres_watcher_allowed(subs_t* subs) { xmlDocPtr xcap_tree = NULL; xmlNodePtr node = NULL, actions_node = NULL, sub_handling_node = NULL; char* sub_handling = NULL; int action_value = -1, ret = 0; str watcher = {0, 0}; uandd_to_uri(subs->from_user, subs->from_domain, &watcher); if(watcher.s == NULL) { LM_ERR("while creating uri\n"); return -1; } /* if force_active set status to active*/ if(force_active) { subs->status = ACTIVE_STATUS; subs->reason.s = NULL; subs->reason.len = 0; ret = 0; goto done; } if(subs->auth_rules_doc == NULL) { subs->status = PENDING_STATUS; subs->reason.s = NULL; subs->reason.len = 0; ret = 0; goto done; } xcap_tree = xmlParseMemory(subs->auth_rules_doc->s, subs->auth_rules_doc->len); if(xcap_tree == NULL) { LM_ERR("parsing xml memory\n"); ret = -1; goto done; } node = get_rule_node(subs, xcap_tree); if(node == NULL) { /* if no rule node was found and the previous state was active -> set the * state to terminated with reason deactivated */ if(subs->status != PENDING_STATUS) { subs->status = TERMINATED_STATUS; subs->reason.s = "deactivated"; subs->reason.len = 11; } ret = 0; goto done; } /* If node is not NULL then there should be a actions element and a sub-handling element * for sure, get_rule_node makes sure of that */ actions_node = xmlNodeGetChildByName(node, "actions"); if (actions_node == NULL) { ret = -1; goto done; } sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling"); if (sub_handling_node == NULL) { ret = -1; goto done; } sub_handling = (char*)xmlNodeGetContent(sub_handling_node); if (sub_handling == NULL) { ret = -1; goto done; } action_value = get_action_value(sub_handling); switch (action_value) { case SH_ACTION_BLOCK: subs->status = TERMINATED_STATUS; subs->reason.s = "rejected"; subs->reason.len = 8; break; case SH_ACTION_CONFIRM: subs->status = PENDING_STATUS; subs->reason.s = NULL; subs->reason.len = 0; break; case SH_ACTION_POLITE_BLOCK: subs->status = ACTIVE_STATUS; subs->reason.s = "polite-block"; subs->reason.len = 12; break; case SH_ACTION_ALLOW: subs->status = ACTIVE_STATUS; subs->reason.s = NULL; subs->reason.len = 0; break; default: LM_ERR("unknown subscription handling action\n"); subs->status = PENDING_STATUS; subs->reason.s = NULL; subs->reason.len = 0; break; } LM_INFO("Subscription from %.*s to %.*s is %s\n", watcher.len, watcher.s, subs->pres_uri.len, subs->pres_uri.s, subs_strstatus(subs)); done: if (watcher.s) pkg_free(watcher.s); if (sub_handling) xmlFree(sub_handling); xmlFreeDoc(xcap_tree); return ret; }