/** * sngtc_get_codec_int - obtains the sngtc mapping for the given payload type * * @return: on success: enum sngtc_codec_definition * on failure: -1 * * TODO: optimize: binary search (3 iterations instead of 8?) */ static int sngtc_get_codec_int(str *payload) { int i; for (i = 0; codec_int_mappings[i].bitrate != -1; i++) if (codec_int_mappings[i].name.len == payload->len && str_strcasecmp(&codec_int_mappings[i].name, payload) == 0) return codec_int_mappings[i].sng_codec; return -1; }
/** * sngtc_get_codec_str - obtains the sngtc mapping for the given encoding name * * @return: on success: enum sngtc_codec_definition * on failure: -1 * * TODO: optimize: binary search (5 iterations instead of 25?) */ static int sngtc_get_codec_str(str *encode) { int i; for (i = 0; codec_str_mappings[i].bitrate != -1; i++) if (codec_str_mappings[i].name.len == encode->len && str_strcasecmp(&codec_str_mappings[i].name, encode) == 0) return codec_str_mappings[i].sng_codec; return -1; }
int cmd_check_addr(struct sip_msg *msg, char *param_cluster, char *param_ip, char *param_addr_type) { int cluster_id; str ip_str; str addr_type_str; static str bin_addr_t = str_init("bin"); static str sip_addr_t = str_init("sip"); enum node_addr_type check_type; if (fixup_get_ivalue(msg, (gparam_p)param_cluster, &cluster_id) < 0) { LM_ERR("Failed to fetch cluster id parameter\n"); return -1; } if (fixup_get_svalue(msg, (gparam_p)param_ip, &ip_str) < 0) { LM_ERR("Failed to fetch ip parameter\n"); return -1; } if (param_addr_type && fixup_get_svalue(msg, (gparam_p)param_addr_type, &addr_type_str) < 0) { LM_ERR("Failed to fetch address type parameter\n"); return -1; } if (param_addr_type) { if (!str_strcasecmp(&addr_type_str, &bin_addr_t)) check_type = NODE_BIN_ADDR; else if (!str_strcasecmp(&addr_type_str, &sip_addr_t)) check_type = NODE_SIP_ADDR; else { LM_ERR("Bad address type, should be 'bin' or 'sip'\n"); return -1; } } else check_type = NODE_SIP_ADDR; if (clusterer_check_addr(cluster_id, &ip_str, check_type) == 0) return -1; else return 1; }
int cmd_check_addr(struct sip_msg *msg, int *cluster_id, str *ip_str, str *addr_type_str) { static str bin_addr_t = str_init("bin"); static str sip_addr_t = str_init("sip"); enum node_addr_type check_type; if (addr_type_str) { if (!str_strcasecmp(addr_type_str, &bin_addr_t)) check_type = NODE_BIN_ADDR; else if (!str_strcasecmp(addr_type_str, &sip_addr_t)) check_type = NODE_SIP_ADDR; else { LM_ERR("Bad address type, should be 'bin' or 'sip'\n"); return -1; } } else check_type = NODE_SIP_ADDR; if (clusterer_check_addr(*cluster_id, ip_str, check_type) == 0) return -1; else return 1; }
/** * parses the command line argument for options * * @param buf the command line argument * @param opts fifo options * @param opt_set set of the options * * @return 0 on success, -1 on failure * * @see dump_fifo() */ static int get_fifo_opts(str * buf, fifo_opt_t * opts, unsigned int opt_set[]) { int opt_argc = 0; str opt_argv[20]; int i, op = -1; unsigned int used_opts = 0; int toklen; memset(opt_argv, 0, sizeof(opt_argv)); memset(opts, 0, sizeof(fifo_opt_t)); opts->prob = -1; while((toklen = str_toklen(buf, " \t\r\n")) >=0 && opt_argc < 20) { buf->s[toklen] = '\0'; /* insert zero termination, since strtod might be used later on it */ opt_argv[opt_argc].len = toklen; opt_argv[opt_argc].s = buf->s; buf->s += toklen + 1; buf->len -= toklen + 1; LM_DBG("found arg[%i]: %.*s\n", opt_argc, opt_argv[opt_argc].len, opt_argv[opt_argc].s); opt_argc++; } for (i=0; i<opt_argc; i++) { LM_DBG("token %.*s", opt_argv[i].len, opt_argv[i].s); if (opt_argv[i].len >= 1) { switch(*opt_argv[i].s) { case '-': switch(opt_argv[i].s[1]) { case OPT_DOMAIN_CHR: op = OPT_DOMAIN; used_opts |= O_DOMAIN; break; case OPT_PREFIX_CHR: op = OPT_PREFIX; used_opts |= O_PREFIX; break; case OPT_HOST_CHR: op = OPT_HOST; used_opts |= O_HOST; break; case OPT_NEW_TARGET_CHR: op = OPT_NEW_TARGET; used_opts |= O_NEW_TARGET; break; case OPT_PROB_CHR: op = OPT_PROB; used_opts |= O_PROB; break; case OPT_R_PREFIX_CHR: op = OPT_R_PREFIX; used_opts |= O_R_PREFIX; break; case OPT_R_SUFFIX_CHR: op = OPT_R_SUFFIX; used_opts |= O_R_SUFFIX; break; case OPT_HASH_INDEX_CHR: op = OPT_HASH_INDEX; used_opts |= O_H_INDEX; break; case OPT_HELP_CHR: FIFO_ERR(E_HELP); return -1; default: { FIFO_ERR(E_WRONGOPT); LM_DBG("Unknown option: %.*s\n", opt_argv[i].len, opt_argv[i].s); return -1; } } break; default: switch(op) { case OPT_DOMAIN: opts->domain = opt_argv[i]; op = -1; break; case OPT_PREFIX: if (str_strcasecmp(&opt_argv[i], &CR_EMPTY_PREFIX) == 0) { opts->prefix.s = NULL; opts->prefix.len = 0; } else { opts->prefix = opt_argv[i]; } op = -1; break; case OPT_HOST: opts->host = opt_argv[i]; op = -1; break; case OPT_NEW_TARGET: opts->new_host = opt_argv[i]; op = -1; break; case OPT_PROB: opts->prob = strtod(opt_argv[i].s, NULL); /* we can use str.s since we zero terminated it earlier */ op = -1; break; case OPT_R_PREFIX: opts->rewrite_prefix = opt_argv[i]; op = -1; break; case OPT_STRIP: str2sint(&opt_argv[i], &opts->strip); op = -1; break; case OPT_R_SUFFIX: opts->rewrite_suffix = opt_argv[i]; op = -1; break; case OPT_HASH_INDEX: str2sint(&opt_argv[i], &opts->hash_index); op = -1; break; default: { LM_DBG("No option given\n"); FIFO_ERR(E_NOOPT); return -1; } } break; } } } if((used_opts & opt_set[OPT_INVALID]) != 0) { LM_DBG("invalid option\n"); FIFO_ERR(E_INVALIDOPT); return -1; } if((used_opts & opt_set[OPT_MANDATORY]) != opt_set[OPT_MANDATORY]) { LM_DBG("option missing\n"); FIFO_ERR(E_MISSOPT); return -1; } return 0; }
/** * Loads the routing data from the config file given in global * variable config_data and stores it in routing tree rd. * The function mixes code parsing calls with rd structure * completion. * * @param rd Pointer to the route data tree where the routing data * shall be loaded into * * @return 0 means ok, -1 means an error occurred * */ int load_config(struct route_data_t * rd) { FILE * file; int ret_domain, ret_prefix, ret_target, ret_prefix_opts, ret_target_opts; int domain_id, allocated_domain_num = DEFAULT_DOMAIN_NUM; str domain_name, prefix_name, rewrite_host; char domain_buf[CR_MAX_LINE_SIZE], prefix_buf[CR_MAX_LINE_SIZE], rewrite_buf[CR_MAX_LINE_SIZE]; str rewrite_prefix, rewrite_suffix, comment; struct domain_data_t *domain_data = NULL; struct carrier_data_t * tmp_carrier_data; int hash_index, max_targets = 0, strip; double prob; int * backed_up = NULL; int backed_up_size = 0, backup = 0, status; void* p_realloc; int i=0, l, k; domain_name.s = domain_buf; domain_name.len = CR_MAX_LINE_SIZE; prefix_name.s = prefix_buf; prefix_name.len = CR_MAX_LINE_SIZE; rewrite_host.s = rewrite_buf; rewrite_host.len = CR_MAX_LINE_SIZE; /* open configuration file */ if ((file = fopen(config_file, "rb"))==NULL) { LM_ERR("Cannot open source file.\n"); return -1; } rd->carrier_num = 1; rd->first_empty_carrier = 0; rd->domain_num = 0; if ((rd->carriers = shm_malloc(sizeof(struct carrier_data_t *))) == NULL) { SHM_MEM_ERROR; goto errclose; } memset(rd->carriers, 0, sizeof(struct carrier_data_t *)); /* Create carrier map */ if ((rd->carrier_map = shm_malloc(sizeof(struct name_map_t))) == NULL) { SHM_MEM_ERROR; goto errclose; } memset(rd->carrier_map, 0, sizeof(struct name_map_t)); rd->carrier_map[0].id = 1; rd->carrier_map[0].name.len = default_tree.len; rd->carrier_map[0].name.s = shm_malloc(rd->carrier_map[0].name.len); if (rd->carrier_map[0].name.s == NULL) { SHM_MEM_ERROR; goto errclose; } memcpy(rd->carrier_map[0].name.s, default_tree.s, rd->carrier_map[0].name.len); /* Create domain map */ if ((rd->domain_map = shm_malloc(sizeof(struct name_map_t) * allocated_domain_num)) == NULL) { SHM_MEM_ERROR; goto errclose; } memset(rd->domain_map, 0, sizeof(struct name_map_t) * allocated_domain_num); /* Create and insert carrier data structure */ tmp_carrier_data = create_carrier_data(1, &rd->carrier_map[0].name, allocated_domain_num); if (tmp_carrier_data == NULL) { LM_ERR("can't create new carrier\n"); goto errclose; } tmp_carrier_data->domain_num = 0; tmp_carrier_data->id = 1; tmp_carrier_data->name = &(rd->carrier_map[0].name); if (add_carrier_data(rd, tmp_carrier_data) < 0) { LM_ERR("couldn't add carrier data\n"); destroy_carrier_data(tmp_carrier_data); goto errclose; } init_prefix_opts(); init_target_opts(); /* add all routes by parsing the route conf file */ /* while there are domain structures, get name and parse the structure*/ while ((ret_domain = parse_struct_header(file, "domain", &domain_name)) == SUCCESSFUL_PARSING) { domain_id = ++rd->domain_num; tmp_carrier_data->domain_num++; /* (re)allocate memory for a maximum of MAX_DOMAIN_NUM domains rd is not fully allocated from the start as this would require the preparsing of the entire route file */ if ( rd->domain_num > allocated_domain_num){ if (MAX_DOMAIN_NUM <= allocated_domain_num){ LM_ERR("Maximum number of domains reached"); break; } LM_INFO("crt_alloc_size=%d must be increased \n", allocated_domain_num); allocated_domain_num *= 2; if ( ( p_realloc = shm_realloc(rd->domain_map, sizeof(struct name_map_t) * allocated_domain_num) ) == NULL) { SHM_MEM_ERROR; goto errclose; } rd->domain_map = (struct name_map_t *)p_realloc; if (( p_realloc = shm_realloc( rd->carriers[0]->domains, sizeof(struct domain_data_t *) * allocated_domain_num)) == NULL) { SHM_MEM_ERROR; goto errclose; } rd->carriers[0]->domains = (struct domain_data_t **)p_realloc; for (i=0; i<rd->domain_num-1; i++){ rd->carriers[0]->domains[i]->name = &(rd->domain_map[i].name); } }// end of mem (re)allocation for domains /*insert domain in domain map*/ rd->domain_map[domain_id-1].id = domain_id; rd->domain_map[domain_id-1].name.len = domain_name.len; rd->domain_map[domain_id-1].name.s = shm_malloc(rd->domain_map[domain_id-1].name.len); if (rd->domain_map[domain_id-1].name.s == NULL) { SHM_MEM_ERROR; goto errclose; } memcpy(rd->domain_map[domain_id-1].name.s, domain_name.s, rd->domain_map[domain_id-1].name.len); /* create new domain data */ if ((domain_data = create_domain_data(domain_id,&(rd->domain_map[domain_id-1].name))) == NULL) { LM_ERR("could not create new domain data\n"); goto errclose; } if (add_domain_data(tmp_carrier_data, domain_data, domain_id-1) < 0) { LM_ERR("could not add domain data\n"); destroy_domain_data(domain_data); goto errclose; } LM_DBG("added domain %d '%.*s' to carrier %d '%.*s'\n", domain_id, domain_name.len, domain_name.s, tmp_carrier_data->id, tmp_carrier_data->name->len, tmp_carrier_data->name->s); /* while there are prefix structures, get name and parse the structure */ while ((ret_prefix = parse_struct_header(file, "prefix", &prefix_name)) == SUCCESSFUL_PARSING) { reset_prefix_opts(); if (str_strcasecmp(&prefix_name, &CR_EMPTY_PREFIX) == 0) { prefix_name.s[0] = '\0'; prefix_name.len = 0; } /* look for max_targets = value which is described in prefix_options */ if ((ret_prefix_opts = parse_options(file, prefix_options, PO_MAX_IDS, "target")) != SUCCESSFUL_PARSING) { LM_ERR("Error in parsing \n"); goto errclose; } max_targets = prefix_options[PO_MAX_TARGETS].value.int_data; /* look for max_targets target structures */ for ( k = 0; k < max_targets; k++) { /* parse the target header, get name and continue*/ ret_target = parse_struct_header(file, "target", &rewrite_host); if (ret_target != SUCCESSFUL_PARSING) { LM_ERR("Error in parsing \n"); goto errclose; } reset_target_opts(); /* look for the target options: prob, hash index, status, etc*/ ret_target_opts = parse_options(file, target_options, TO_MAX_IDS, "}"); if ( SUCCESSFUL_PARSING == ret_target_opts ){ /* parsing target structure closing bracket*/ parse_struct_stop(file); }else{ LM_ERR("Error in parsing in target options \n"); goto errclose; } /* intermediary variables for more lisibility */ if (str_strcasecmp(&rewrite_host, &CR_EMPTY_PREFIX) == 0) { rewrite_host.s[0] = '\0'; rewrite_host.len = 0; } LM_DBG("loading target %.*s\n", rewrite_host.len, rewrite_host.s); prob = target_options[TO_ID_PROB].value.float_data; strip = target_options[TO_ID_STRIP].value.int_data; rewrite_prefix.s = target_options[TO_ID_REWR_PREFIX].value.string_data.s; rewrite_prefix.len = target_options[TO_ID_REWR_PREFIX].value.string_data.len; rewrite_suffix.s = target_options[TO_ID_REWR_SUFFIX].value.string_data.s; rewrite_suffix.len = target_options[TO_ID_REWR_SUFFIX].value.string_data.len; hash_index = target_options[TO_ID_HASH_INDEX].value.int_data; comment.s = target_options[TO_ID_COMMENT].value.string_data.s; comment.len = target_options[TO_ID_COMMENT].value.string_data.len; status = target_options[TO_ID_STATUS].value.int_data; if ( (backed_up_size = target_options[TO_ID_BACKED_UP].no_elems) > 0){ if ((backed_up = pkg_malloc(sizeof(int) * (backed_up_size + 1))) == NULL) { PKG_MEM_ERROR; goto errclose; } for (l = 0; l < backed_up_size; l++) { backed_up[l] = target_options[TO_ID_BACKED_UP].value.int_list[l]; } backed_up[backed_up_size] = -1; } backup = target_options[TO_ID_BACKUP].value.int_data; LM_DBG("\n Adding route to tree <'%.*s'>: prefix_name:%s\n," " max_targets =%d\n, prob=%f\n, rewr_host=%s\n," " strip=%i\n, rwr_prefix=%s\n, rwr_suff=%s\n," " status=%i\n, hash_index=%i\n, comment=%s \n", domain_data->name->len, domain_data->name->s, prefix_name.s, max_targets, prob, rewrite_host.s, strip, rewrite_prefix.s, rewrite_suffix.s, status, hash_index, comment.s); if (add_route_to_tree(domain_data->tree, &prefix_name, 0, 0, &prefix_name, max_targets, prob, &rewrite_host, strip, &rewrite_prefix, &rewrite_suffix, status, hash_index, backup, backed_up, &comment) < 0) { LM_INFO("Error while adding route\n"); if (backed_up) { pkg_free(backed_up); } goto errclose; } if (backed_up) { pkg_free(backed_up); } backed_up = NULL; } if (k != prefix_options[0].value.int_data ) { LM_ERR("Error in parsing: max_targets =%i, actual targets =%i \n", prefix_options[0].value.int_data, i); goto errclose; } /* parsing prefix structure closing bracket */ if (parse_struct_stop(file) != SUCCESSFUL_PARSING) { LM_ERR("Error in parsing targets, expecting } \n"); goto errclose; } } // END OF PREFIX part /* parsing domain structure closing bracket */ if (parse_struct_stop(file) != SUCCESSFUL_PARSING) { LM_ERR("Error in parsing targets, expecting } \n"); goto errclose; } } if (EOF_REACHED != ret_domain){ LM_ERR("Error appeared while parsing domain header \n"); goto errclose; } LM_INFO("File parsed successfully \n"); fclose(file); return 0; errclose: fclose(file); return -1; }
int fifo_pa_location_contact(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char p_contact_s[MAX_P_URI]; char location_s[MAX_LOCATION]; char priority_s[MAX_LOCATION]; char expires_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, p_contact, location, priority_str, expires_str; time_t expires; double priority; int changed = 0; char *msg = "no error"; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location_contact: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(p_contact_s, MAX_P_URI, fifo, &p_contact.len) || p_contact.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_contact expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_contact expected\n"); return 1; } p_contact.s = p_contact_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location_contact: location expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: location expected\n"); return 1; } location.s = location_s; if (!read_line(priority_s, MAX_LOCATION, fifo, &priority_str.len) || priority_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: priority expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: priority expected\n"); return 1; } priority = strtod(priority_s, NULL); if (!read_line(expires_s, MAX_LOCATION, fifo, &expires_str.len) || expires_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: expires expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: expires expected\n"); return 1; } expires = strtoul(expires_s, NULL, 0); register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location_contact: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { msg = "400 could not find presentity\n"; LOG(L_ERR, "ERROR: pa_location_contact: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } find_presence_tuple(&p_contact, presentity, &tuple); if (!tuple && new_tuple_on_publish) { new_presence_tuple(&p_contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); tuple->state = PS_ONLINE; changed = 1; } if (!tuple) { LOG(L_ERR, "publish_presentity: no tuple for %.*s\n", presentity->uri.len, presentity->uri.s); msg = "400 could not find presence tuple\n"; goto error; } changed = 1; if (1 || (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0)) { changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (tuple->priority != priority) { tuple->priority = priority; changed = 1; } if (expires < 7*24*3600) { /* must be seconds */ get_act_time(); expires = act_time + expires; } if (tuple->expires != expires) { tuple->expires = expires; changed = 1; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; error: unlock_pdomain(pdomain); fifo_reply(response_file, msg); return 1; }
int fifo_pa_location(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char location_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, location; int changed = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location: location expected\n"); LOG(L_ERR, "ERROR: pa_location: location expected\n"); return 1; } location.s = location_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { unlock_pdomain(pdomain); fifo_reply(response_file, "400 could not find presentity\n"); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } changed = 1; for (tuple = presentity->tuples; tuple; tuple = tuple->next) { if (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0) changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; }
/* * Update existing presentity and watcher list */ static int publish_presentity_pidf(struct sip_msg* _m, struct pdomain* _d, struct presentity* presentity, int *pchanged) { char *body = get_body(_m); presence_tuple_t *tuple = NULL; str contact = { NULL, 0 }; str basic = { NULL, 0 }; str status = { NULL, 0 }; str location = { NULL, 0 }; str site = { NULL, 0 }; str floor = { NULL, 0 }; str room = { NULL, 0 }; str packet_loss = { NULL, 0 }; double x=0, y=0, radius=0; time_t expires = act_time + default_expires; double priority = default_priority; int prescaps = 0; int flags = 0; int changed = 0; int ret = 0; flags = parse_pidf(body, &contact, &basic, &status, &location, &site, &floor, &room, &x, &y, &radius, &packet_loss, &priority, &expires, &prescaps); if (contact.len) { find_presence_tuple(&contact, presentity, &tuple); if (!tuple && new_tuple_on_publish) { new_presence_tuple(&contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); changed = 1; } } else { tuple = presentity->tuples; } if (!tuple) { LOG(L_ERR, "publish_presentity: no tuple for %.*s\n", presentity->uri.len, presentity->uri.s); return -1; } LOG(L_INFO, "publish_presentity_pidf: -1-\n"); if (basic.len && basic.s) { int origstate = tuple->state; tuple->state = ((strcasecmp(basic.s, "online") == 0) || (strcasecmp(basic.s, "open") == 0)) ? PS_ONLINE : PS_OFFLINE; if (tuple->state != origstate) changed = 1; } if (status.len && status.s) { if (tuple->status.len && str_strcasecmp(&tuple->status, &status) != 0) changed = 1; tuple->status.len = status.len; strncpy(tuple->status.s, status.s, status.len); tuple->status.s[status.len] = 0; } LOG(L_INFO, "publish_presentity: -2-\n"); if (location.len && location.s) { if (tuple->location.loc.len && str_strcasecmp(&tuple->location.loc, &location) != 0) changed = 1; tuple->location.loc.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.s[location.len] = 0; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.loc.len = 0; } if (site.len && site.s) { if (tuple->location.site.len && str_strcasecmp(&tuple->location.site, &site) != 0) changed = 1; tuple->location.site.len = site.len; strncpy(tuple->location.site.s, site.s, site.len); tuple->location.site.s[site.len] = 0; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.site.len = 0; } if (floor.len && floor.s) { if (tuple->location.floor.len && str_strcasecmp(&tuple->location.floor, &floor) != 0) changed = 1; tuple->location.floor.len = floor.len; strncpy(tuple->location.floor.s, floor.s, floor.len); tuple->location.floor.s[floor.len] = 0; }else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.floor.len = 0; } if (room.len && room.s) { if (tuple->location.room.len && str_strcasecmp(&tuple->location.room, &room) != 0) changed = 1; tuple->location.room.len = room.len; strncpy(tuple->location.room.s, room.s, room.len); tuple->location.room.s[room.len] = 0; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.room.len = 0; } if (packet_loss.len && packet_loss.s) { if (tuple->location.packet_loss.len && str_strcasecmp(&tuple->location.packet_loss, &packet_loss) != 0) changed = 1; tuple->location.packet_loss.len = packet_loss.len; strncpy(tuple->location.packet_loss.s, packet_loss.s, packet_loss.len); tuple->location.packet_loss.s[packet_loss.len] = 0; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.packet_loss.len = 0; } if (x) { if (tuple->location.x != x) changed = 1; tuple->location.x = x; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.x = 0; } if (y) { if (tuple->location.y != y) changed = 1; tuple->location.y = y; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.y = 0; } if (radius) { if (tuple->location.radius != radius) changed = 1; tuple->location.radius = radius; } else if (flags & PARSE_PIDF_LOCATION_MASK) { tuple->location.radius = 0; } if (tuple->priority != priority) { changed = 1; tuple->priority = priority; } if (tuple->expires != expires) { changed = 1; tuple->expires = expires; } if (use_location_package) if (site.len && floor.len && room.len && changed) { location_package_location_add_user(_d, &site, &floor, &room, presentity); } if (flags & PARSE_PIDF_PRESCAPS) { if (tuple->prescaps != prescaps) changed = 1; tuple->prescaps = prescaps; } changed = 1; if (changed) presentity->flags |= PFLAG_PRESENCE_CHANGED; LOG(L_INFO, "publish_presentity: -3-: changed=%d\n", changed); if (pchanged && changed) { *pchanged = 1; } if ((ret = db_update_presentity(presentity)) < 0) { return ret; } LOG(L_INFO, "publish_presentity: -4-\n"); return 0; }
/** * Loads the routing data from the config file given in global * variable config_data and stores it in routing tree rd. * * @param rd Pointer to the route data tree where the routing data * shall be loaded into * * @return 0 means ok, -1 means an error occurred * */ int load_config(struct rewrite_data * rd) { cfg_t * cfg = NULL; int n, m, o, i, j, k,l; cfg_t * d, * p, * t; str domain; str prefix; double prob; str rewrite_prefix; str rewrite_suffix; str rewrite_host; str comment; int backed_up_size = 0; int * backed_up = NULL; int backup = 0; int status, hash_index, max_targets, strip; if ((cfg = parse_config()) == NULL) { return -1; } if ((rd->carriers = shm_malloc(sizeof(struct carrier_tree *))) == NULL) { LM_ERR("out of shared memory\n"); return -1; } memset(rd->carriers, 0, sizeof(struct carrier_tree *)); rd->tree_num = 1; n = cfg_size(cfg, "domain"); if (add_carrier_tree(&default_tree, 1, rd, n) == NULL) { LM_ERR("couldn't add carrier tree\n"); return -1; } memset(rd->carriers[0]->trees, 0, sizeof(struct route_tree *) * n); for (i = 0; i < n; i++) { d = cfg_getnsec(cfg, "domain", i); domain.s = (char *)cfg_title(d); if (domain.s==NULL) domain.s=""; domain.len = strlen(domain.s); m = cfg_size(d, "prefix"); LM_INFO("loading domain %.*s\n", domain.len, domain.s); for (j = 0; j < m; j++) { p = cfg_getnsec(d, "prefix", j); prefix.s = (char *)cfg_title(p); if (prefix.s==NULL) prefix.s=""; prefix.len = strlen(prefix.s); if (str_strcasecmp(&prefix, &SP_EMPTY_PREFIX) == 0) { prefix.s = ""; prefix.len = 0; } LM_INFO("loading prefix %.*s\n", prefix.len, prefix.s); max_targets = cfg_getint(p, "max_targets"); o = cfg_size(p, "target"); for (k = 0; k < o; k++) { t = cfg_getnsec(p, "target", k); rewrite_host.s = (char *)cfg_title(t); if (rewrite_host.s==NULL) rewrite_host.s=""; rewrite_host.len = strlen(rewrite_host.s); if (str_strcasecmp(&rewrite_host, &SP_EMPTY_PREFIX) == 0) { rewrite_host.s = ""; rewrite_host.len = 0; } LM_INFO("loading target %.*s\n", rewrite_host.len, rewrite_host.s); prob = cfg_getfloat(t, "prob"); strip = cfg_getint(t, "strip"); rewrite_prefix.s = (char *)cfg_getstr(t, "rewrite_prefix"); if (rewrite_prefix.s==NULL) rewrite_prefix.s=""; rewrite_prefix.len = strlen(rewrite_prefix.s); rewrite_suffix.s = (char *)cfg_getstr(t, "rewrite_suffix"); if (rewrite_suffix.s==NULL) rewrite_suffix.s=""; rewrite_suffix.len = strlen(rewrite_suffix.s); hash_index = cfg_getint(t, "hash_index"); comment.s = (char *)cfg_getstr(t, "comment"); if (comment.s==NULL) comment.s=""; comment.len = strlen(comment.s); status = cfg_getint(t, "status"); if ((backed_up_size = cfg_size(t, "backed_up")) > 0) { if ((backed_up = pkg_malloc(sizeof(int) * (backed_up_size + 1))) == NULL) { LM_ERR("out of private memory\n"); return -1; } for (l = 0; l < backed_up_size; l++) { backed_up[l] = cfg_getnint(t, "backed_up", l); } backed_up[backed_up_size] = -1; } backup = cfg_getint(t, "backup"); LM_INFO("adding route for prefix %.*s, to host %.*s, prob %f, backed up: %i, backup: %i\n", prefix.len, prefix.s, rewrite_host.len, rewrite_host.s, prob, backed_up_size, backup); if (add_route(rd, 1, &domain, &prefix, 0, 0, max_targets, prob, &rewrite_host, strip, &rewrite_prefix, &rewrite_suffix, status, hash_index, backup, backed_up, &comment) < 0) { LM_INFO("Error while adding route\n"); if (backed_up) { pkg_free(backed_up); } return -1; } if (backed_up) { pkg_free(backed_up); } backed_up = NULL; } } } cfg_free(cfg); return 0; }