provider.c

Go to the documentation of this file.
00001 /*
00002  * openser osp module. 
00003  *
00004  * This module enables openser to communicate with an Open Settlement 
00005  * Protocol (OSP) server.  The Open Settlement Protocol is an ETSI 
00006  * defined standard for Inter-Domain VoIP pricing, authorization
00007  * and usage exchange.  The technical specifications for OSP 
00008  * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org.
00009  *
00010  * Uli Abend was the original contributor to this module.
00011  * 
00012  * Copyright (C) 2001-2005 Fhg Fokus
00013  *
00014  * This file is part of Kamailio, a free SIP server.
00015  *
00016  * Kamailio is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version
00020  *
00021  * Kamailio is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  */
00030 
00031 #include <osp/osp.h>
00032 #include <osp/osputils.h>
00033 #include "../../dprint.h"
00034 #include "provider.h"
00035 
00036 extern unsigned int _osp_sp_number;
00037 extern char* _osp_sp_uris[];
00038 extern unsigned long _osp_sp_weights[];
00039 extern unsigned char* _osp_private_key;
00040 extern unsigned char* _osp_local_certificate;
00041 extern unsigned char* _osp_ca_certificate;
00042 extern int _osp_ssl_lifetime;
00043 extern int _osp_persistence;
00044 extern int _osp_retry_delay;
00045 extern int _osp_retry_limit;
00046 extern int _osp_timeout;
00047 extern int _osp_crypto_hw;
00048 extern OSPTPROVHANDLE _osp_provider;
00049 
00050 /*
00051  * Create a new OSP provider object per process
00052  * return 0 success, others failure
00053  */
00054 int ospSetupProvider(void) 
00055 {
00056     OSPTPRIVATEKEY privatekey;
00057     OSPTCERT localcert;
00058     OSPTCERT cacert;
00059     OSPTCERT* cacerts[1];
00060     int result;
00061 
00062     cacerts[0] = &cacert;
00063 
00064     if ((result = OSPPInit(_osp_crypto_hw)) != 0) {
00065         LM_ERR("failed to initalize OSP (%d)\n", result);
00066     } else if (OSPPUtilLoadPEMPrivateKey(_osp_private_key, &privatekey) != 0) {
00067         LM_ERR("failed to load private key from '%s'\n", _osp_private_key);
00068     } else if (OSPPUtilLoadPEMCert(_osp_local_certificate, &localcert) != 0) {
00069         LM_ERR("failed to load local certificate from '%s'\n",_osp_local_certificate);
00070     } else if (OSPPUtilLoadPEMCert(_osp_ca_certificate, &cacert) != 0) {
00071         LM_ERR("failed to load CA certificate from '%s'\n", _osp_ca_certificate);
00072     } else {
00073         result = OSPPProviderNew(
00074             _osp_sp_number,
00075             (const char**)_osp_sp_uris,
00076             _osp_sp_weights,
00077             "http://localhost:1234",
00078             &privatekey,
00079             &localcert,
00080             1,
00081             (const OSPTCERT**)cacerts,
00082             1,
00083             _osp_ssl_lifetime,
00084             _osp_sp_number,
00085             _osp_persistence,
00086             _osp_retry_delay,
00087             _osp_retry_limit,
00088             _osp_timeout,
00089             "",
00090             "",
00091             &_osp_provider);
00092         if (result != 0) {
00093             LM_ERR("failed to create provider (%d)\n", result);
00094         } else {
00095             LM_DBG("created new (per process) provider '%d'\n", _osp_provider);
00096             result = 0;
00097         }
00098     }
00099 
00100     /* 
00101      * Free space allocated while loading crypto information from PEM-encoded files.
00102      * There are some problems to free the memory, do not free them
00103      */
00104     if (privatekey.PrivateKeyData != NULL) {
00105         //free(privatekey.PrivateKeyData);
00106     }
00107 
00108     if (localcert.CertData != NULL) {
00109         //free(localcert.CertData);
00110     }
00111     
00112     if (cacert.CertData != NULL) {
00113         //free(localcert.CertData);
00114     }
00115 
00116     return result;
00117 }
00118 
00119 /*
00120  * Erase OSP provider object
00121  * return 0 success, others failure
00122  */
00123 int ospDeleteProvider(void) 
00124 {
00125     int result;
00126 
00127     if ((result = OSPPProviderDelete(_osp_provider, 0)) != 0) {
00128         LM_ERR("failed to erase provider '%d' (%d)\n", _osp_provider, result);
00129     }
00130     
00131     return result;
00132 }
00133 

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