Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 98 additions & 79 deletions src/switch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1333,96 +1333,115 @@ SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *t

SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup)
{
switch_event_header_t *hp;
switch_event_header_t *hp;

if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}

(*event)->event_id = todup->event_id;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
(*event)->flags = todup->flags;
for (hp = todup->headers; hp; hp = hp->next) {
if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}
(*event)->event_id = todup->event_id;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
(*event)->flags = todup->flags;

if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, hp->name, hp->array[i]);
}
} else {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
}
}
for (hp = todup->headers; hp; hp = hp->next) {
if (zstr(hp->name)) {
continue;
}

if (todup->body) {
(*event)->body = DUP(todup->body);
}
if (todup->subclass_name && !strcasecmp(hp->name, "Event-Subclass")) {
continue;
}

(*event)->key = todup->key;
if (hp->idx > 0 && hp->array) {
for (int i = 0; i < hp->idx; i++) {
if (!zstr(hp->array[i])) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, hp->name, hp->array[i]);
}
}
} else if (!zstr(hp->value)) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, hp->name, hp->value);
}
}

return SWITCH_STATUS_SUCCESS;
if (!zstr(todup->body)) {
(*event)->body = DUP(todup->body);
}

(*event)->key = todup->key;

return SWITCH_STATUS_SUCCESS;
}


SWITCH_DECLARE(switch_status_t) switch_event_dup_reply(switch_event_t **event, switch_event_t *todup)
{
switch_event_header_t *hp;
char hname[1024] = "";
char *p;

if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}

(*event)->event_id = todup->event_id;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
(*event)->flags = todup->flags;

for (hp = todup->headers; hp; hp = hp->next) {
char *name = hp->name, *value = hp->value;

if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}

if (!strncasecmp(hp->name, "from_", 5)) {
p = hp->name + 5;
switch_snprintf(hname, sizeof(hname), "to_%s", p);
name = hname;
} else if (!strncasecmp(hp->name, "to_", 3)) {
p = hp->name + 3;
switch_snprintf(hname, sizeof(hname), "from_%s", p);
name = hname;
} else if (!strcasecmp(name, "to")) {
name = "from";
} else if (!strcasecmp(name, "from")) {
name = "to";
}

if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, name, hp->array[i]);
}
} else {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, name, value);
}
}

switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "replying", "true");

if (todup->body) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "orig_body", todup->body);
}

(*event)->key = todup->key;

return SWITCH_STATUS_SUCCESS;
switch_event_header_t *hp;
char hname[1024] = "";
char *p;

if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}

(*event)->event_id = todup->event_id;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
(*event)->flags = todup->flags;

for (hp = todup->headers; hp; hp = hp->next) {
char *name;
char *value;

if (zstr(hp->name)) {
continue;
}

if (todup->subclass_name && !strcasecmp(hp->name, "Event-Subclass")) {
continue;
}

name = hp->name;
value = hp->value;

if (zstr(value) && hp->idx == 0) {
continue;
}

if (!strncasecmp(name, "from_", 5)) {
p = name + 5;
switch_snprintf(hname, sizeof(hname), "to_%s", p);
name = hname;
} else if (!strncasecmp(name, "to_", 3)) {
p = name + 3;
switch_snprintf(hname, sizeof(hname), "from_%s", p);
name = hname;
} else if (!strcasecmp(name, "to")) {
name = "from";
} else if (!strcasecmp(name, "from")) {
name = "to";
}

if (hp->idx > 0 && hp->array) {
for (int i = 0; i < hp->idx; i++) {
if (!zstr(hp->array[i])) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, name, hp->array[i]);
}
}
} else if (!zstr(value)) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, name, value);
}
}

switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "replying", "true");

if (!zstr(todup->body)) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "orig_body", todup->body);
}

(*event)->key = todup->key;

return SWITCH_STATUS_SUCCESS;
}

#define SWITCH_SERIALIZED_EVENT_MAP "S(iiisss)A(S(ss))"
Expand Down