`
`call_e164.class.php
`1 <?php
`2
`3
`4 /**
`5 * Rating Billing and Routing
`6 *
`7 * Three main classes in this package :
`8 * <ol>
`9 * <li>e164_call extended by call_ttl.
`10 * <li>call_ttl extended by call_routes.
`11 * <li>call_routes called by the invite.php (a simple XML-RPC server invoked by a
`remote client).
`12 * </ol>
`13 *
`14 * Those classes are used by the xml servers (invite.php, invite_stop.php) to calculate
`and produce:
`15 *
`16 * <ol>
`17 * <li>The Total Time to Live.
`18 * <li>The Route(s) a call can/should take
`19 * <li>Finally, calculate call costs and profits for Digifonica, Digifonica partners
`and End users (Partner clients)
`20 * </ol>
`21 *
`22 * @package Digifonica_RBR
`23 * @author Fuad A.
`24 * @copyright Digifonica
`25 *
`26 */
`27
`28 /**
`29 * needed for Voice Email Servers and supernode mapping
`30 *
`31 */
`32 require_once("config.php");
`33
`34
`35
`36
`/**
`37
`* Number and call type reconstructor.
`38
` *
`39
`* e164 is a class specific to the digifonica model, and is used to generate a
`properly formated e164 number<br>
`40
`* according to a caller profile. It goes further to establishing criteria about
`the callee and its type.<br>
`41
`* This is a caller-callee reconstructor, no matter where the person resides in the
`world, s/he can dial local, <br>
`42
`* national or internationa number the way s/he is used to.<br>
`43
`* Using a caller profile, we identify if a callee (number being called) is local,
`national or internal call to <br>
`44
`* the caller and not to the system.<br>
`45
` *
`46
`* Three main classes in this package :
`47
`* <ol>
`48
`* <li>e164_call extended by call_ttl.
`49
`* <li>call_ttl extended by call_routes.
`1
`
`Voip-Pal Ex. 2014
`IPR2016-01198
`
`
`
`call_e164.class.php
`50
`* <li>call_routes called by the invite.php (a simple XML-RPC server invoked by a
`remote client).
`51
`* </ol>
`52
` *
`53
`* Those classes are used by the xml servers (invite.php, invite_stop.php) to
`calculate and produce:
`54
` *
`55
`* <ol>
`56
`* <li>The Total Time to Live.
`57
`* <li>The Route(s) a call can/should take
`58
`* <li>Finally, calculate call costs and profits for Digifonica, Digifonica
`partners and End users (Partner clients)
`59
`* </ol>
`60
` *
`61
`* @package Digifonica_RBR
`62
`* @author Fuad A.
`63
`* @copyright Digifonica
`64
` */
`65 class e164_call {
`66
`67
`68
`69
`70
`71
`72
`73
`74
`75
`76
`77
`78
`79
`80
`81
`82
`83
`84
`85
`86
`87
`88
`89
`90
`91
`92
`93
`94
`95
`96
`97
`98
`99
`100
`101
`102
`
`/**
`* This is an array containing all possible call errors
` *
`* @global Array $errors
` *
` */
`private $errors = array(
`1=> "1:CALLER PROFILE NOT FOUND",
`2=> "2:MALFORMED CALLEE,OR NETWORK CALLEE DOES NOT EXIST",
`3=> "3:WRONG NUMBER DIALED",
`4=> "4:WRONG INTERNATIONAL NUMBER",
`5=> "5:WRONG NUMBER LENGTH",
`6=> "6:WRONG NUMBER LENGTH, LOCAL AREACODE MUST BE DIALED",
`7=> "7:WRONG NATIONAL NUMBER",
`8=> "8:CALLED A DID WITH NO MAPPING"
`
`/*
`caller variables
`
`2
`
`);
`
`/**
`* This is an array containg all possible call types.
` *
`* @var Array
` */
`private $call_type = array(
`1=> "INTERNATIONAL",
`2=> "NATIONAL",
`3=> "LOCAL",
`4=> "NETWORK",
`5=> "FAIL",
`6=> "LOCAL,NATIONAL STYLE",
`7=> "NETWORK, CROSS DOMAIN"
`
`);
`
`
`
`/**
`* Holds Original caller
` *
`* @var String
` */
`public $original_caller;
`/**
`* Holds original caller domain
` *
`* @var String
` */
`protected $original_caller_domain;
`/**
`* Original caller idd
` *
`* @var String
` */
`protected $original_caller_idd;
`/**
`* Original caller ndd
` *
`* @var String
` */
`protected $original_caller_ndd;
`/**
`* Holds Original caller areacode.
` *
`* @var String
` */
`protected $original_caller_areacode;
`/**
`* Holds Original caller country code.
` *
`* @var String
` */
`protected $original_caller_countrycode;
`/**
`* Holds Original flag if the caller had overlapping numbers
` *
`* @var Boolean
` */
`protected $original_caller_has_overlapping;
`/**
`* Holds Original caller area codes (Overlapping)
` *
`* @var Array
` */
`protected $original_caller_areacodes=array();
`
`call_e164.class.php
`103
`*/
`104
`105
`106
`107
`108
`109
`110
`111
`112
`113
`114
`115
`116
`117
`118
`119
`120
`121
`122
`123
`124
`125
`126
`127
`128
`129
`130
`131
`132
`133
`134
`135
`136
`137
`138
`139
`140
`141
`142
`143
`144
`145
`146
`147
`148
`149
`150
`151
`152
`153
`154
`/**
`155
`* holds the caller number (Could be a digifonica number or a PSTN number, this is
`not set during an incoming PSTN call or a call from another super node.
`156
` *
`157
`* @var string
`
`3
`
`
`
`call_e164.class.php
`158
` */
`public $caller;
`159
`160
`/**
`161
`* Holds the caller domain. (not set in the case of incoming call from PSTN or
`another supernode)
`162
` *
`163
`* @var String
`164
` */
`protected $caller_domain;
`165
`166
`/**
`167
`* Contains callee domain, can be empty when a PSTN call is the callee, if callee
`domain is not present, class will atte,pt to guess it.
`168
` *
`169
`* @var String
`170
` */
`protected $callee_domain;
`171
`172
`/**
`173
`* The caller Internationa Dialing Digit (IDD) extracted from the caller profile,
`to identify an international call. this can have multiple leading Zeroes( treating like
`string)
`174
` *
`175
`* @var String
`176
` */
`protected $caller_idd;
`177
`178
`/**
`179
`* National Dialing Digit (NDD) for the user, this identify when a user is trying
`to make a National call. (can have leading zero, so treating it like a string)
`180
` *
`181
`* @var String
`182
` */
`protected $caller_ndd;
`183
`184
`/**
`185
`* the caller area code, this is used to determine if the caller is making a local
`call and to find out overlapping area codes if any.
`186
` *
`187
`* @var integer
`188
` */
`protected $caller_areacode;
`189
`190
`/**
`191
`* Caller country code, used to determine if a user is making a national call.
`192
` *
`193
`* @var Integer
`194
` */
`protected $caller_countrycode;
`195
`196
`/**
`197
`* Flag to identify that a user has overlapping area codes
`198
`* Example: Vancouver has 604 and 778 and both can call each other for free, so a
`call between them is concidered local call.
`199
` *
`200
`* @var Boolean
`201
` */
`protected $caller_has_overlapping;
`202
`203
`/**
`204
`* This holds all area codes for the user, including overlapping area codes.
`205
` *
`206
`* @var Array
`
`4
`
`
`
`/*
`callee variables
`*/
`
`call_e164.class.php
`207
` */
`protected $caller_areacodes;
`208
`209
`210
`/**
`211
`* Flag that the caller has been set.
`212
` *
`213
`* @var Boolean
`214
` */
`protected $caller_is_set;
`215
`216
`/**
`217
`* this is a flag, used to store original callee only once, original callee must be
`stored in case of multiple call forwards.
`218
` *
`219
`* @var Boolean
`220
` */
`protected $callee_is_set;
`221
`222
`223
`224
`225
`226
`227
`/**
`228
`* Holds the original callee number
`229
` *
`230
`* @var String
`231
` */
`protected $original_callee;
`232
`233
`/**
`234
`* Original callee domain
`235
` *
`236
`* @var String
`237
` */
`protected $original_callee_domain;
`238
`239
`/**
`240
`* Stores Callee number
`241
` *
`242
`* @var string
`243
` */
`protected $callee;
`244
`245
`/**
`246
`* This is the actual value of the call type, the textual representation is in the
`array $call_type
`247
` *
`248
`* @var integer
`249
` */
`protected $callee_type; //look up for $call_type
`250
`251
`/**
`252
`* Stores callee data
`253
`* store as an associative array as follows :
`254
`* <ol>
`255
`* <li>ml_id
`256
`* <li>ml_dialing_code
`257
`* <li>country_code
`258
`* <li>ISO_3166_1_alpha_2
`259
`* <li>UTC_min
`260
`* <li>UTC_max
`
`5
`
`
`
`call_e164.class.php
`261
`* <li>destination
`262
`* <li>type_id
`263
`* <li>location
`264
`* <li>area_code_length
`265
`* <li>min_subscr_nr_length
`266
`* <li>max_subscr_nr_length
`267
`* <li>ml_rate
`268
`* <li>ml_increment_charge1
`269
`* <li>ml_increment_charge2
`270
`* </ol>
`271
` *
`272
`* @var Array
`273
` */
`protected $callee_data = array();
`274
`275
`/**
`276
`* This is a flag, and is set once the length is a verified (like
`$callee_length_verified) and concidered good. Set but not used yet.
`277
` *
`278
`* @var Boolean
`279
` */
`protected $callee_length_is_good;
`280
`281
`/**
`282
`* This is a flag, and is set once the length is a verified (like
`$callee_length_is_good) and concidered good. Set but not used yet.
`283
` *
`284
`* @var Boolean
`285
` */
`protected $callee_length_verified;
`286
`287
`288
`289
`290
`291
`292
`/**
`293
`* Flag that at least one call forward has occured.
`294
` *
`295
`* @var Boolean
`296
` */
`protected $cf_flag; // indicates that Call forward has occured
`297
`298
`/**
`299
`* Final result/format of the e164 number is stored in this variable.
`300
` *
`301
`* @var String
`302
` */
`protected $e164_formed_nubmer;
`303
`304
`/**
`305
`* This is used to set a THIRD_PARTY_INVITE (incoming call from PSTN), i.e. no
`caller profile needs to be created.
`306
` *
`307
`* @var String
`308
` */
`protected $special_request='';
`309
`310
`311
`312
`313
`
`/**
`* Constructor for the class
` *
`
`/*
`call related variables
`*/
`
`6
`
`
`
`if(! ($this->special_request == 'THIRD_PARTY_INVITE')){
`$this->caller_domain = $domain;
`$this->create_caller_profile();
`
`}
`$this->caller_is_set = true;
`
`}
`
`}
`
`}
`
`$this->caller = $caller;
`
`/**
`* Takes care of sequence of execution to create a caller profile
` *
`* @param String $caller
`* @param String $domain
` */
`public function set_caller($caller,$domain){
`
`call_e164.class.php
`314
`* @param String $caller
`315
`* @param String $domain
`316
`* @return e164_call
`317
` */
`function e164_call($caller='',$domain='') {
`318
`$this->caller_is_set = false;
`319
`if($caller and $domain){
`320
`$this->set_caller($caller,$domain);
`321
`322
`323
`324
`325
`326
`327
`328
`329
`330
`331
`332
`333
`334
`335
`336
`337
`338
`339
`340
`341
`342
`/**
`343
`* All aspects of the caller Flags and data needed to identify a caller is set
`here. including overlapping numbers.
`344
` *
`345
` */
`private function create_caller_profile(){
`346
`try{
`347
`$user_data = mysql_fetch_array($this->sql_query("SELECT * FROM
`348
`subscriber_dialing_profile WHERE username='$this->caller' and domain= '$this
`->caller_domain'"));
`if($user_data){
`349
`$this->caller_idd = $user_data['idd'];
`350
`$this->caller_ndd = $user_data['ndd'];
`351
`$this->caller_areacode = $user_data['area_code'];
`352
`$this->caller_countrycode = $user_data['country_code'];
`353
`$temp = explode(",",$user_data['local_length']);
`354
`$this->caller_min_local_length = $temp[0];
`355
`$this->caller_max_local_length = $temp[1];
`356
`357
`/*
`358
`Below IF statement
`359
`the "over_lap_numbers" table contains overlapping areacodes
`360
`i.e. 778 and 604 in vancouver, Canada co-exist in the same geographical
`area
`361
`here we populate user codes for local dialing
`362
`*/
`$temp_arr = mysql_fetch_array($this->sql_query("SELECT num_group FROM
`363
`over_lap_numbers WHERE `country_code` = '$this->caller_countrycode' and num_group like
`'%#$this->caller_areacode#%'"));
`
`7
`
`
`
`if($temp_arr){
`$temp_codes = explode("#",$temp_arr['num_group']);
`array_shift($temp_codes);
`array_pop($temp_codes);
`$this->caller_areacodes = $temp_codes;
`$this->caller_has_overlapping = true;
`}else{
`$this->caller_areacodes = array($this->caller_areacode);
`$this->caller_has_overlapping = false;
`
`}
`$this->caller_is_set = true;
`}else{
`throw new Exception(1);
`
`}
`}catch (Exception $e){
`$this->e164_exception_handler($e->getMessage());
`
`}
`
`}
`
`call_e164.class.php
`364
`365
`366
`367
`368
`369
`370
`371
`372
`}
`373
`if(!$this->caller_is_set){
`374
`$this->original_caller = $this->caller;
`375
`$this->original_caller_domain = $this->caller_domain;
`376
`$this->original_caller_idd = $this->caller_idd;
`377
`$this->original_caller_ndd = $this->caller_ndd;
`378
`$this->original_caller_areacode = $this->caller_areacode;
`379
`$this->original_caller_countrycode = $this->caller_countrycode;
`380
`$this->original_caller_has_overlapping = $this->
`381
`caller_has_overlapping;
`$this->original_caller_areacodes=$this->caller_areacodes;
`382
`383
`384
`385
`386
`387
`388
`389
`390
`391
`392
`393
`394
`395
`396
`397
`398
`399
`400
`401
`402
`403
`404
`405
`406
`407
`408
`409
`/* Next Lines checking for DID Masking i.e. user calling a PSTN that is mapped
`internally */
`$temp_user = $this->check_for_did($this->e164_formed_nubmer);
`410
`if($temp_user){
`411
`$temp_arr = explode("#",$temp_user);
`412
`413
`/*$this->callee = $temp_arr[0];
`414
`$callee_domain = $temp_arr[1];*/
`$this->set_callee($temp_arr[0],$temp_arr[1]);
`415
`416
`417
`
`/**
`* Takes care of the sequence and logic needed to create a callee
` *
`* @param String $callee
`* @param String $callee_domain
` */
`public function set_callee($callee,$callee_domain=''){
`if(!$this->callee_is_set){
`$this->original_callee = $callee;
`$this->callee_is_set = true;
`
`}
`$this->callee = $this->clean_callee($callee);
`
`$this->callee_domain = $callee_domain;
`$this->create_callee_profile();
`
`}
`/* End of DID Check */
`
`8
`
`
`
`}
`}catch (Exception $e){
`$this->e164_exception_handler($e->getMessage());
`
`}
`
`}
`return false;
`
`call_e164.class.php
`}
`418
`419
`420
`/**
`421
`* Checks if the number being called is a mapped DID in our system, if it is we
`rout it internally
`422
` *
`423
`* @param String $user
`424
`* @return Boolean or DidMap(DigifonicaNumber#Domain)
`425
` */
`protected function check_for_did($user=''){
`426
`$num = $user?$user:$this->callee;
`427
`$did_check = @mysql_fetch_array($this->sql_query("SELECT * FROM did_bank WHERE
`428
`did='$num'"));
`if($did_check[0]){
`429
`try{
`430
`if($did_check['mapped_to'] and $did_check['domain']){
`431
`return $did_check['mapped_to']."#".$did_check['domain'];
`432
`}else{
`433
`throw new Exception(8);
`434
`435
`436
`437
`438
`439
`440
`441
`442
`443
`444
`445
`446
`447
`448
`}
`449
`450
`/**
`451
`* Creates a callee profile, all aspects of the callee is set here including the
`e164 number is also set here. NOTE: the e164 number can change when call forwarding
`occures.
`452
` *
`453
` */
`private function create_callee_profile(){
`454
`455
`/*
`456
`We set all aspect of the callee
`457
`1- local, national, international, newtwork call
`458
`2- depending on the match (Or no match) we create call the e164 creater or
`reject the callee
`459
`*/
`460
`461
`/*
`462
`First detect if callee national, international or other
`463
`*/
`$callee_length = strlen($this->callee);
`464
`try{
`465
`switch (true) {
`466
`case (isset($this->caller_idd) && preg_match("/^".$this->caller_idd."/",
`467
`$this->callee)):
`
`}
`/**
`* Sets the global variable, it is called num to imply the numeric format needed.
` *
`* @param String $num
` */
`protected function set_e164_formed_number($num){
`$this->e164_formed_nubmer = "$num";
`
`9
`
`
`
`}
`
`$idd_length = strlen($this->caller_idd);
`$this->set_ml_id($idd_length);
`if($this->callee_data['ml_id']){ //callee was found and set
`$this->callee_type = 1;
`$this->check_callee_length($idd_length);
`$this->set_e164_formed_number(substr($this->callee,$idd_length));
`}else{
`throw new Exception(4);
`
`call_e164.class.php
`468
`469
`470
`471
`472
`473
`474
`475
`476
`477
`break;
`478
`case ( isset($this->caller_ndd) && preg_match("/^".$this->caller_ndd."/"
`479
`,$this->callee)):
`$ndd_length = strlen($this->caller_ndd);
`480
`$this->callee = $this->caller_countrycode.substr($this->callee,
`481
`$ndd_length);
`if($this->matched_areacodes($this->caller_areacodes,substr($this->callee
`482
`,strlen($this->caller_ndd)))){
`$this->callee_type = 6;
`483
`}else{
`484
`$this->callee_type = 2;
`485
`486
`487
`488
`489
`490
`491
`492
`}
`493
`break;
`494
`case ( isset($this->caller_areacodes) && ($area_code_length=$this->
`495
`matched_areacodes($this->caller_areacodes,$this->callee)) and (($callee_length>=($this->
`caller_min_local_length + $area_code_length)) and ($callee_length<=($this->
`caller_max_local_length +$area_code_length)))):
`$ndd_length = strlen($this->caller_ndd);
`496
`$this->callee_type = 3;
`497
`$this->set_ml_id(0,$this->caller_countrycode);
`498
`$this->check_callee_length(0,$this->caller_countrycode);
`499
`$this->set_e164_formed_number($this->caller_countrycode.$this->callee);
`500
`break;
`501
`default:
`502
`503
`//check if network or normal local call or Fail it
`if(($callee_length>=$this->caller_min_local_length) and ($callee_length
`504
`<=$this->caller_max_local_length)){
`505
`//could be a local number
`if(($this->callee[0] != '0') and ($this->callee[0] != '1') and (!
`506
`$this->caller_has_overlapping)){
`507
`//if caller areacaode (when calling locally) has overlapping
`areacodes then the fully qualified areacode must be dialed
`508
`//$this->callee =
`$this->caller_countrycode.$this->caller_areacode.$this->callee;
`$ndd_length = strlen($this->caller_ndd);
`509
`$this->callee_type = 3;
`510
`$this->set_ml_id(0,$this->caller_countrycode.$this->
`511
`caller_areacode);
`512
`
`}
`$this->set_ml_id(0);
`$this->check_callee_length(0);
`if($this->callee_data['ml_id']){
`$this->set_e164_formed_number($this->callee);
`}else{
`throw new Exception();
`
`$this->check_callee_length(0,$this->caller_countrycode.$this->
`10
`
`
`
`}
`}else{
`//could be a network call
`$callee_reseller = $this->valid_network_number($this->callee);
`if($callee_reseller){
`$this->callee_domain = $callee_reseller;
`if($this->callee_domain==$this->caller_domain){
`$this->callee_type = 4;
`}else{
`$this->callee_type = 7;
`
`}
`$this->set_e164_formed_number($this->callee);
`}else{
`$this->callee_type = 5; //fail
`throw new Exception(2);
`
`}
`
`}
`break;
`
`call_e164.class.php
`caller_areacode);
`$this->set_e164_formed_number($this->caller_countrycode.$this->
`513
`caller_areacode.$this->callee);
`}else{
`514
`throw new Exception(6);
`515
`516
`517
`518
`519
`520
`521
`522
`523
`524
`525
`526
`527
`528
`529
`530
`531
`532
`533
`534
`535
`536
`537
`538
`539
`540
`541
`542
`543
`544
`545
`546
`547
`548
`549
`550
`551
`552
`553
`554
`555
`556
`557
`558
`559
`560
`561
`562
`/**
`563
`* Function matches overlapping area codes for the number being called in a
`national or direct way... i.e. in vancouver dial 1604 (looks like national) and 604
`both are local (or 1778 or 778)
`564
` *
`
`/*
`function cleans the callee from non numeric characters
`*/
`/**
`* Cleans number being dialed from non numerical garbage
` *
`* @param String $callee
`* @return String
` */
`private function clean_callee($callee){
`$temp_callee = "";
`for($i=0;$i<strlen($callee);$i++){
`if(is_numeric($callee[$i])){
`$temp_callee .= $callee[$i];
`
`}
`}catch (Exception $e){
`$this->e164_exception_handler($e->getMessage());
`
`}
`
`}
`
`}
`
`}
`return $temp_callee;
`
`}
`
`11
`
`
`
`}
`
`}
`
`}
`return false;
`
`call_e164.class.php
`565
`* @param Array $arr
`566
`* @param String $callee
`567
`* @return Integer or Boolean False if no matches and length of first matched if any.
`568
` */
`private function matched_areacodes($arr,$callee){
`569
`for($i=0;$i<sizeof($arr);$i++){
`570
`if(preg_match("/^".$arr[$i]."/",$callee,$matches)){
`571
`return strlen($matches[0]);
`572
`573
`574
`575
`576
`577
`578
`/**
`579
`* Sets data needed about the number being called, all data is populated from the
`Masterlist
`580
`* the prepend is needed to add the areacode and/or areacode to calculate the max
`length
`581
` *
`582
`* @param Integer $start_from
`583
`* @param String $prepend
`584
` */
`private function set_ml_id($start_from,$prepend=''){
`585
`$num_max_length = strlen(substr($prepend.$this->callee,$start_from));
`586
`$done = false;
`587
`$ind = 1;
`588
`while(!$done){
`589
`$num = substr($prepend.$this->callee,$start_from,$ind);
`590
`$ml_id_check = mysql_fetch_array($this->sql_query("SELECT * FROM masterlist
`591
`WHERE ml_dialing_code LIKE '".$num."%' LIMIT 1"));
`if(!$ml_id_check){
`592
`593
`// found the longest match
`$dialing_code_data = mysql_fetch_array($this->sql_query("SELECT * FROM
`594
`masterlist WHERE ml_dialing_code LIKE '".$previous_num."%' LIMIT 1"));
`$this->callee_data['ml_id'] = $dialing_code_data['ml_id'];
`595
`$this->callee_data['ml_dialing_code'] = $dialing_code_data[
`596
`'ml_dialing_code'];
`$this->callee_data['country_code'] = $dialing_code_data['country_code'];
`597
`$this->callee_data['ISO_3166_1_alpha_2'] = $dialing_code_data[
`598
`'ISO_3166_1_alpha_2'];
`$this->callee_data['UTC_min'] = $dialing_code_data['UTC_min'];
`599
`$this->callee_data['UTC_max'] = $dialing_code_data['UTC_max'];
`600
`$this->callee_data['destination'] = $dialing_code_data['destination'];
`601
`$this->callee_data['type_id'] = $dialing_code_data['type_id'];
`602
`$this->callee_data['location'] = $dialing_code_data['location'];
`603
`$this->callee_data['area_code_length'] = $dialing_code_data[
`604
`'area_code_length'];
`$this->callee_data['min_subscr_nr_length'] = $dialing_code_data[
`605
`'min_subscr_nr_length'];
`$this->callee_data['max_subscr_nr_length'] = $dialing_code_data[
`606
`'max_subscr_nr_length'];
`$this->callee_data['ml_rate'] = $dialing_code_data['ml_rate'];
`607
`$this->callee_data['ml_increment_charge1'] = $dialing_code_data[
`608
`'ml_increment_charge1'];
`$this->callee_data['ml_increment_charge2'] = $dialing_code_data[
`609
`'ml_increment_charge2'];
`
`12
`
`
`
`$done = true;
`
`$start_from
`$prepend
`
`starting point of checking
`caller area code and/or country code needs to
`
`}
`
`}
`
`}
`
`}
`$previous_num = $num;
`$ind++;
`if($ind>$num_max_length){
`$done = true;
`
`call_e164.class.php
`$this->callee_data['national_significant_number'] = $dialing_code_data[
`610
`'ml_increment_charge2'];
`611
`612
`613
`614
`615
`616
`617
`618
`619
`620
`621
`622
`/**
`623
`* Check the callee (number being called) against its type
`624
` *
`625
`* @param Integer
`626
`* @param String
`appended sometimes
`627
` */
`private function check_callee_length($start_from,$prepend=''){
`628
`$this->callee_length_verified = false;
`629
`$this->callee_length_is_good = false;
`630
`$max = $this->callee_data['max_subscr_nr_length'];
`631
`$min = $this->callee_data['min_subscr_nr_length'];
`632
`633
`try{
`634
`switch ($this->callee_data['type_id']) {
`635
`case 'COU':
`636
`$num = substr($prepend.$this->callee,($start_from+strlen($this->
`637
`callee_data['ml_dialing_code'])));
`$num_length = strlen($num);
`638
`if(($num_length >= 3) and ($num_length<=15)){
`639
`$this->callee_length_verified = true;
`640
`$this->callee_length_is_good = true;
`641
`}else{
`642
`throw new Exception(5);
`643
`}
`644
`break;
`645
`case 'MOB':
`646
`$num = substr($prepend.$this->callee,($start_from+strlen($this->
`647
`callee_data['country_code'])));
`$num_length = strlen($num);
`648
`$num_extra_limit = strlen($this->callee_data[
`649
`'national_significant_number']);
`if(($num_length >= ($min - $num_extra_limit) ) and ($num_length<= ($max
`650
`+ $num_extra_limit))){
`$this->callee_length_verified = true;
`651
`$this->callee_length_is_good = true;
`652
`}else{
`653
`throw new Exception(5);
`654
`}
`655
`break;
`656
`case 'FIX':
`657
`$num = substr($prepend.$this->callee,($start_from+strlen($this->
`658
`callee_data['ml_dialing_code'])));
`
`13
`
`
`
`}
`break;
`
`}
`}catch (Exception $e){
`$this->e164_exception_handler($e->getMessage());
`
`$num_length = strlen($num);
`if(($num_length >= $min) and ($num_length<=$max)){
`$this->callee_length_verified = true;
`$this->callee_length_is_good = true;
`}else{
`throw new Exception(5);
`
`call_e164.class.php
`659
`660
`661
`662
`663
`664
`}
`665
`break;
`666
`default:
`667
`$num = substr($prepend.$this->callee,($start_from+strlen($this->
`668
`callee_data['ml_dialing_code'])));
`$num_length = strlen($num);
`669
`if(($num_length >= $min) and ($num_length<=$max)){
`670
`$this->callee_length_verified = true;
`671
`$this->callee_length_is_good = true;
`672
`}else{
`673
`throw new Exception(5);
`674
`675
`676
`677
`678
`679
`680
`681
`682
`683
`684
`685
`686
`687
`688
`689
`690
`691
`692
`693
`694
`695
`696
`$myconnection = mysql_connect("$hostname_connect","$username_connect","
`697
`$password_connect") or die ("Error connecting to Server.");
`mysql_select_db("$database_connect",$myconnection) or die ("Database not found");
`698
`699
`700
`701
`702
`/**
`703
`* Simple SQL query execution, this is done in case we decide to log all Queries
`etc...
`704
` *
`705
`* @param String $q
`706
`* @return Resource
`707
` */
`public function sql_query($q){
`708
`$this->db_connect();
`709
`710
`///$query = mysql_query($q) or die ("$q
`".var_dump(debug_backtrace()).mysql_error());
`14
`
`}
`
`}
`
`/**
`* quick connection to the db
` *
` */
`private function db_connect(){
`
`/**
`* Contains simple database variables
` *
` */
`include("db_config.php");
`
`}
`
`
`
`}
`
`}
`
`}
`
`call_e164.class.php
`$query = mysql_query($q) or die (mysql_error());
`711
`return $query;
`712
`713
`714
`715
`/**
`716
`* Checks that the number is a valid network number by referencing Domain assigned
`ranges...
`717
`* if the user does not exist on a super node range, a simple check is done to see
`if the number called starts with a know Supernode code, and is accepted as valid if it
`does .
`718
` *
`719
`* @param String $number
`720
`* @return unknown
`721
` */
`private function valid_network_number($number=''){
`722
`global $_super_nodes;
`723
`$number = $number?$number:$this->callee;
`724
`$callee_reseller = mysql_fetch_array($this->sql_query("SELECT domain FROM
`725
`reseller_remote_data WHERE '$number'>=range_start and '$number'<=range_end and
`(LENGTH(range_start)= LENGTH('$number'))"));
`if($callee_reseller['domain']){
`726
`if($this->user_exists($number,$callee_reseller['domain'])){
`727
`return $callee_reseller['domain'];
`728
`}elseif($_super_nodes[substr($this->callee,0,2)]){
`729
`return $_super_nodes[substr($this->callee,0,2)];
`730
`731
`732
`733
`734
`735
`736
`/**
`737
`* Checks if a user exists under a certain domain, callee data is assumed if
`nothing is passed
`738
` *
`739
`* @param String $number
`740
`* @param String $domain
`741
`* @return Boolean
`742
` */
`public function user_exists($number='',$domain=''){
`743
`744
`$exists = false;
`745
`$number = $number?$number:$this->callee;
`746
`$domain = $domain?$domain:$this->callee_domain;
`747
`$number_exists = mysql_fetch_array($this->sql_query("SELECT domain FROM
`748
`subscriber WHERE username='$number' AND domain='$domain'"));
`if($number_exists[0]){
`749
`$exists = true;
`750
`751
`752
`753
`754
`755
`/**
`756
`* Outputs a caught error and exits with its code, all codes are defined in the
`$errors variable
`757
` *
`758
`* @param integer $exception
`
`}
`return $exists;
`
`}
`
`}
`return false;
`
`15
`
`
`
`}
`
`/**
`* Dumps data to the screen about the class and routs
` *
`* @return String
` */
`public function __toString() {
`$res = "";
`
`$res .= "Forwarding Detected.<br><br>\n";
`$res .= "ORIGINAL_caller: ".$this->original_caller." <br>\n";
`$res .= "ORIGINAL_caller_domain: ".$this->original_caller_domain." <br>\n";
`$res .= "ORIGINAL_caller_idd: ".$this->original_caller_idd." <br>\n";
`$res .= "ORIGINAL_caller_ndd: ".$this->original_caller_ndd." <br>\n";
`$res .= "ORIGINAL_caller_areacode: ".$this->original_caller_areacode."
`
`call_e164.class.php
`759
` */
`private function e164_exception_handler($exception){
`760
`echo $this->errors[$exception];
`761
`exit($exception);
`762
`763
`764
`765
`766
`767
`768
`769
`770
`771
`772
`if($this->cf_flag){
`773
`$res .=
`774
`"================================================================================<br><br>
`\n";
`775
`776
`777
`778
`779
`780
`<br>\n";
`$res .= "ORIGINAL_caller_countrycode: ".$this->original_caller_countrycode.
`781
`" <br><br>\n\n";
`$res .= "ORIGINAL_callee_domain: ".$this->original_callee_domain."
`782
`<br><br>\n";
`783
`$res .= "ORIGINAL_callee: ".$this->original_caller_countrycode." <br>\n\n";
`784
`$res .= "ORIGINAL_callee_domain: ".$this->original_callee_domain."
`785
`<br><br>\n";
`786
`$res .=
`787
`"================================================================================<br><br>
`\n";
`788
`789
`790
`791
`$res .= "caller: ".$this->caller." <br>\n";
`792
`$res .= "caller_domain: ".$this->caller_domain." <br>\n";
`793
`$res .= "caller_idd: ".$this->caller_idd." <br>\n";
`794
`$res .= "caller_ndd: ".$this->caller_ndd." <br>\n";
`795
`$res .= "caller_areacode: ".$this->caller_areacode." <br>\n";
`796
`$res .= "caller_countrycode: ".$this->caller_countrycode." <br><br>\n\n";
`797
`$res .= "callee: ".$this->callee." <br>\n";
`798
`$res .= "callee_type: ".$this->call_type[$this->callee_type]." <br>\n";
`799
`$res .= "callee_domain: ".$this->callee_domain." <br><br>\n";
`800
`$res .=
`801
`"================================================================================<br><br>
`\n";
`802
`803
`804
`
`}
`$res .= "\n\n<br>CALLER INFORMATION ::<br><br>\n\n";
`
`$res .= "\n\n<br><br>CALLEE INFORMATION ::<br><br>\n\n";
`while (list($key, $value) = each ($this->callee_data)) {
`$res .= $key." = ".$value." <br>\n";
`16
`
`
`
`call_e164.class.php
`}
`805
`$res .=
`806
`"================================================================================<br><br>
`\n";
`807
`808
`809
`810
`811
`812
`813
`814
`815 }
`816 ?>
`817
`
`$res .= "\n\n<br><br>ROUTES INFORMATION ::<br><br>\n\n";
`while (list($key, $value) = each ($this->routes)) {
`$res .= $key." = ".$value." <br>\n";
`
`}
`
`$res .= "\n\n<br><br> e164_formed_number = ".$this->e164_formed_nubmer;
`return $res;
`
`}
`
`17
`
`
`
`call_routes.class.php
`1 <?php
`2
`3
`4 /**
`5 *
`6 * Call routes calculator, the only class that needs to be called in this package.
`7 * Class generates routes and SIP message based on what is defined in the DB. Also
`retreives VM route, Call display information.
`8 * This class extends TTL (Total time to live) and it is the main class that should be
`called when calculating routes.
`9 *
`10 * @package Digifonica_RBR
`11 * @author Fuad A.
`12 * @copyright Digifonica
`13
`14 */
`15
`16 /**
`17 * Needed for this class (Extending it)
`18 *
`19 */
`20 require_once("call_ttl.class.php");
`21 /**
`22 * needed for Voice Email Servers and supernode mapping
`23 *
`24 */
`25 require_once("config.php");
`26
`27
`/**
`28
` *
`29
`* Call routes calculator, the only class that needs to be called in this package.
`30
`* Class generates routes and SIP message based on what is defined in the DB. Also
`retreives VM route, Call display information.
`31
`* This class extends TTL (Total time to live) and it is the main class that should
`be called when calculating routes.
`32
` *
`33
`* @package Digifonica_RBR
`34
`* @author Fuad A.
`35
`* @copyright Digifonica
`36
`37
` */
`38 class call_routes extends call_ttl {
`39
`40
`41
`42
`43
`44
`45
`46
`47
`48
`49
`50
`51
`52
`
`/**
`* Array containing routes as SIP messages
` *
`* @var Array
` */
`protected $routes = array();
`/**
`* holds the caller ID of the user
` *
`* @var String
` */
`protected $caller_id='Private';
`/**
`
`18
`
`
`
`}
`
`call_routes.class.php
`53
`* Holds the Voice mail domain to use! (Retreived from config file)
`54
` *
`55
`* @var String
`56
` */
`protected $vm_domain;
`57
`58
`59
`/**
`60
`* Constructor... the class must be called with the defined parameters. Callee
`domain is optional and the class will try to guess it.
`61
`* Special is a flag (THIRD_PARTY_INVITE) when set, the caller is not set and
`concidered a incoming PSTN call.
`62
` *
`63
`* @param String $caller
`64
`* @param String $domain
`65
`* @param String $callee
`66
`* @param String $callee_domain
`67
`* @param String $special
`68
`* @return call_routes
`69
` */
`function call_routes($caller,$domain,$callee,$callee_domain='',$special='') {
`70
`$this->special_request = $special;
`71
`$this->call_ttl($caller,$domain,$callee,$callee_domain);
`72
`$this->genereate_routes();
`73
`74
`75
`76
`/**
`77
`* Check if the domain has a special VM server otherwise ... it returns the default
`route.
`78
`