Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:50 2007

Asterisk developer's documentation :: Codename Pineapple


sip3_callerid.c File Reference


Detailed Description

Various SIP callerid functions Version 3 of chan_sip.

Author:
Mark Spencer <markster@digium.com>

Olle E. Johansson <oej@edvina.net> (all the chan_sip3 changes)

See Also:

Definition in file sip3_callerid.c.

#include "asterisk.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <sys/signal.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <regex.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/app.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj.h"
#include "asterisk/dnsmgr.h"
#include "asterisk/linkedlists.h"
#include "asterisk/manager.h"
#include "asterisk/monitor.h"
#include "asterisk/localtime.h"
#include "asterisk/compiler.h"
#include "sip3.h"
#include "sip3funcs.h"

Include dependency graph for sip3_callerid.c:

Go to the source code of this file.

Functions

char * get_calleridname (const char *input, char *output, size_t outputsize)
 Get caller id name from SIP headers.
int get_rpid_num (const char *input, char *output, int maxlen)
 Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found.
void replace_cid (struct sip_dialog *p, const char *rpid_num, const char *calleridname)
 helper function for check_{user|peer}_ok()


Function Documentation

char* get_calleridname const char *  input,
char *  output,
size_t  outputsize
 

Get caller id name from SIP headers.

Definition at line 130 of file sip3_callerid.c.

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 }

int get_rpid_num const char *  input,
char *  output,
int  maxlen
 

Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found.

Definition at line 102 of file sip3_callerid.c.

References AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED.

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 }

void replace_cid struct sip_dialog p,
const char *  rpid_num,
const char *  calleridname
 

helper function for check_{user|peer}_ok()

Definition at line 85 of file sip3_callerid.c.

References ast_is_shrinkable_phonenumber(), ast_shrink_phone_number(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, cid_name, cid_num, sip_dialog::flags, and SIP_TRUSTRPID.

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 }


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