Skip to content

Commit

Permalink
Fixed using internal ID for DB updated operations.
Browse files Browse the repository at this point in the history
Use the DB ID when doing updates instead of the internal ID.

(cherry picked from commit d871bc9)
  • Loading branch information
bogdan-iancu committed May 2, 2014
1 parent 8a28a98 commit d41d8df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
21 changes: 12 additions & 9 deletions modules/drouting/drouting.c
Expand Up @@ -479,6 +479,7 @@ static void dr_prob_handler(unsigned int ticks, void* param)

static void dr_state_flusher(void)
{
static db_ps_t cr_ps=NULL, gw_ps=NULL;
pgw_t *gw;
pcr_t *cr;
db_key_t key_cmp;
Expand All @@ -490,7 +491,7 @@ static void dr_state_flusher(void)
if (!rdata || !(*rdata))
return;

val_cmp.type = DB_INT;
val_cmp.type = DB_STR;
val_cmp.nul = 0;

val_set.type = DB_INT;
Expand All @@ -501,7 +502,7 @@ static void dr_state_flusher(void)
LM_ERR("cannot select table \"%.*s\"\n", drd_table.len, drd_table.s);
return;
}
key_cmp = &id_drd_col;
key_cmp = &gwid_drd_col;
key_set = &state_drd_col;

/* iterate the gateways */
Expand All @@ -511,13 +512,14 @@ static void dr_state_flusher(void)
continue;

/* populate the update */
val_cmp.val.int_val = gw->_id;
val_cmp.val.str_val = gw->id;
val_set.val.int_val = (gw->flags&DR_DST_STAT_DSBL_FLAG) ? ((gw->flags&DR_DST_STAT_NOEN_FLAG)?1:2) : (0);

/* update the state of this gateway */
LM_DBG("updating the state of gw %d (%.*s) to %d\n",
gw->_id, gw->id.len, gw->id.s, val_set.val.int_val);
LM_DBG("updating the state of gw <%.*s> to %d\n",
gw->id.len, gw->id.s, val_set.val.int_val);

CON_PS_REFERENCE(db_hdl) = gw_ps;
if ( dr_dbf.update(db_hdl,&key_cmp,0,&val_cmp,&key_set,&val_set,1,1)<0 ) {
LM_ERR("DB update failed\n");
} else {
Expand All @@ -530,7 +532,7 @@ static void dr_state_flusher(void)
LM_ERR("cannot select table \"%.*s\"\n", drc_table.len, drc_table.s);
return;
}
key_cmp = &id_drc_col;
key_cmp = &cid_drc_col;
key_set = &state_drc_col;

/* iterate the carriers */
Expand All @@ -540,13 +542,14 @@ static void dr_state_flusher(void)
continue;

/* populate the update */
val_cmp.val.int_val = cr->db_id;
val_cmp.val.str_val = cr->id;
val_set.val.int_val = (cr->flags&DR_CR_FLAG_IS_OFF) ? 1 : 0;

/* update the state of this carrier */
LM_DBG("updating the state of cr %d (%.*s) to %d\n",
cr->db_id, cr->id.len, cr->id.s, val_set.val.int_val);
LM_DBG("updating the state of cr <%.*s> to %d\n",
cr->id.len, cr->id.s, val_set.val.int_val);

CON_PS_REFERENCE(db_hdl) = cr_ps;
if ( dr_dbf.update(db_hdl,&key_cmp,0,&val_cmp,&key_set,&val_set,1,1)<0 ) {
LM_ERR("DB update failed\n");
} else {
Expand Down
8 changes: 3 additions & 5 deletions modules/drouting/prefix_tree.h
Expand Up @@ -66,9 +66,9 @@ do {\

/* list of PSTN gw */
typedef struct pgw_ {
/* internal numerical ID */
/* internal numerical ID, not DB related */
unsigned int _id;
/* GW ID*/
/* GW ID from DB */
str id;
/* type of gateway */
int type;
Expand Down Expand Up @@ -105,9 +105,7 @@ typedef struct pgw_list_ {

/* list of carriers */
struct pcr_ {
/* id matching the one in db */
unsigned int db_id;
/* carrier ID/name */
/* carrier ID/name from DB */
str id;
/* flags */
unsigned int flags;
Expand Down
3 changes: 1 addition & 2 deletions modules/drouting/routing.c
Expand Up @@ -214,7 +214,7 @@ int parse_destination_list(rt_data_t* rd, char *dstlist,
}


int add_carrier(int db_id, char *id, int flags, char *gwlist, char *attrs,
int add_carrier(char *id, int flags, char *gwlist, char *attrs,
int state, rt_data_t *rd)
{
pcr_t *cr = NULL;
Expand Down Expand Up @@ -247,7 +247,6 @@ int add_carrier(int db_id, char *id, int flags, char *gwlist, char *attrs,
}

/* copy integer fields */
cr->db_id = db_id;
cr->flags = flags;

/* set state */
Expand Down
1 change: 0 additions & 1 deletion modules/drouting/routing.h
Expand Up @@ -80,7 +80,6 @@ build_rt_data( void );

int
add_carrier(
int db_id,
char *id,
int flags,
char *gwlist,
Expand Down

0 comments on commit d41d8df

Please sign in to comment.