Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header editing feature #3857

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
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
63 changes: 63 additions & 0 deletions pjsip-apps/src/pjsua/pjsua_app_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ static void keystroke_help()
puts("| | V Adjust audio Volume | f Save config |");
puts("| S Send arbitrary REQUEST | Cp Codec priorities | |");
puts("+-----------------------------------------------------------------------------+");
puts("| Patch Commands: |");
puts("| |");
puts("| pa Append field to outgiong requests |");
puts("| pd Delete field from outgiong requests |");
puts("| pr Replace field in outgiong requests |");
puts("| p- Stop apply p* manipulation with outgoing requests |");
puts("| p+ Resume apply p* manipulation with outgoing requests |");
puts("| pc Discard all changes for outgoing requests |");
puts("+-----------------------------------------------------------------------------+");

#if PJSUA_HAS_VIDEO
puts("| Video: \"vid help\" for more info |");
puts("+-----------------------------------------------------------------------------+");
Expand Down Expand Up @@ -2081,6 +2091,59 @@ void legacy_main(void)
ui_handle_ip_change();
break;

case 'p': /* Handle header editing patches */
{
if (menuin[1] == '-') {
set_override(0);
break;
}
if (menuin[1] == '+') {
set_override(1);
break;
}
if (menuin[1] == 'c') {
int previous, current;
previous = request_lens();
clean_request_head();
current = previous - request_lens();
printf("Clean %d headers overhead\n", current);
break;
}

if (menuin[1] == 'd') {
char h_name[FIELD_SIZE];
char h_value[FIELD_SIZE];;
simple_input("Header:", h_name, sizeof(h_name));
if (!simple_input("Value:", h_value, sizeof(h_value))) {
*h_value = '\0';
}
to_request_tail(h_name, h_value, -1);
set_override(1);
break;
}
if (menuin[1] == 'a') {
int mode = 1;
if (menuin[2]=='+'){
mode = 10;
}
char h_name[FIELD_SIZE], h_value[FIELD_SIZE];
simple_input("Header:", h_name, sizeof(h_name));
simple_input("Value:", h_value, sizeof(h_value));
to_request_tail(h_name, h_value, mode);
set_override(1);
break;
}
if (menuin[1] == 'r') {
char h_name[FIELD_SIZE], h_value[FIELD_SIZE];
simple_input("Header:", h_name, sizeof(h_name));
simple_input("Value:", h_value, sizeof(h_value));
to_request_tail(h_name, h_value, 0);
set_override(1);
break;
}
break;
}

default:
if (menuin[0] != '\n' && menuin[0] != '\r') {
printf("Invalid input %s", menuin);
Expand Down
13 changes: 12 additions & 1 deletion pjsip/include/pjsip.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
#include <pjsip/sip_ua_layer.h>
#include <pjsip/sip_dialog.h>

#define FIELD_SIZE 256

#endif /* __PJSIP_H__ */
struct cli_hdr
{
char title[FIELD_SIZE];
char value[FIELD_SIZE];
int operation;
struct cli_hdr *next;
};

typedef struct cli_hdr extheader;


#endif /* __PJSIP_H__ */
6 changes: 6 additions & 0 deletions pjsip/include/pjsip/sip_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ struct pjsip_module
* to change.
*/
void (*on_tsx_state)(pjsip_transaction *tsx, pjsip_event *event);
/**
* Optional function to be called when transport layer is about to
* transmit outgoing response message and provide manipulation with
* tdata

*/
pj_status_t (*pre_send_cb)(pjsip_tx_data *tdata); // pre request cb
};


Expand Down
47 changes: 45 additions & 2 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -9088,14 +9088,57 @@ PJ_DECL(pj_status_t) pjsua_vid_conf_update_port(pjsua_conf_port_id port_id);


/* end of VIDEO API */

/**
* @}
* Get the override headers flag.
*
* @return int value of the override flag.
*/
PJ_DECL(int) get_override();


/**
* @}
* Set the override headers flag.
*
* @param int value to set into the override flag
*/
PJ_DECL(void) set_override(int new_flag);


/**
* Return pointer to the extheader object
*
* @return pointer to extheader object
*/
PJ_DECL(extheader*) get_request_head();


/**
* Returns length of extheader list
*
* @return length of extheader list
*/
PJ_DECL(int) request_lens();


/**
* Clean extheader object
*/
PJ_DECL(void) clean_request_head();


