Navigation


Changeset 420:c8a61dabea55 in freeDiameter for extensions/app_sip/libdiamsip.c


Ignore:
Timestamp:
Jul 19, 2010, 4:46:33 PM (14 years ago)
Author:
Alexandre Westfahl <awestfahl@freediameter.net>
Branch:
default
Phase:
public
Message:

app_sip:Added LIR/LIA for SL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_sip/libdiamsip.c

    r409 r420  
    3434* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                             *
    3535*********************************************************************************************************/
    36 #include <mysql.h>
     36//#include <mysql.h>
    3737#include "diamsip.h"
    3838
     
    185185       
    186186}
     187
     188int get_diameter_uri(const unsigned char *sip_aor, const size_t sipaorlen, char ** diameter_uri, size_t *diameterurilen)
     189{
     190  CHECK_PARAMS(sip_aor && sipaorlen);
     191 
     192  size_t querylen, sipaorpurelen;
     193  char *query, *sipaor_pure;
     194  int not_found=1;
     195 
     196 
     197 
     198     
     199  //a sip aor must begin by "sip:" or "sips:" so it must at least be longer than 4 chars
     200  if(sipaorlen<5)
     201    return 2;
     202 
     203  //NOTE: each method has to purify sip_aor itself. You must remove quotes or special chars for security
     204 
     205  switch(as_conf->datasource)
     206  {
     207    //MySQL
     208    case ASMYSQL:
     209
     210      querylen=SQL_GETDIAMURI_LEN + sipaorlen;
     211     
     212         
     213          //We allocate the double size of SIP-URI because at worst it can be all quotes
     214          CHECK_MALLOC(sipaor_pure=malloc(sipaorlen*2+1));
     215          //We purify SIP-URI not to have forbidden characters
     216          sipaorpurelen=mysql_real_escape_string(conn, sipaor_pure, (const char *)sip_aor, sipaorlen);
     217         
     218         
     219      query = malloc(querylen+sipaorpurelen+ 2);
     220          snprintf(query, querylen+1, SQL_GETDIAMURI, sipaor_pure);
     221     
     222      MYSQL_RES *res;
     223      MYSQL_ROW row;
     224     
     225
     226      //We make the query       
     227      request_mysql(query);
     228      res=mysql_use_result(conn);
     229      if(res==NULL)
     230      {
     231                //We couldn't make the request
     232                diameter_uri=NULL;
     233                return 2;
     234      }
     235      TRACE_DEBUG(INFO,"***********%d|%d****************\n%s\n*********************************",sipaorlen,sipaorpurelen,query);
     236      while ((row = mysql_fetch_row(res)) != NULL)
     237      {
     238                *diameterurilen=strlen(row[0]);
     239                if(*diameterurilen>0)
     240                {
     241                        CHECK_MALLOC(*diameter_uri=malloc(*diameterurilen+1));
     242                        strcpy(*diameter_uri,row[0]);
     243                        not_found=0;
     244                        break;
     245                }
     246      }
     247      mysql_free_result(res);
     248      free(query);
     249          free(sipaor_pure);
     250      break;
     251     
     252    default:
     253     
     254      //We must never go here, if so, we must stop diameter_sip
     255      diameter_uri=NULL;
     256      return 2;
     257     
     258      break;
     259  }
     260 
     261  //0 if it was found
     262  return not_found;
     263 
     264}
     265
     266
    187267/*
    188268void nonce_add_element(char * nonce)
Note: See TracChangeset for help on using the changeset viewer.