third_party_reg.c

Go to the documentation of this file.
00001 /*
00002  * $Id: third_party_reg.c 502 2007-11-30 12:32:57Z placido $
00003  *  
00004  * Copyright (C) 2004-2006 FhG Fokus
00005  *
00006  * This file is part of Open IMS Core - an open source IMS CSCFs & HSS
00007  * implementation
00008  *
00009  * Open IMS Core is free software; you can redistribute it and/or modify
00010  * it 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  * For a license to use the Open IMS Core software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact Fraunhofer FOKUS by e-mail at the following
00017  * addresses:
00018  *     info@open-ims.org
00019  *
00020  * Open IMS Core is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  * 
00025  * It has to be noted that this Open Source IMS Core System is not 
00026  * intended to become or act as a product in a commercial context! Its 
00027  * sole purpose is to provide an IMS core reference implementation for 
00028  * IMS technology testing and IMS application prototyping for research 
00029  * purposes, typically performed in IMS test-beds.
00030  * 
00031  * Users of the Open Source IMS Core System have to be aware that IMS
00032  * technology may be subject of patents and licence terms, as being 
00033  * specified within the various IMS-related IETF, ITU-T, ETSI, and 3GPP
00034  * standards. Thus all Open IMS Core users have to take notice of this 
00035  * fact and have to agree to check out carefully before installing, 
00036  * using and extending the Open Source IMS Core System, if related 
00037  * patents and licences may become applicable to the intended usage 
00038  * context.  
00039  *
00040  * You should have received a copy of the GNU General Public License
00041  * along with this program; if not, write to the Free Software
00042  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00043  * 
00044  */
00045  
00055 #include "third_party_reg.h"
00056 
00057 #include "mod.h" 
00058 #include "../../mem/mem.h"
00059 #include "../../mem/shm_mem.h"
00060 #include "../../parser/parse_uri.h"
00061 #include "../../locking.h"
00062 #include "../tm/tm_load.h"
00063 #include "../scscf/scscf_load.h"
00064 #include "sip.h"
00065 #include "ims_pm.h"
00066 
00067 extern struct tm_binds isc_tmb; 
00069 extern str isc_my_uri;          
00070 extern str isc_my_uri_sip;      
00072 extern int isc_expires_grace;   
00076 extern struct scscf_binds isc_scscfb;      
00085 int isc_third_party_reg(struct sip_msg *msg, isc_match *m,isc_mark *mark)
00086 {
00087     r_third_party_registration r;
00088     int expires=0;
00089     str req_uri ={0,0};
00090     str to ={0,0};
00091     str pvni ={0,0};
00092     str pani ={0,0};
00093     str cv ={0,0};
00094 
00095     struct hdr_field *hdr;
00096 
00097     LOG(L_INFO,"INFO:"M_NAME":isc_third_party_reg: Enter\n");
00098 
00099     /* Set Request Uri to IFC matching server name */
00100     req_uri.len = m->server_name.len;
00101     req_uri.s = m->server_name.s;
00102 
00103     /* Get To header*/
00104     to = cscf_get_public_identity(msg);
00105 
00106 
00107     /*TODO - check if the min/max expires is in the acceptable limits
00108      * this does not work correctly if the user has multiple contacts
00109      * and register/deregisters them individually!!!
00110      */
00111     expires = cscf_get_max_expires(msg);
00112     
00113     /* Get P-Visited-Network-Id header */
00114     pvni = cscf_get_visited_network_id(msg, &hdr);
00115     /* Get P-Access-Network-Info header */
00116     pani = cscf_get_access_network_info(msg, &hdr);
00117     
00118     /* Get P-Charging-Vector header */
00119     /* Just forward the charging header received from P-CSCF */
00120     /* Todo: implement also according to TS 24.229, chap 5.4.1.7 */
00121     cv =   cscf_get_charging_vector(msg, &hdr);
00122 
00123     if (req_uri.s){
00124         
00125         memset(&r,0,sizeof(r_third_party_registration));
00126 
00127         r.req_uri = req_uri;
00128         r.to = to;
00129         r.from = isc_my_uri_sip;
00130         r.pvni = pvni;
00131         r.pani = pani;
00132         r.cv = cv;
00133         r.service_info = m->service_info;
00134          
00135         if (expires<=0) r_send_third_party_reg(&r,0);
00136         else r_send_third_party_reg(&r,expires+isc_expires_grace);
00137         return ISC_RETURN_TRUE;
00138     }else{
00139         return ISC_RETURN_FALSE;
00140     }   
00141 }
00142 
00143 
00144 
00145 
00146 static str method={"REGISTER",8};
00147 static str event_hdr={"Event: registration\r\n",21};
00148 static str max_fwds_hdr={"Max-Forwards: 10\r\n",18};
00149 static str expires_s={"Expires: ",9};
00150 static str expires_e={"\r\n",2};
00151 static str contact_s={"Contact: <",10};
00152 static str contact_e={">\r\n",3};
00153 
00154 static str p_visited_network_id_s={"P-Visited-Network-ID: ",22};
00155 static str p_visited_network_id_e={"\r\n",2};
00156 
00157 static str p_access_network_info_s={"P-Access-Network-Info: ",23};
00158 static str p_access_network_info_e={"\r\n",2};
00159 
00160 static str p_charging_vector_s={"P-Charging-Vector: ",19};
00161 static str p_charging_vector_e={"\r\n",2};
00162 static str body_s={"<ims-3gpp version=\"1\"><service-info>",36};
00163 static str body_e={"</service-info></ims-3gpp>",26};
00164 
00165 
00166 #ifdef WITH_IMS_PM
00167     static str zero={0,0};
00168 #endif
00169 
00176 int r_send_third_party_reg(r_third_party_registration *r,int expires)
00177 {
00178         str h={0,0};
00179         str b={0,0};
00180 
00181         LOG(L_DBG,"DBG:"M_NAME":r_send_third_party_reg: REGISTER to <%.*s>\n",
00182                 r->req_uri.len,r->req_uri.s);
00183 
00184         h.len = event_hdr.len+max_fwds_hdr.len;
00185         h.len += expires_s.len + 12 + expires_e.len;
00186 
00187         h.len += contact_s.len + isc_my_uri_sip.len + contact_e.len;
00188 
00189         if (r->pvni.len) h.len += p_visited_network_id_s.len +
00190                 p_visited_network_id_e.len + r->pvni.len;
00191 
00192         if (r->pani.len) h.len += p_access_network_info_s.len +
00193                 p_access_network_info_e.len + r->pani.len;
00194 
00195         if (r->cv.len) h.len += p_charging_vector_s.len +
00196                 p_charging_vector_e.len + r->cv.len;
00197 
00198         h.s = pkg_malloc(h.len);
00199         if (!h.s){
00200             LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error allocating %d bytes\n",h.len);
00201             h.len = 0;
00202             return 0;
00203         }
00204 
00205         h.len = 0;
00206         STR_APPEND(h,event_hdr);
00207         
00208         STR_APPEND(h,max_fwds_hdr);
00209 
00210         STR_APPEND(h,expires_s);
00211         sprintf(h.s+h.len,"%d",expires);
00212         h.len += strlen(h.s+h.len);
00213         STR_APPEND(h,expires_e);
00214 
00215         STR_APPEND(h,contact_s);
00216         STR_APPEND(h,isc_my_uri_sip);
00217         STR_APPEND(h,contact_e);
00218 
00219         if (r->pvni.len) {
00220                 STR_APPEND(h,p_visited_network_id_s);
00221                 STR_APPEND(h,r->pvni);
00222                 STR_APPEND(h,p_visited_network_id_e);
00223         }
00224 
00225         if (r->pani.len) {
00226                 STR_APPEND(h,p_access_network_info_s);
00227                 STR_APPEND(h,r->pani);
00228                 STR_APPEND(h,p_access_network_info_e);
00229         }
00230 
00231         if (r->cv.len) {
00232                 STR_APPEND(h,p_charging_vector_s);
00233                 STR_APPEND(h,r->cv);
00234                 STR_APPEND(h,p_charging_vector_e);
00235         }
00236         LOG(L_CRIT,"SRV INFO:<%.*s>\n",r->service_info.len, r->service_info.s);
00237         if (r->service_info.len){
00238             b.len = body_s.len+r->service_info.len+body_e.len;
00239             b.s = pkg_malloc(b.len);
00240             if (!b.s){
00241                 LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error allocating %d bytes\n",b.len);
00242                 b.len = 0;
00243                 return 0;
00244             }
00245     
00246             b.len = 0;
00247             STR_APPEND(b,body_s);
00248             STR_APPEND(b,r->service_info);          
00249             STR_APPEND(b,body_e);           
00250         }
00251         
00252 
00253         if (isc_tmb.t_request(&method, &(r->req_uri), &(r->to), &(r->from), &h, &b, 0,
00254                  r_third_party_reg_response, &(r->req_uri))<0)
00255         {
00256                 LOG(L_ERR,"ERR:"M_NAME":r_send_third_party_reg: Error sending in transaction\n");
00257                 goto error;
00258         }
00259         #ifdef WITH_IMS_PM
00260             IMS_PM_LOG(UR_Att3rdPartyReg);
00261         #endif
00262         if (h.s) pkg_free(h.s);
00263         return 1;
00264 
00265 error:
00266         if (h.s) pkg_free(h.s);
00267         return 0;
00268 }
00269 
00270 
00275 void r_third_party_reg_response(struct cell *t,int type,struct tmcb_params *ps)
00276 {
00277         str req_uri;
00278         int expires;
00279         LOG(L_DBG,"DBG:"M_NAME":r_third_party_reg_response: code %d\n",ps->code);
00280         if (!ps->rpl) {
00281                 LOG(L_ERR,"INF:"M_NAME":r_third_party_reg_response: No reply\n");
00282                 return;
00283         }
00284         
00285         #ifdef WITH_IMS_PM
00286             if (ps->code>=200 && ps->code<300) 
00287                 IMS_PM_LOG01(UR_Succ3rdPartyReg,ps->code);
00288             else if (ps->code>=300) IMS_PM_LOG01(UR_Fail3rdPartyReg,ps->code);
00289         #endif
00290              
00291         if (ps->code>=200 && ps->code<300){
00292                 if (ps->rpl)
00293                         expires = cscf_get_expires_hdr(ps->rpl);
00294                 else
00295                         return;
00296                 req_uri = *((str*) *(ps->param));
00297         }else
00298         if (ps->code==404){
00299         }else{
00300                 LOG(L_INFO,"INF:"M_NAME":r_third_party_reg_response: code %d\n",ps->code); 
00301         }
00302 }
00303 

Generated on Thu Oct 23 04:14:38 2008 for Open IMS Core CSCFs by  doxygen 1.5.2