/**
*
* @param t header title for an operation
* @param v header value for an operation
* @param op number of operation, where
* 0 - replace header
* 1 - append header
* -1 - delete header
* 10 - append header, if currently exist header with the same name
*/
PJ_DECL(void) to_request_tail(char *t, char* v, int op);


PJ_END_DECL

Expand Down
20 changes: 13 additions & 7 deletions pjsip/src/pjsip/sip_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,13 +1115,19 @@ static pj_status_t endpt_on_tx_msg( pjsip_endpoint *endpt,

mod = endpt->module_list.prev;
if (tdata->msg->type == PJSIP_REQUEST_MSG) {
while (mod != &endpt->module_list) {
if (mod->on_tx_request)
status = (*mod->on_tx_request)(tdata);
if (status != PJ_SUCCESS)
break;
mod = mod->prev;
}
while (mod != &endpt->module_list) {
if (mod->pre_send_cb) {
status = (*mod->pre_send_cb)(tdata);
if (status != PJ_SUCCESS){
puts("Header management fails!");
}
}
if (mod->on_tx_request)
status = (*mod->on_tx_request)(tdata);
if (status != PJ_SUCCESS)
break;
mod = mod->prev;
}

} else {
while (mod != &endpt->module_list) {
Expand Down
155 changes: 155 additions & 0 deletions pjsip/src/pjsua-lib/pjsua_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,161 @@ static int get_ip_addr_ver(const pj_str_t *host);
static void schedule_reregistration(pjsua_acc *acc);
static void keep_alive_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te);


int is_override = 0;
extheader* head_request_changes = NULL;
extheader* clean_list = NULL;


PJ_DEF(void) set_override(int new_flag)
{
is_override = new_flag;
}


PJ_DEF(int) get_override()
{
return is_override;
}


PJ_DEF(extheader*) get_request_head()
{
return head_request_changes;
}


PJ_DEF(extheader*) generic_get_tail(extheader* first_element)
{
if(first_element==NULL){
return first_element;
}

if(first_element->next==NULL){
return first_element;
}
extheader *last;
last = first_element->next;
while(last->next!=NULL){
last = last->next;
}
return last;
}


PJ_DEF(extheader*) get_request_tail()
{
return generic_get_tail(head_request_changes);
}


PJ_DEF(void) generic_to_tail(extheader* first_element, char *t, char* v, int op)
{
extheader* tailed;
extheader* last;
tailed=malloc(sizeof(extheader));
if (tailed==NULL){
return ;
}
strcpy(tailed->title, t);
strcpy(tailed->value, v);

tailed->operation = op;

tailed->next= NULL;
last = generic_get_tail(first_element);
if (last==NULL){
first_element = tailed;
return ;
}
last->next = tailed;
}


PJ_DEF(void) to_request_tail(char *t, char* v, int op)
{
extheader* tailed;
extheader* last;
tailed=malloc(sizeof(extheader));
if (tailed==NULL){
return ;
}
strcpy(tailed->title, t);
strcpy(tailed->value, v);

tailed->operation = op;

tailed->next= NULL;
last = get_request_tail();
if (last==NULL){
head_request_changes = tailed;
return ;
}
last->next = tailed;
}


PJ_DEF(int) generic_lens(extheader* first_element)
{
int i = 0;
if (first_element==NULL){
return i;
}
extheader* iteration_head;
iteration_head = first_element;
while(iteration_head!=NULL){
i++;
iteration_head = iteration_head->next;
}
return i;
}


PJ_DEF(int) request_lens()
{
return generic_lens(head_request_changes);
}


void generic_clean_head(extheader* first_element)
{
if (first_element == NULL){
return ;
}
extheader* current_head;
current_head = first_element;
while(current_head!=NULL){
current_head = first_element->next;
free(first_element);
first_element = current_head;
}
first_element = NULL;
}


void clean_request_head()
{
extheader *clean_tail = NULL;
if(clean_list==NULL){
clean_list = head_request_changes;
}
else{
clean_tail = clean_list;
while(clean_tail->next!=NULL){
clean_tail = clean_tail->next;
}
clean_tail->next = head_request_changes;
}
head_request_changes = NULL;
}


void clean_all_hard()
{
return generic_clean_head(clean_list);
}


/*
* Get number of current accounts.
*/
Expand Down
Loading
Loading