path_mod.c

Go to the documentation of this file.
00001 /*
00002  * $Id: path_mod.c 4934 2008-09-17 11:34:26Z henningw $ 
00003  *
00004  * Path handling for intermediate proxies
00005  *
00006  * Copyright (C) 2006 Inode GmbH (Andreas Granig <andreas.granig@inode.info>)
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 /*! \file
00027  * \brief Path :: Core
00028  *
00029  * \ingroup path
00030  * - Module: path
00031  */
00032 
00033 /*! \defgroup path Path:: Handling of "path" header for intermediate proxies
00034  * This module is designed to be used at intermediate sip proxies
00035  * like loadbalancers in front of registrars and proxies. It
00036  * provides functions for inserting a Path header including a
00037  * parameter for passing forward the received-URI of a
00038  * registration to the next hop. It also provides a mechanism for
00039  * evaluating this parameter in subsequent requests and to set the
00040  * destination URI according to it.
00041  *
00042  * - No developer API
00043  * - No MI functions
00044  */
00045 
00046 
00047 
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <string.h>
00051 
00052 #include "../../sr_module.h"
00053 #include "../../mem/mem.h"
00054 #include "../../mod_fix.h"
00055 #include "../rr/api.h"
00056 
00057 #include "path.h"
00058 #include "path_mod.h"
00059 
00060 MODULE_VERSION
00061 
00062 
00063 /*! \brief If received-param of current Route uri should be used
00064  * as dst-uri. */
00065 int use_received = 0;
00066 
00067 /*! \brief
00068  * Module initialization function prototype
00069  */
00070 static int mod_init(void);
00071 
00072 /*! \brief
00073  * rr callback API
00074  */
00075 struct rr_binds path_rrb;
00076 
00077 
00078 /*! \brief
00079  * Exported functions
00080  */
00081 static cmd_export_t cmds[] = {
00082    { "add_path",          (cmd_function)add_path,              0,
00083          0,              0,  REQUEST_ROUTE },
00084    { "add_path",          (cmd_function)add_path_usr,          1,
00085          fixup_str_null, 0, REQUEST_ROUTE },
00086    { "add_path_received", (cmd_function)add_path_received,     0,
00087          0,              0, REQUEST_ROUTE },
00088    { "add_path_received", (cmd_function)add_path_received_usr, 1,
00089          fixup_str_null, 0, REQUEST_ROUTE },
00090    { 0, 0, 0, 0, 0, 0 }
00091 };
00092 
00093 
00094 /*! \brief
00095  * Exported parameters
00096  */
00097 static param_export_t params[] = {
00098    {"use_received", INT_PARAM, &use_received },
00099    { 0, 0, 0 }
00100 };
00101 
00102 
00103 /*! \brief
00104  * Module interface
00105  */
00106 struct module_exports exports = {
00107    "path", 
00108    DEFAULT_DLFLAGS, /* dlopen flags */
00109    cmds,       /* Exported functions */
00110    params,     /* Exported parameters */
00111    0,          /* exported statistics */
00112    0,          /* exported MI functions */
00113    0,          /* exported pseudo-variables */
00114    0,          /* extra processes */
00115    mod_init,   /* module initialization function */
00116    0,          /* response function */
00117    0,    /* destroy function */
00118    0           /* child initialization function */
00119 };
00120 
00121 
00122 static int mod_init(void)
00123 {
00124    if (use_received) {
00125       if (load_rr_api(&path_rrb) != 0) {
00126          LM_ERR("failed to load rr-API\n");
00127          return -1;
00128       }
00129       if (path_rrb.register_rrcb(path_rr_callback, 0) != 0) {
00130          LM_ERR("failed to register rr callback\n");
00131          return -1;
00132       }
00133    }
00134    
00135    return 0;
00136 }

Generated on Thu May 24 02:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6