Skip to content

Commit

Permalink
tm: export transaction context operations
Browse files Browse the repository at this point in the history
All transactions may now hold additional context-specific data.
Data can be stored/fetched using the newly added functions in tm_binds.
  • Loading branch information
liviuchircu committed Oct 30, 2014
1 parent 7db8a2e commit 85c8dab
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/tm/h_table.c
Expand Up @@ -276,7 +276,7 @@ struct cell* build_cell( struct sip_msg* p_msg )
unsigned short set;

/* allocs a new cell */
new_cell = (struct cell*)shm_malloc( sizeof( struct cell ) );
new_cell = (struct cell*)shm_malloc(sizeof(struct cell) + context_size(CONTEXT_TRAN));
if ( !new_cell ) {
ser_error=E_OUT_OF_MEM;
return NULL;
Expand Down
70 changes: 70 additions & 0 deletions modules/tm/t_ctx.c
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2014 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2014-10-30 initial version (liviu)
*/

#include "t_funcs.h"

int t_ctx_register_int(void)
{
return __context_register_int(CONTEXT_TRAN);
}

int t_ctx_register_str(void)
{
return __context_register_str(CONTEXT_TRAN);
}

int t_ctx_register_ptr(void)
{
return __context_register_ptr(CONTEXT_TRAN);
}

void t_ctx_put_int(struct cell *t, int pos, int data)
{
__context_put_int(CONTEXT_TRAN, context_of(t), pos, data);
}

void t_ctx_put_str(struct cell *t, int pos, str *data)
{
__context_put_str(CONTEXT_TRAN, context_of(t), pos, data);
}

void t_ctx_put_ptr(struct cell *t, int pos, void *data)
{
__context_put_ptr(CONTEXT_TRAN, context_of(t), pos, data);
}

int t_ctx_get_int(struct cell *t, int pos)
{
return __context_get_int(CONTEXT_TRAN, context_of(t), pos);
}

str *t_ctx_get_str(struct cell *t, int pos)
{
return __context_get_str(CONTEXT_TRAN, context_of(t), pos);
}

void *t_ctx_get_ptr(struct cell *t, int pos)
{
return __context_get_ptr(CONTEXT_TRAN, context_of(t), pos);
}
50 changes: 50 additions & 0 deletions modules/tm/t_ctx.h
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2014 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2014-10-30 initial version (liviu)
*/

#ifndef __T_CTX_H
#define __T_CTX_H

typedef int (*t_ctx_register_int_f)(void);
typedef int (*t_ctx_register_str_f)(void);
typedef int (*t_ctx_register_ptr_f)(void);
typedef void (*t_ctx_put_int_f)(struct cell *t, int pos, int data);
typedef void (*t_ctx_put_str_f)(struct cell *t, int pos, str *data);
typedef void (*t_ctx_put_ptr_f)(struct cell *t, int pos, void *data);
typedef int (*t_ctx_get_int_f)(struct cell *t, int pos);
typedef str *(*t_ctx_get_str_f)(struct cell *t, int pos);
typedef void *(*t_ctx_get_ptr_f)(struct cell *t, int pos);

int t_ctx_register_int(void);
int t_ctx_register_str(void);
int t_ctx_register_ptr(void);

void t_ctx_put_int(struct cell *t, int pos, int data);
void t_ctx_put_str(struct cell *t, int pos, str *data);
void t_ctx_put_ptr(struct cell *t, int pos, void *data);

int t_ctx_get_int(struct cell *t, int pos);
str *t_ctx_get_str(struct cell *t, int pos);
void *t_ctx_get_ptr(struct cell *t, int pos);

#endif /* __T_CTX_H */
14 changes: 14 additions & 0 deletions modules/tm/tm.c
Expand Up @@ -77,6 +77,7 @@
#include "t_fifo.h"
#include "mi.h"
#include "tm_load.h"
#include "t_ctx.h"


/* item functions */
Expand Down Expand Up @@ -653,6 +654,19 @@ int load_tm( struct tm_binds *tmb)
tmb->setlocalTholder = setlocalTholder;
tmb->get_branch_index = get_branch_index;

/* tm context functions */
tmb->t_ctx_register_int = t_ctx_register_int;
tmb->t_ctx_register_str = t_ctx_register_str;
tmb->t_ctx_register_ptr = t_ctx_register_ptr;

tmb->t_ctx_put_int = t_ctx_put_int;
tmb->t_ctx_put_str = t_ctx_put_str;
tmb->t_ctx_put_ptr = t_ctx_put_ptr;

tmb->t_ctx_get_int = t_ctx_get_int;
tmb->t_ctx_get_str = t_ctx_get_str;
tmb->t_ctx_get_ptr = t_ctx_get_ptr;

return 1;
}

Expand Down
13 changes: 13 additions & 0 deletions modules/tm/tm_load.h
Expand Up @@ -44,6 +44,7 @@
#include "t_cancel.h"
#include "dlg.h"
#include "h_table.h"
#include "t_ctx.h"


struct tm_binds {
Expand Down Expand Up @@ -79,6 +80,18 @@ struct tm_binds {
setkr_f t_setkr;
set_localT_holder_f setlocalTholder;
tgetbranch_f get_branch_index;

t_ctx_register_int_f t_ctx_register_int;
t_ctx_register_str_f t_ctx_register_str;
t_ctx_register_ptr_f t_ctx_register_ptr;

t_ctx_put_int_f t_ctx_put_int;
t_ctx_put_str_f t_ctx_put_str;
t_ctx_put_ptr_f t_ctx_put_ptr;

t_ctx_get_int_f t_ctx_get_int;
t_ctx_get_str_f t_ctx_get_str;
t_ctx_get_ptr_f t_ctx_get_ptr;
};


Expand Down

0 comments on commit 85c8dab

Please sign in to comment.