qos_mi.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2007 SOMA Networks, Inc.
00005  * Written by Ovidiu Sas (osas)
00006  *
00007  * This file is part of Kamailio, a free SIP server.
00008  *
00009  * Kamailio is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * Kamailio is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022  * USA
00023  *
00024  * History:
00025  * --------
00026  * 2007-07-16 initial version (osas)
00027  */
00028 
00029 
00030 #include "../../ut.h"
00031 #include "../../dprint.h"
00032 #include "../../mi/mi.h"
00033 #include "qos_handlers.h"
00034 #include "qos_ctx_helpers.h"
00035 
00036 
00037 int add_mi_sdp_payload_nodes(struct mi_node* node, int index, sdp_payload_attr_t* sdp_payload)
00038 {
00039    struct mi_node* node1;
00040    struct mi_attr* attr;
00041    char* p;
00042    int len;
00043 
00044    p = int2str((unsigned long)(index), &len);
00045    node1 = add_mi_node_child( node, MI_DUP_VALUE, "payload", 7, p, len);
00046    if (node1==NULL)
00047       return 1;
00048 
00049    attr = add_mi_attr(node1, MI_DUP_VALUE, "rtpmap", 6, sdp_payload->rtp_payload.s, sdp_payload->rtp_payload.len);
00050    if (attr==NULL)
00051       return 1;
00052 
00053    if (sdp_payload->rtp_enc.s!=NULL && sdp_payload->rtp_enc.len!=0) {
00054       attr = add_mi_attr(node1, MI_DUP_VALUE, "codec", 5, sdp_payload->rtp_enc.s, sdp_payload->rtp_enc.len);
00055       if(attr == NULL)
00056          return 1;
00057    }
00058 
00059    if (sdp_payload->sendrecv_mode.s!=NULL && sdp_payload->sendrecv_mode.len!=0) {
00060       attr = add_mi_attr(node1, MI_DUP_VALUE, "sendrecv", 8, sdp_payload->sendrecv_mode.s, sdp_payload->sendrecv_mode.len);
00061       if(attr == NULL)
00062          return 1;
00063    }
00064 
00065    if (sdp_payload->ptime.s!=NULL && sdp_payload->ptime.len!=0) {
00066       attr = add_mi_attr(node1, MI_DUP_VALUE, "ptime", 5, sdp_payload->ptime.s, sdp_payload->ptime.len);
00067       if(attr == NULL)
00068          return 1;
00069    }
00070 
00071    return 0;
00072 }
00073 
00074 int add_mi_stream_nodes(struct mi_node* node, int index, sdp_stream_cell_t* stream)
00075 {
00076    struct mi_node* node1;
00077    struct mi_attr* attr;
00078    sdp_payload_attr_t* sdp_payload;
00079    char* p;
00080    int i, len;
00081 
00082    p = int2str((unsigned long)(index), &len);
00083    node1 = add_mi_node_child( node, MI_DUP_VALUE, "stream", 6, p, len);
00084    if (node1==NULL)
00085       return 1;
00086    
00087    attr = add_mi_attr(node1, MI_DUP_VALUE, "media", 5, stream->media.s, stream->media.len);
00088    if(attr == NULL) 
00089       return 1; 
00090 
00091    attr = add_mi_attr(node1, MI_DUP_VALUE, "IP", 2, stream->ip_addr.s, stream->ip_addr.len);
00092    if(attr == NULL) 
00093       return 1;
00094 
00095    attr = add_mi_attr(node1, MI_DUP_VALUE, "port", 4, stream->port.s, stream->port.len);
00096    if(attr == NULL)
00097       return 1;
00098 
00099    attr = add_mi_attr(node1, MI_DUP_VALUE, "transport", 9, stream->transport.s, stream->transport.len);
00100    if(attr == NULL)
00101       return 1;
00102 
00103    p = int2str((unsigned long)(stream->payloads_num), &len);
00104    attr = add_mi_attr(node1, MI_DUP_VALUE, "payloads_num", 12, p, len);
00105    if(attr == NULL)
00106       return 1;
00107 
00108    sdp_payload = stream->payload_attr;
00109    for(i=stream->payloads_num-1;i>=0;i--){
00110       if (!sdp_payload) {
00111          LM_ERR("got NULL sdp_payload\n");
00112          return 1;
00113       }
00114       if (0!=add_mi_sdp_payload_nodes(node1, i, sdp_payload)){
00115          return 1;
00116       }
00117       sdp_payload = sdp_payload->next;
00118    }
00119 
00120    return 0;
00121 }
00122 
00123 int add_mi_session_nodes(struct mi_node* node, int index, sdp_session_cell_t* session)
00124 {
00125    struct mi_node* node1;
00126    struct mi_attr* attr;
00127    sdp_stream_cell_t* stream;
00128    char* p;
00129    int i, len;
00130 
00131    switch (index) {
00132       case 0:
00133          node1 = add_mi_node_child( node, MI_DUP_VALUE, "session", 7, "caller", 6);
00134          if (node1==NULL)
00135             return 1;
00136          break;
00137       case 1:
00138          node1 = add_mi_node_child( node, MI_DUP_VALUE, "session", 7, "callee", 6);
00139          if (node1==NULL)
00140             return 1;
00141          break;
00142       default:
00143          return 1;
00144    }
00145 
00146    attr = add_mi_attr(node1, MI_DUP_VALUE, "cnt_disp", 8, session->cnt_disp.s, session->cnt_disp.len);
00147    if(attr == NULL)
00148       return 1;
00149 
00150    attr = add_mi_attr(node1, MI_DUP_VALUE, "bw_type", 7, session->bw_type.s, session->bw_type.len);
00151    if(attr == NULL)
00152       return 1;
00153 
00154    attr = add_mi_attr(node1, MI_DUP_VALUE, "bw_width", 8, session->bw_width.s, session->bw_width.len);
00155    if(attr == NULL)
00156       return 1;
00157 
00158    p = int2str((unsigned long)(session->streams_num), &len); 
00159    attr = add_mi_attr(node1, MI_DUP_VALUE, "streams", 7, p, len);
00160    if(attr == NULL)
00161       return 1;
00162 
00163    stream = session->streams;
00164    for(i=session->streams_num-1;i>=0;i--){
00165       if (!stream) {
00166          LM_ERR("got NULL stream\n");
00167          return 1;
00168       }
00169       if (0!=add_mi_stream_nodes(node1, i, stream)){
00170          return 1;
00171       }
00172       stream = stream->next;
00173    }
00174 
00175    return 0;
00176 }
00177 
00178 int add_mi_sdp_nodes(struct mi_node* node, qos_sdp_t* qos_sdp)
00179 {
00180    struct mi_node* node1;
00181    struct mi_attr* attr;
00182    char* p;
00183    int i, len;
00184    sdp_session_cell_t* session;
00185 
00186    if ( qos_sdp->prev != NULL ) LM_ERR("got qos_sdp->prev=%p\n", qos_sdp->prev);
00187 
00188    while (qos_sdp) {
00189       node1 = add_mi_node_child( node, MI_DUP_VALUE, "sdp", 3, NULL, 0);
00190       if (node1==NULL)
00191          return 1;
00192 
00193       p = int2str((unsigned long)(qos_sdp->method_dir), &len);
00194       attr = add_mi_attr(node1, MI_DUP_VALUE, "m_dir", 5, p, len);
00195       if(attr == NULL)
00196          return 1;
00197 
00198       p = int2str((unsigned long)(qos_sdp->method_id), &len);
00199       attr = add_mi_attr(node1, MI_DUP_VALUE, "m_id", 4, p, len);
00200       if(attr == NULL)
00201          return 1;
00202 
00203       attr = add_mi_attr(node1, MI_DUP_VALUE, "method", 6, qos_sdp->method.s, qos_sdp->method.len);
00204       if(attr == NULL)
00205          return 1;
00206 
00207       attr = add_mi_attr(node1, MI_DUP_VALUE, "cseq", 4, qos_sdp->cseq.s, qos_sdp->cseq.len);
00208       if(attr == NULL)
00209          return 1;
00210 
00211       p = int2str((unsigned long)(qos_sdp->negotiation), &len);
00212       attr = add_mi_attr(node1, MI_DUP_VALUE, "negotiation", 11, p, len);
00213       if(attr == NULL)
00214          return 1;
00215 
00216       for (i=1;i>=0;i--){
00217          session = qos_sdp->sdp_session[i];
00218          if (session) {
00219             if (0 != add_mi_session_nodes(node1, i, session))
00220                return 1;
00221          }
00222       }
00223 
00224       qos_sdp = qos_sdp->next;
00225    }
00226    return 0;
00227 }
00228 
00229 void qos_dialog_mi_context_CB(struct dlg_cell* did, int type, struct dlg_cb_params * params)
00230 {
00231    struct mi_node* parent_node = (struct mi_node*)(params->dlg_data);
00232    struct mi_node* node;
00233    qos_ctx_t* qos_ctx = (qos_ctx_t*)*(params->param);
00234    qos_sdp_t* qos_sdp;
00235 
00236    qos_sdp = qos_ctx->pending_sdp;
00237    if (qos_sdp) {
00238       node = add_mi_node_child(parent_node, MI_DUP_VALUE, "qos", 3, "pending_sdp", 11);
00239       if (node==NULL) {
00240          LM_ERR("oom\n");
00241          return;
00242       }
00243 
00244       if (0 != add_mi_sdp_nodes( node, qos_sdp))
00245          return;
00246    }
00247 
00248 
00249    qos_sdp = qos_ctx->negotiated_sdp;
00250    if (qos_sdp) {
00251       node = add_mi_node_child(parent_node, MI_DUP_VALUE, "qos", 3, "negotiated_sdp", 14);
00252       if (node==NULL) {
00253          LM_ERR("oom\n");
00254          return;
00255       }
00256 
00257       if (0 != add_mi_sdp_nodes( node, qos_sdp))
00258          return;
00259    }
00260 
00261 
00262    return;
00263 }
00264 

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