mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 01:49:05 +00:00
FS-11346: [core] add api to pass pre-parsed values instead of dial strings to switch_ivr_originate
SWITCH_DECLARE(switch_status_t) switch_dial_handle_create(switch_dial_handle_t **handle); SWITCH_DECLARE(void) switch_dial_handle_destroy(switch_dial_handle_t **handle); SWITCH_DECLARE(void) switch_dial_handle_add_leg_list(switch_dial_handle_t *handle, switch_dial_leg_list_t **leg_listP); SWITCH_DECLARE(void) switch_dial_leg_list_add_leg(switch_dial_leg_list_t *parent, const char *dial_string, switch_dial_leg_t **legP); SWITCH_DECLARE(void) switch_dial_handle_add_global_var(switch_dial_handle_t *handle, const char *var, const char *val); SWITCH_DECLARE(void) switch_dial_handle_add_global_var_printf(switch_dial_handle_t *handle, const char *var, const char *fmt, ...); SWITCH_DECLARE(switch_status_t) switch_dial_handle_add_leg_var(switch_dial_leg_t *leg, const char *var, const char *val); SWITCH_DECLARE(switch_status_t) switch_dial_handle_add_leg_var_printf(switch_dial_leg_t *leg, const char *var, const char *fmt, ...); SWITCH_DECLARE(int) switch_dial_handle_get_peers(switch_dial_handle_t *handle, int idx, char **array, int max); SWITCH_DECLARE(int) switch_dial_handle_get_vars(switch_dial_handle_t *handle, int idx, switch_event_t **array, int max); SWITCH_DECLARE(switch_event_t *) switch_dial_handle_get_global_vars(switch_dial_handle_t *handle); SWITCH_DECLARE(switch_event_t *) switch_dial_leg_get_vars(switch_dial_leg_t *leg); SWITCH_DECLARE(int) switch_dial_handle_get_total(switch_dial_handle_t *handle); SWITCH_DECLARE(void) switch_ivr_orig_and_bridge(switch_core_session_t *session, const char *data, switch_dial_handle_t *dh); add switch_dial_handle_t *dh to end of args for switch_ivr_originate
This commit is contained in:
committed by
Mike Jerris
parent
b03cde3c57
commit
d3e320ef56
@@ -117,100 +117,108 @@ static switch_status_t do_config(switch_bool_t reload)
|
||||
|
||||
//#define _switch_stun_packet_next_attribute(attribute, end) (attribute && (attribute = (switch_stun_packet_attribute_t *) (attribute->value + _switch_stun_attribute_padded_length(attribute))) && ((void *)attribute < end) && ((void *)(attribute + _switch_stun_attribute_padded_length(attribute)) < end))
|
||||
|
||||
#define MAX_PEERS 128
|
||||
SWITCH_STANDARD_API(skel_function)
|
||||
{
|
||||
switch_event_t *event;
|
||||
unsigned char frame_buffer[8192] = {0};
|
||||
uint8_t buf[256] = { 0 };
|
||||
switch_stun_packet_t *packet;
|
||||
char user_name[] = "0000000000000000:1111111111111111";
|
||||
//char user_name[] = "0000000000000000";
|
||||
void *end_buf;
|
||||
switch_stun_packet_attribute_t *attr;
|
||||
int xlen = 0;
|
||||
|
||||
packet = switch_stun_packet_build_header(SWITCH_STUN_BINDING_REQUEST, NULL, buf);
|
||||
|
||||
printf("1len %d %d\n", ntohs(packet->header.length), xlen);
|
||||
|
||||
switch_stun_packet_attribute_add_username(packet, user_name, strlen(user_name));
|
||||
printf("2len %d %d\n", ntohs(packet->header.length), xlen);
|
||||
|
||||
switch_stun_packet_attribute_add_controlled(packet);
|
||||
|
||||
//switch_stun_packet_attribute_add_password(packet, user_name, strlen(user_name));
|
||||
//printf("3len %d %d\n", ntohs(packet->header.length), xlen);
|
||||
|
||||
//switch_stun_packet_attribute_add_use_candidate(packet);
|
||||
|
||||
switch_stun_packet_attribute_add_integrity(packet, "FUCK");
|
||||
switch_stun_packet_attribute_add_fingerprint(packet);
|
||||
switch_dial_handle_t *dh;
|
||||
switch_dial_leg_list_t *ll;
|
||||
switch_dial_leg_t *leg = NULL;
|
||||
int timeout = 0;
|
||||
char *peer_names[MAX_PEERS] = { 0 };
|
||||
switch_event_t *peer_vars[MAX_PEERS] = { 0 };
|
||||
int i;
|
||||
switch_core_session_t *peer_session = NULL;
|
||||
switch_call_cause_t cause;
|
||||
|
||||
switch_dial_handle_create(&dh);
|
||||
|
||||
|
||||
end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf));
|
||||
switch_dial_handle_add_global_var(dh, "ignore_early_media", "true");
|
||||
switch_dial_handle_add_global_var_printf(dh, "coolness_count", "%d", 12);
|
||||
|
||||
|
||||
//// SET TO 1 FOR AND LIST example or to 0 for OR LIST example
|
||||
#if 0
|
||||
switch_dial_handle_add_leg_list(dh, &ll);
|
||||
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo1@bar1.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo2@bar2.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo3@bar3.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/3000@cantina.freeswitch.org");
|
||||
|
||||
|
||||
#else
|
||||
|
||||
switch_dial_handle_add_leg_list(dh, &ll);
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo1@bar1.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
switch_dial_handle_add_leg_list(dh, &ll);
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo2@bar2.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
switch_dial_handle_add_leg_list(dh, &ll);
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/foo3@bar3.com");
|
||||
timeout += 10;
|
||||
switch_dial_handle_add_leg_var_printf(leg, "leg_timeout", "%d", timeout);
|
||||
|
||||
|
||||
switch_dial_handle_add_leg_list(dh, &ll);
|
||||
switch_dial_leg_list_add_leg(ll, &leg, "sofia/internal/3000@cantina.freeswitch.org");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/////// JUST DUMP SOME OF IT TO SEE FIRST
|
||||
|
||||
switch_dial_handle_get_peers(dh, 0, peer_names, MAX_PEERS);
|
||||
switch_dial_handle_get_vars(dh, 0, peer_vars, MAX_PEERS);
|
||||
|
||||
|
||||
|
||||
switch_stun_packet_first_attribute(packet, attr);
|
||||
|
||||
for(i = 0; i < MAX_PEERS; i++) {
|
||||
if (peer_names[i]) {
|
||||
char *foo;
|
||||
|
||||
printf("peer: [%s]\n", peer_names[i]);
|
||||
|
||||
xlen = sizeof(switch_stun_packet_header_t);
|
||||
|
||||
printf("len %d %d\n", ntohs(packet->header.length), xlen);
|
||||
|
||||
do {
|
||||
printf("WTF %p %d %d:(%d)\n", (void *)attr, ntohs(attr->type), ntohs(attr->length), switch_stun_attribute_padded_length_hbo(attr));
|
||||
|
||||
if (!switch_stun_packet_next_attribute_hbo(attr, end_buf)) {
|
||||
break;
|
||||
if (peer_vars[i]) {
|
||||
if (switch_event_serialize(peer_vars[i], &foo, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
printf("%s\n", foo);
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
xlen += 4+switch_stun_attribute_padded_length_hbo(attr);
|
||||
} while (xlen <= ntohs(packet->header.length));
|
||||
|
||||
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
do_config(SWITCH_TRUE);
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_size_t len = 0;
|
||||
int x = 0;
|
||||
|
||||
/* populate the event with some headers */
|
||||
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "testing", "true");
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "foo", "bar");
|
||||
|
||||
for (x = 0; x < 10; x++) {
|
||||
char name[128];
|
||||
switch_snprintf(name, sizeof(name), "test-header-%d", x);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, name, "value-%d", x);
|
||||
}
|
||||
|
||||
|
||||
/* Nothing up my sleeve, here is the event */
|
||||
|
||||
DUMP_EVENT(event);
|
||||
|
||||
|
||||
/* ok, serialize it into frame_buffer and destroy the event *poof* */
|
||||
len = sizeof(frame_buffer);
|
||||
switch_event_binary_serialize(event, (void *)frame_buffer, &len);
|
||||
switch_event_destroy(&event);
|
||||
|
||||
|
||||
/* wave the magic wand and feed frame_buffer to deserialize */
|
||||
switch_event_binary_deserialize(&event, (void *)frame_buffer, len, SWITCH_FALSE);
|
||||
|
||||
/* TA DA */
|
||||
DUMP_EVENT(event);
|
||||
|
||||
switch_event_destroy(&event);
|
||||
}
|
||||
|
||||
|
||||
switch_ivr_originate(NULL, &peer_session, &cause, NULL, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, dh);
|
||||
|
||||
if (peer_session) {
|
||||
switch_ivr_session_transfer(peer_session, "3500", "XML", NULL);
|
||||
switch_core_session_rwunlock(peer_session);
|
||||
}
|
||||
|
||||
|
||||
switch_dial_handle_destroy(&dh);
|
||||
|
||||
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user