static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, switch_caller_profile_t *outbound_profile, switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) { const char *profile; char *dup_profile = NULL; if (session) { profile = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_profile"); } else { dup_profile = switch_core_get_variable_dup("sip_profile"); profile = dup_profile; } if (zstr(profile)) { profile = "default"; } outbound_profile->destination_number = switch_core_sprintf(outbound_profile->pool, "%s/%s", profile, outbound_profile->destination_number); UNPROTECT_INTERFACE(sip_endpoint_interface); switch_safe_free(dup_profile); return switch_core_session_outgoing_channel(session, var_event, "sofia", outbound_profile, new_session, pool, SOF_NONE, cancel_cause); }
static char *expand_vars(char *xml_str) { char *var, *val; char *rp = xml_str; /* read pointer */ char *ep, *wp, *buff; /* end pointer, write pointer, write buffer */ if (!(strstr(xml_str, "$${"))) { return xml_str; } switch_zmalloc(buff, strlen(xml_str) * 2); wp = buff; ep = buff + (strlen(xml_str) * 2) - 1; while (*rp && wp < ep) { if (*rp == '$' && *(rp + 1) == '$' && *(rp + 2) == '{') { char *e = switch_find_end_paren(rp + 2, '{', '}'); if (e) { rp += 3; var = rp; *e++ = '\0'; rp = e; if ((val = switch_core_get_variable_dup(var))) { char *p; for (p = val; p && *p && wp <= ep; p++) { *wp++ = *p; } switch_safe_free(val); } continue; } } *wp++ = *rp++; } *wp++ = '\0'; switch_safe_free(xml_str); return buff; }
static void valet_send_presence(const char *lot_name, valet_lot_t *lot, valet_token_t *token, switch_bool_t in) { char *domain_name, *dup_lot_name = NULL, *dup_domain_name = NULL; switch_event_t *event; int count; dup_lot_name = strdup(lot_name); lot_name = dup_lot_name; if ((domain_name = strchr(dup_lot_name, '@'))) { *domain_name++ = '\0'; } if (zstr(domain_name)) { dup_domain_name = switch_core_get_variable_dup("domain"); domain_name = dup_domain_name; } if (zstr(domain_name)) { domain_name = "cluecon.com"; } count = valet_lot_count(lot); if (count > 0) { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "force-status", "Active (%d caller%s)", count, count == 1 ? "" : "s"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "active"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", lot_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "confirmed"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound"); switch_event_fire(&event); } } else { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", lot_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", lot_name, domain_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Empty"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", lot_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "terminated"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound"); switch_event_fire(&event); } } if (in) { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", token->ext); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", token->ext, domain_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", token->bridged == 0 ? "Holding" : "Active"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "active"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", token->ext); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "confirmed"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", token->bridged == 0 ? "outbound" : "inbound"); switch_event_fire(&event); } } else { if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", VALET_PROTO); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", token->ext); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", token->ext, domain_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "force-status", "Empty"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", "unknown"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", EC++); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", token->ext); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "terminated"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-direction", "inbound"); switch_event_fire(&event); } } switch_safe_free(dup_domain_name); switch_safe_free(dup_lot_name); }
SWITCH_DECLARE(char *) getGlobalVariable(char *var_name) { return switch_core_get_variable_dup(var_name); }
static abyss_bool http_directory_auth(TSession *r, char *domain_name) { char *p = NULL; char *x = NULL; char z[256] = "", t[80] = ""; char user[512] = "" ; char *pass = NULL; const char *mypass1 = NULL, *mypass2 = NULL; const char *box = NULL; int at = 0; char *dp = NULL; abyss_bool rval = FALSE; char *dup_domain = NULL; p = RequestHeaderValue(r, "authorization"); if (p) { NextToken((const char **const) &p); x = GetToken(&p); if (x) { if (!strcasecmp(x, "basic")) { NextToken((const char **const) &p); switch_b64_decode(p, user, sizeof(user)); if ((pass = strchr(user, ':'))) { *pass++ = '\0'; } if ((dp = strchr(user, '@'))) { *dp++ = '\0'; domain_name = dp; at++; } if (!domain_name) { if (globals.virtual_host) { if ((domain_name = (char *) r->requestInfo.host)) { if (!strncasecmp(domain_name, "www.", 3)) { domain_name += 4; } } } if (!domain_name) { if (globals.default_domain) { domain_name = globals.default_domain; } else { if ((dup_domain = switch_core_get_variable_dup("domain"))) { domain_name = dup_domain; } } } } if (zstr(user) || zstr(domain_name)) { goto fail; } if (!zstr(globals.realm) && !zstr(globals.user) && !zstr(globals.pass)) { if (at) { switch_snprintf(z, sizeof(z), "%s@%s:%s", globals.user, globals.realm, globals.pass); } else { switch_snprintf(z, sizeof(z), "%s:%s", globals.user, globals.pass); } xmlrpc_base64Encode(z, t); if (!strcmp(p, t)) { goto authed; } } if (!user_attributes(user, domain_name, &mypass1, &mypass2, &box, NULL)) { goto fail; } if (!zstr(mypass2) && !strcasecmp(mypass2, "user-choose")) { switch_safe_free(mypass2); } if (!mypass1) { goto authed; } else { if (at) { switch_snprintf(z, sizeof(z), "%s@%s:%s", user, domain_name, mypass1); } else { switch_snprintf(z, sizeof(z), "%s:%s", user, mypass1); } xmlrpc_base64Encode(z, t); if (!strcmp(p, t)) { goto authed; } if (mypass2) { if (at) { switch_snprintf(z, sizeof(z), "%s@%s:%s", user, domain_name, mypass2); } else { switch_snprintf(z, sizeof(z), "%s:%s", user, mypass2); } xmlrpc_base64Encode(z, t); if (!strcmp(p, t)) { goto authed; } } if (box) { if (at) { switch_snprintf(z, sizeof(z), "%s@%s:%s", box, domain_name, mypass1); } else { switch_snprintf(z, sizeof(z), "%s:%s", box, mypass1); } xmlrpc_base64Encode(z, t); if (!strcmp(p, t)) { goto authed; } if (mypass2) { if (at) { switch_snprintf(z, sizeof(z), "%s@%s:%s", box, domain_name, mypass2); } else { switch_snprintf(z, sizeof(z), "%s:%s", box, mypass2); } xmlrpc_base64Encode(z, t); if (!strcmp(p, t)) { goto authed; } } } } goto fail; authed: switch_snprintf(z, sizeof(z), "%s@%s", (box ? box : user), domain_name); r->requestInfo.user = strdup(z); ResponseAddField(r, "freeswitch-user", (box ? box : user)); ResponseAddField(r, "freeswitch-domain", domain_name); rval = TRUE; goto done; } } } fail: switch_snprintf(z, sizeof(z), "Basic realm=\"%s\"", domain_name ? domain_name : globals.realm); ResponseAddField(r, "WWW-Authenticate", z); ResponseStatus(r, 401); done: switch_safe_free(mypass1); switch_safe_free(mypass2); switch_safe_free(box); switch_safe_free(dup_domain); return rval; }