root/src/ftdm_call_utils.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. FT_DECLARE
  2. FT_DECLARE
  3. FT_DECLARE
  4. FT_DECLARE
  5. FT_DECLARE

   1 /*
   2  * Copyright (c) 2010, Sangoma Technologies
   3  * David Yat Sin <dyatsin@sangoma.com>
   4  * All rights reserved.
   5  * 
   6  * Redistribution and use in source and binary forms, with or without
   7  * modification, are permitted provided that the following conditions
   8  * are met:
   9  * 
  10  * * Redistributions of source code must retain the above copyright
  11  * notice, this list of conditions and the following disclaimer.
  12  * 
  13  * * Redistributions in binary form must reproduce the above copyright
  14  * notice, this list of conditions and the following disclaimer in the
  15  * documentation and/or other materials provided with the distribution.
  16  * 
  17  * * Neither the name of the original author; nor the names of any contributors
  18  * may be used to endorse or promote products derived from this software
  19  * without specific prior written permission.
  20  * 
  21  * 
  22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  26  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33  */
  34 
  35 #include "private/ftdm_core.h"
  36 #include <ctype.h>
  37 
  38 
  39 FT_DECLARE(ftdm_status_t) ftdm_span_set_npi(const char *npi_string, uint8_t *target)
  40 {
  41         if (!strcasecmp(npi_string, "isdn") || !strcasecmp(npi_string, "e164")) {
  42                 *target = FTDM_NPI_ISDN;
  43         } else if (!strcasecmp(npi_string, "data")) {
  44                 *target = FTDM_NPI_DATA;
  45         } else if (!strcasecmp(npi_string, "telex")) {
  46                 *target = FTDM_NPI_TELEX;
  47         } else if (!strcasecmp(npi_string, "national")) {
  48                 *target = FTDM_NPI_NATIONAL;
  49         } else if (!strcasecmp(npi_string, "private")) {
  50                 *target = FTDM_NPI_PRIVATE;
  51         } else if (!strcasecmp(npi_string, "reserved")) {
  52                 *target = FTDM_NPI_RESERVED;
  53         } else if (!strcasecmp(npi_string, "unknown")) {
  54                 *target = FTDM_NPI_UNKNOWN;
  55         } else {
  56                 ftdm_log(FTDM_LOG_WARNING, "Invalid NPI value (%s)\n", npi_string);
  57                 *target = FTDM_NPI_UNKNOWN;
  58                 return FTDM_FAIL;
  59         }
  60         return FTDM_SUCCESS;
  61 }
  62 
  63 FT_DECLARE(ftdm_status_t) ftdm_span_set_ton(const char *ton_string, uint8_t *target)
  64 {
  65         if (!strcasecmp(ton_string, "national")) {
  66                 *target = FTDM_TON_NATIONAL;
  67         } else if (!strcasecmp(ton_string, "international")) {
  68                 *target = FTDM_TON_INTERNATIONAL;
  69         } else if (!strcasecmp(ton_string, "local")) {
  70                 *target = FTDM_TON_SUBSCRIBER_NUMBER;
  71         } else if (!strcasecmp(ton_string, "unknown")) {
  72                 *target = FTDM_TON_UNKNOWN;
  73         } else {
  74                 ftdm_log(FTDM_LOG_WARNING, "Invalid TON value (%s)\n", ton_string);
  75                 *target = FTDM_TON_UNKNOWN;
  76                 return FTDM_FAIL;
  77         }
  78         return FTDM_SUCCESS;
  79 }
  80 
  81 FT_DECLARE(ftdm_status_t) ftdm_span_set_bearer_capability(const char *bc_string, ftdm_bearer_cap_t *target)
  82 {
  83         if (!strcasecmp(bc_string, "speech")) {
  84                 *target = FTDM_BEARER_CAP_SPEECH;
  85         } else if (!strcasecmp(bc_string, "unrestricted-digital")) {
  86                 *target = FTDM_BEARER_CAP_64K_UNRESTRICTED;
  87         } else if (!strcasecmp(bc_string, "3.1Khz")) {
  88                 *target = FTDM_BEARER_CAP_3_1KHZ_AUDIO;
  89         } else {
  90                 ftdm_log(FTDM_LOG_WARNING, "Unsupported Bearer Capability value (%s)\n", bc_string);
  91                 return FTDM_FAIL;
  92         }
  93         return FTDM_SUCCESS;
  94 }
  95 
  96 FT_DECLARE(ftdm_status_t) ftdm_span_set_bearer_layer1(const char *bc_string, ftdm_user_layer1_prot_t *target)
  97 {
  98         if (!strcasecmp(bc_string, "v110")) {
  99                 *target = FTDM_USER_LAYER1_PROT_V110;
 100         } else if (!strcasecmp(bc_string, "ulaw")) {
 101                 *target = FTDM_USER_LAYER1_PROT_ULAW;
 102         } else if (!strcasecmp(bc_string, "alaw")) {
 103                 *target =FTDM_USER_LAYER1_PROT_ALAW ;
 104         } else {
 105                 ftdm_log(FTDM_LOG_WARNING, "Unsupported Bearer Layer1 Prot value (%s)\n", bc_string);
 106                 return FTDM_FAIL;
 107         }
 108         return FTDM_SUCCESS;
 109 }
 110 
 111 
 112 FT_DECLARE(ftdm_status_t) ftdm_is_number(char *number)
 113 {
 114         if (!number) {
 115                 return FTDM_FAIL;
 116         }
 117 
 118         for ( ; *number; number++) {
 119                 if (!isdigit(*number)) {
 120                         return FTDM_FAIL;
 121                 }
 122         }
 123         return FTDM_SUCCESS;
 124 }
 125 

/* [<][>][^][v][top][bottom][index][help] */