Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:56 2007

Asterisk developer's documentation :: Codename Pineapple


sip3_callerid.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2007, Digium, Inc.
00005  * and Edvina AB, Sollentuna, Sweden (chan_sip3 changes/additions)
00006  *
00007  * Mark Spencer <markster@digium.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 /*!
00021  * \file
00022  * \brief Various SIP callerid functions
00023  * Version 3 of chan_sip
00024  *
00025  * \author Mark Spencer <markster@digium.com>
00026  * \author Olle E. Johansson <oej@edvina.net> (all the chan_sip3 changes)
00027  *
00028  * See Also:
00029  * \arg \ref AstCREDITS
00030  *
00031  */
00032 
00033 #include "asterisk.h"
00034 
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 53128 $")
00036 
00037 #include <stdio.h>
00038 #include <ctype.h>
00039 #include <string.h>
00040 #include <unistd.h>
00041 #include <sys/socket.h>
00042 #include <sys/ioctl.h>
00043 #include <net/if.h>
00044 #include <errno.h>
00045 #include <stdlib.h>
00046 #include <fcntl.h>
00047 #include <netdb.h>
00048 #include <signal.h>
00049 #include <sys/signal.h>
00050 #include <netinet/in.h>
00051 #include <netinet/in_systm.h>
00052 #include <arpa/inet.h>
00053 #include <netinet/ip.h>
00054 #include <regex.h>
00055 
00056 #include "asterisk/lock.h"
00057 #include "asterisk/channel.h"
00058 #include "asterisk/config.h"
00059 #include "asterisk/logger.h"
00060 #include "asterisk/module.h"
00061 #include "asterisk/pbx.h"
00062 #include "asterisk/options.h"
00063 #include "asterisk/sched.h"
00064 #include "asterisk/io.h"
00065 #include "asterisk/rtp.h"
00066 #include "asterisk/udptl.h"
00067 #include "asterisk/acl.h"
00068 #include "asterisk/callerid.h"
00069 #include "asterisk/app.h"
00070 #include "asterisk/astdb.h"
00071 #include "asterisk/causes.h"
00072 #include "asterisk/utils.h"
00073 #include "asterisk/file.h"
00074 #include "asterisk/astobj.h"
00075 #include "asterisk/dnsmgr.h"
00076 #include "asterisk/linkedlists.h"
00077 #include "asterisk/manager.h"
00078 #include "asterisk/monitor.h"
00079 #include "asterisk/localtime.h"
00080 #include "asterisk/compiler.h"
00081 #include "sip3.h"
00082 #include "sip3funcs.h"
00083 
00084 /*! \brief helper function for check_{user|peer}_ok() */
00085 void replace_cid(struct sip_dialog *p, const char *rpid_num, const char *calleridname)
00086 {
00087    /* replace callerid if rpid found, and not restricted */
00088    if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) {
00089       char *tmp = ast_strdupa(rpid_num); /* XXX the copy can be done later */
00090       if (!ast_strlen_zero(calleridname))
00091          ast_string_field_set(p, cid_name, calleridname);
00092       if (ast_is_shrinkable_phonenumber(tmp))
00093          ast_shrink_phone_number(tmp);
00094       ast_string_field_set(p, cid_num, tmp);
00095    }
00096 }
00097 
00098 /*! \brief  Get caller id number from Remote-Party-ID header field 
00099  * Returns true if number should be restricted (privacy setting found)
00100  * output is set to NULL if no number found
00101  */
00102 int get_rpid_num(const char *input, char *output, int maxlen)
00103 {
00104    char *start;
00105    char *end;
00106 
00107    start = strchr(input,':');
00108    if (!start) {
00109       output[0] = '\0';
00110       return 0;
00111    }
00112    start++;
00113 
00114    /* we found "number" */
00115    ast_copy_string(output,start,maxlen);
00116    output[maxlen-1] = '\0';
00117 
00118    end = strchr(output,'@');
00119    if (end)
00120       *end = '\0';
00121    else
00122       output[0] = '\0';
00123    if (strstr(input,"privacy=full") || strstr(input,"privacy=uri"))
00124       return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
00125 
00126    return 0;
00127 }
00128 
00129 /*! \brief  Get caller id name from SIP headers */
00130 char *get_calleridname(const char *input, char *output, size_t outputsize)
00131 {
00132    const char *end = strchr(input,'<');   /* first_bracket */
00133    const char *tmp = strchr(input,'"');   /* first quote */
00134    int bytes = 0;
00135    int maxbytes = outputsize - 1;
00136 
00137    if (!end || end == input)  /* we require a part in brackets */
00138       return NULL;
00139 
00140    /* move away from "<" */
00141    end--;
00142 
00143    /* we found "name" */
00144    if (tmp && tmp < end) {
00145       end = strchr(tmp+1, '"');
00146       if (!end)
00147          return NULL;
00148       bytes = (int) (end - tmp);
00149       /* protect the output buffer */
00150       if (bytes > maxbytes)
00151          bytes = maxbytes;
00152       ast_copy_string(output, tmp + 1, bytes);
00153    } else {
00154       /* we didn't find "name" */
00155       /* clear the empty characters in the begining*/
00156       input = ast_skip_blanks(input);
00157       /* clear the empty characters in the end */
00158       while(*end && *end < 33 && end > input)
00159          end--;
00160       if (end >= input) {
00161          bytes = (int) (end - input) + 2;
00162          /* protect the output buffer */
00163          if (bytes > maxbytes)
00164             bytes = maxbytes;
00165          ast_copy_string(output, input, bytes);
00166       } else
00167          return NULL;
00168    }
00169    return output;
00170 }

Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen