rtpproxy_stream.c

Go to the documentation of this file.
00001 /* $Id: rtpproxy_stream.c,v 1.2 2008/11/04 22:28:04 sobomax Exp $
00002  *
00003  * Copyright (C) 2008 Sippy Software, Inc., http://www.sippysoft.com
00004  *
00005  * This file is part of ser, a free SIP server.
00006  *
00007  * ser is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version
00011  *
00012  * For a license to use the ser software under conditions
00013  * other than those described here, or to purchase support for this
00014  * software, please contact iptel.org by e-mail at the following addresses:
00015  *    info@iptel.org
00016  *
00017  * ser is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 #include <stdio.h>
00029 #include <sys/uio.h>
00030 
00031 #include "../../ip_addr.h"
00032 #include "../../parser/msg_parser.h"
00033 #include "../../sr_module.h"
00034 #include "../../ut.h"
00035 #include "nathelper.h"
00036 #include "nhelpr_funcs.h"
00037 
00038 int
00039 fixup_var_str_int(void **param, int param_no)
00040 {
00041     unsigned long go_to;
00042     int ret;
00043     pv_elem_t *model;
00044     str s;
00045 
00046     if (param_no == 1) {
00047         model = NULL;
00048         s.s = (char *)(*param);
00049         s.len = strlen(s.s);
00050         if (pv_parse_format(&s, &model) < 0) {
00051             LM_ERR("wrong format[%s]!\n", (char *)(*param));
00052             return E_UNSPEC;
00053         }
00054         if (model == NULL) {
00055             LM_ERR("empty parameter!\n");
00056             return E_UNSPEC;
00057         }
00058         *param = (void *)model;
00059     } else if (param_no == 2) {
00060         go_to = str2s(*param, strlen(*param), &ret);
00061         if (ret == 0) {
00062             pkg_free(*param);
00063             *param = (void *)go_to;
00064         } else {
00065             LM_ERR("bad number <%s>\n", (char *)(*param));
00066             return E_CFG;
00067         }
00068     }
00069     return 0;
00070 }
00071 
00072 static int
00073 rtpproxy_stream(struct sip_msg* msg, str *pname, int count, int stream2uac)
00074 {
00075     int nitems;
00076     str callid, from_tag, to_tag;
00077     struct rtpp_node *node;
00078     char cbuf[16];
00079     struct iovec v[] = {
00080         {NULL,        0},
00081         {cbuf,        0}, /* 1 P<count> */
00082         {" ",         1},
00083         {NULL,        0}, /* 3 callid */
00084         {" ",         1},
00085         {NULL,        0}, /* 5 pname */
00086         {" session ", 9},
00087         {NULL,        0}, /* 7 from tag */
00088         {";1 ",       3},
00089         {NULL,        0}, /* 9 to tag */
00090         {";1",        2}
00091     };
00092 
00093     if (get_callid(msg, &callid) == -1 || callid.len == 0) {
00094         LM_ERR("can't get Call-Id field\n");
00095         return -1;
00096     }
00097     if (get_to_tag(msg, &to_tag) == -1) {
00098         LM_ERR("can't get To tag\n");
00099         return -1;
00100     }
00101     if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) {
00102         LM_ERR("can't get From tag\n");
00103         return -1;
00104     }
00105     v[1].iov_len = sprintf(cbuf, "P%d", count);
00106     STR2IOVEC(callid, v[3]);
00107     STR2IOVEC(*pname, v[5]);
00108     node = select_rtpp_node(callid, 1);
00109     if (!node) {
00110         LM_ERR("no available proxies\n");
00111         return -1;
00112     }
00113     if (node->rn_ptl_supported == 0) {
00114         LM_ERR("required functionality is not "
00115           "supported by the version of the RTPproxy running on the selected "
00116           "node.  Please upgrade the RTPproxy and try again.\n");
00117         return -1;
00118     }
00119     nitems = 11;
00120     if (stream2uac == 0) {
00121         if (to_tag.len == 0)
00122             return -1;
00123         STR2IOVEC(to_tag, v[7]);
00124         STR2IOVEC(from_tag, v[9]);
00125     } else {
00126         STR2IOVEC(from_tag, v[7]);
00127         STR2IOVEC(to_tag, v[9]);
00128         if (to_tag.len <= 0)
00129             nitems -= 2;
00130     }
00131     send_rtpp_command(node, v, nitems);
00132 
00133     return 1;
00134 }
00135 
00136 static int
00137 rtpproxy_stream2_f(struct sip_msg *msg, char *str1, int count, int stream2uac)
00138 {
00139     str pname;
00140 
00141     if (str1 == NULL || pv_printf_s(msg, (pv_elem_p)str1, &pname) != 0)
00142    return -1;
00143     return rtpproxy_stream(msg, &pname, count, stream2uac);
00144 }
00145 
00146 int
00147 rtpproxy_stream2uac2_f(struct sip_msg* msg, char* str1, char* str2)
00148 {
00149 
00150     return rtpproxy_stream2_f(msg, str1, (int)(long)str2, 1);
00151 }
00152 
00153 int
00154 rtpproxy_stream2uas2_f(struct sip_msg* msg, char* str1, char* str2)
00155 {
00156 
00157     return rtpproxy_stream2_f(msg, str1, (int)(long)str2, 0);
00158 }
00159 
00160 static int
00161 rtpproxy_stop_stream(struct sip_msg* msg, int stream2uac)
00162 {
00163     int nitems;
00164     str callid, from_tag, to_tag;
00165     struct rtpp_node *node;
00166     struct iovec v[] = {
00167         {NULL,        0},
00168         {"S",         1}, /* 1 */
00169         {" ",         1},
00170         {NULL,        0}, /* 3 callid */
00171         {" ",         1},
00172         {NULL,        0}, /* 5 from tag */
00173         {";1 ",       3},
00174         {NULL,        0}, /* 7 to tag */
00175         {";1",        2}
00176     };
00177 
00178     if (get_callid(msg, &callid) == -1 || callid.len == 0) {
00179         LM_ERR("can't get Call-Id field\n");
00180         return -1;
00181     }
00182     if (get_to_tag(msg, &to_tag) == -1) {
00183         LM_ERR("can't get To tag\n");
00184         return -1;
00185     }
00186     if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) {
00187         LM_ERR("can't get From tag\n");
00188         return -1;
00189     }
00190     STR2IOVEC(callid, v[3]);
00191     node = select_rtpp_node(callid, 1);
00192     if (!node) {
00193         LM_ERR("no available proxies\n");
00194         return -1;
00195     }
00196     if (node->rn_ptl_supported == 0) {
00197         LM_ERR("required functionality is not "
00198           "supported by the version of the RTPproxy running on the selected "
00199           "node.  Please upgrade the RTPproxy and try again.\n");
00200         return -1;
00201     }
00202     nitems = 9;
00203     if (stream2uac == 0) {
00204         if (to_tag.len == 0)
00205             return -1;
00206         STR2IOVEC(to_tag, v[5]);
00207         STR2IOVEC(from_tag, v[7]);
00208     } else {
00209         STR2IOVEC(from_tag, v[5]);
00210         STR2IOVEC(to_tag, v[7]);
00211         if (to_tag.len <= 0)
00212             nitems -= 2;
00213     }
00214     send_rtpp_command(node, v, nitems);
00215 
00216     return 1;
00217 }
00218 
00219 int
00220 rtpproxy_stop_stream2uac2_f(struct sip_msg* msg, char* str1, char* str2)
00221 {
00222 
00223     return rtpproxy_stop_stream(msg, 1);
00224 }
00225 
00226 int
00227 rtpproxy_stop_stream2uas2_f(struct sip_msg* msg, char* str1, char* str2)
00228 {
00229 
00230     return rtpproxy_stop_stream(msg, 0);
00231 }

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