Skip to content

Commit

Permalink
cfgutils Add functions for checking if a route exists
Browse files Browse the repository at this point in the history
Adding check_route_exists() and route_if_exists() functions.
  • Loading branch information
oej committed Mar 2, 2013
1 parent 0d69ffe commit c2c4c39
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions modules/cfgutils/cfgutils.c
@@ -1,6 +1,7 @@
/*
* $Id$
*
* Copyright (C) 2012 Edvina AB
* Copyright (C) 2007 1&1 Internet AG
* Copyright (C) 2007 BASIS AudioNet GmbH
* Copyright (C) 2004 FhG
Expand Down Expand Up @@ -70,6 +71,7 @@
#include "../../globals.h"
#include "../../hashes.h"
#include "../../locking.h"
#include "../../route.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
Expand All @@ -91,6 +93,8 @@ static int dbg_pkg_status(struct sip_msg*, char*,char*);
static int dbg_shm_status(struct sip_msg*, char*,char*);
static int dbg_pkg_summary(struct sip_msg*, char*,char*);
static int dbg_shm_summary(struct sip_msg*, char*,char*);
static int route_exists(struct sip_msg*, char*);
static int check_route_exists(struct sip_msg*, char*);

static int set_gflag(struct sip_msg*, char *, char *);
static int reset_gflag(struct sip_msg*, char *, char *);
Expand Down Expand Up @@ -178,6 +182,10 @@ static cmd_export_t cmds[]={
ANY_ROUTE},
{"core_hash", (cmd_function)w_core_hash, 3, fixup_core_hash, 0,
ANY_ROUTE},
{"check_route_exists", (cmd_function)check_route_exists, 1, 0, 0,
ANY_ROUTE},
{"route_if_exists", (cmd_function)route_exists, 1, 0, 0,
ANY_ROUTE},
{"bind_cfgutils", (cmd_function)bind_cfgutils, 0,
0, 0, 0},
{0, 0, 0, 0, 0, 0}
Expand Down Expand Up @@ -737,6 +745,32 @@ static int cfg_unlock(struct sip_msg *msg, char *key, char *s2)
return cfg_lock_wrapper(msg, (gparam_p)key, 1);
}

/*! Check if a route block exists - only request routes
*/
static int check_route_exists(struct sip_msg *msg, char *route)
{
if (route_lookup(&main_rt, route))
return 1;
return 0;
}

/*! Run a request route block if it exists
*/
static int route_exists(struct sip_msg *msg, char *route)
{
struct run_act_ctx ctx;
int newroute, backup_rt;

if (!(newroute = route_lookup(&main_rt, route))) {
return 0;
}
backup_rt = get_route_type();
set_route_type(REQUEST_ROUTE);
init_run_actions_ctx(&ctx);
run_top_route(main_rt.rlist[newroute], msg, 0);
set_route_type(backup_rt);
return 0;
}

static int mod_init(void)
{
Expand Down

0 comments on commit c2c4c39

Please sign in to comment.