cpl_sig.c

Go to the documentation of this file.
00001 /*
00002  * $Id: cpl_sig.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00023 
00024 #include "../../action.h"
00025 #include "../../dset.h"
00026 #include "../tm/tm_load.h"
00027 #include "loc_set.h"
00028 #include "cpl_sig.h"
00029 #include "cpl_env.h"
00030 
00031 
00032 /* forwards the msg to the given location set; if flags has set the
00033  * CPL_PROXY_DONE, all locations will be added as branches, otherwise, the 
00034  * first one will set as RURI (this is ha case when this is the first proxy 
00035  * of the message)
00036  * The given list of location will be freed, returning 0 instead.
00037  * Returns:  0 - OK
00038  *          -1 - error */
00039 int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
00040                                        unsigned char flag)
00041 {
00042    struct location *foo;
00043    struct action act;
00044    int bflags;
00045 
00046    if (!*locs) {
00047       LM_ERR("empty loc set!!\n");
00048       goto error;
00049    }
00050 
00051    /* if it's the first time when this sip_msg is proxied, use the first addr
00052     * in loc_set to rewrite the RURI */
00053    if (!(flag&CPL_PROXY_DONE)) {
00054       LM_DBG("rewriting Request-URI with <%s>\n",(*locs)->addr.uri.s);
00055       /* build a new action for setting the URI */
00056       act.type = SET_URI_T;
00057       act.elem[0].type = STRING_ST;
00058       act.elem[0].u.string = (*locs)->addr.uri.s;
00059       act.next = 0;
00060       /* push the action */
00061       if (do_action(&act, msg) < 0) {
00062          LM_ERR("do_action failed\n");
00063          goto error;
00064       }
00065       /* build a new action for setting the DSTURI */
00066       if((*locs)->addr.received.s && (*locs)->addr.received.len) {
00067          LM_DBG("rewriting Destination URI "
00068             "with <%s>\n",(*locs)->addr.received.s);
00069          act.type = SET_DSTURI_T;
00070          act.elem[0].type = STRING_ST;
00071          act.elem[0].u.s = (*locs)->addr.received;
00072          act.next = 0;
00073          /* push the action */
00074          if (do_action(&act, msg) < 0) {
00075             LM_ERR("do_action failed\n");
00076             goto error;
00077          }
00078       }
00079       /* is the location NATED? */
00080       if ((*locs)->flags&CPL_LOC_NATED)
00081          setbflag( 0, cpl_fct.ulb.nat_flag );
00082       /* free the location and point to the next one */
00083       foo = (*locs)->next;
00084       free_location( *locs );
00085       *locs = foo;
00086    }
00087 
00088    /* add the rest of the locations as branches */
00089    while(*locs) {
00090       bflags = ((*locs)->flags&CPL_LOC_NATED) ? cpl_fct.ulb.nat_flag : 0 ;
00091       LM_DBG("appending branch <%.*s>, flags %d\n",
00092          (*locs)->addr.uri.len, (*locs)->addr.uri.s, bflags);
00093       if(append_branch(msg, &(*locs)->addr.uri, &(*locs)->addr.received,0,
00094       Q_UNSPECIFIED, bflags, 0)==-1){
00095          LM_ERR("failed when appending branch <%s>\n",(*locs)->addr.uri.s);
00096          goto error;
00097       }
00098       /* free the location and point to the next one */
00099       foo = (*locs)->next;
00100       free_location( *locs );
00101       *locs = foo;
00102    }
00103 
00104    /* run what proxy route is set */
00105    if (cpl_env.proxy_route) {
00106       /* do not alter route type - it might be REQUEST or FAILURE */
00107       run_top_route( rlist[cpl_env.proxy_route], msg);
00108    }
00109 
00110    /* do t_forward */
00111    if (cpl_fct.tmb.t_relay(msg, 0, 0, 0, 0, 0, 0)==-1) {
00112       LM_ERR("t_relay failed !\n");
00113       goto error;
00114    }
00115 
00116    return 0;
00117 error:
00118    return -1;
00119 }
00120 
00121 

Generated on Mon May 21 18:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6