Codename Pineapple

Home page | Mailing list | Docs

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

Asterisk developer's documentation :: Codename Pineapple


sip3_utils.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2006  Edvina AB, Sollentuna, Sweden (chan_sip3 changes/additions)
00005  * and Edvina AB, Sollentuna, Sweden (chan_sip3 changes/additions)
00006  *
00007  * Olle E. Johansson
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 utility functions
00023  *
00024  * Version 3 of chan_sip
00025  *
00026  * \author Olle E. Johansson <oej@edvina.net> 
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/lock.h"
00064 #include "asterisk/sched.h"
00065 #include "asterisk/io.h"
00066 #include "asterisk/manager.h"
00067 #include "asterisk/acl.h"
00068 #include "asterisk/utils.h"
00069 #include "asterisk/file.h"
00070 #include "asterisk/astobj.h"
00071 #include "asterisk/dnsmgr.h"
00072 #include "asterisk/linkedlists.h"
00073 #include "asterisk/stringfields.h"
00074 #include "asterisk/monitor.h"
00075 #include "asterisk/localtime.h"
00076 #include "asterisk/compiler.h"
00077 #include "sip3.h"
00078 #include "sip3funcs.h"
00079 
00080 
00081 GNURK void logdebug(int level, const char *fmt, ...)
00082    __attribute__ ((format (printf, 2, 3)));
00083 
00084 /*! \brief Output message to LOG_DEBUG channel */
00085 static void logdebug_va(int level, const char *fmt, va_list ap)
00086 {
00087    if (option_debug >= level)
00088       ast_log(LOG_DEBUG, fmt, ap);
00089 }
00090 
00091 /*! \brief Append to SIP dialog history with arg list  */
00092 GNURK void logdebug(int level, const char *fmt, ...)
00093 {
00094    va_list ap;
00095 
00096    va_start(ap, fmt);
00097    logdebug_va(level, fmt, ap);
00098    va_end(ap);
00099 
00100    return;
00101 }
00102 
00103 GNURK void append_history_full(struct sip_dialog *p, const char *fmt, ...)
00104    __attribute__ ((format (printf, 2, 3)));
00105 
00106 /*! \brief Append to SIP dialog history with arg list  */
00107 GNURK void append_history_va(struct sip_dialog *p, const char *fmt, va_list ap)
00108 {
00109    char buf[80], *c = buf; /* max history length */
00110    struct sip_history *hist;
00111    int l;
00112 
00113    vsnprintf(buf, sizeof(buf), fmt, ap);
00114    strsep(&c, "\r\n"); /* Trim up everything after \r or \n */
00115    l = strlen(buf) + 1;
00116    if (!(hist = ast_calloc(1, sizeof(*hist) + l)))
00117       return;
00118    if (!p->history && !(p->history = ast_calloc(1, sizeof(*p->history)))) {
00119       free(hist);
00120       return;
00121    }
00122    memcpy(hist->event, buf, l);
00123    AST_LIST_INSERT_TAIL(p->history, hist, list);
00124 }
00125 
00126 /*! \brief Append to SIP dialog history with arg list  */
00127 GNURK void append_history_full(struct sip_dialog *dialog, const char *fmt, ...)
00128 {
00129    va_list ap;
00130 
00131    if (!dialog)
00132       return;
00133    va_start(ap, fmt);
00134    append_history_va(dialog, fmt, ap);
00135    va_end(ap);
00136 
00137    return;
00138 }
00139 
00140 /*! \brief Dump SIP history to debug log file at end of lifespan for SIP dialog */
00141 GNURK void sip_dump_history(struct sip_dialog *dialog)
00142 {
00143    int x = 0;
00144    struct sip_history *hist;
00145 
00146    if (!dialog)
00147       return;
00148 
00149    if (!option_debug && !sipdebug) {
00150       ast_log(LOG_NOTICE, "You must have debugging enabled (SIP or Asterisk) in order to dump SIP history.\n");
00151       return;
00152    }
00153 
00154    ast_log(LOG_DEBUG, "\n---------- SIP HISTORY for '%s' \n", dialog->callid);
00155    if (dialog->subscribed)
00156       ast_log(LOG_DEBUG, "  * Subscription\n");
00157    else
00158       ast_log(LOG_DEBUG, "  * SIP Call\n");
00159    if (dialog->history)
00160       AST_LIST_TRAVERSE(dialog->history, hist, list)
00161          ast_log(LOG_DEBUG, "  %-3.3d. %s\n", ++x, hist->event);
00162    if (!x)
00163       ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
00164    ast_log(LOG_DEBUG, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid);
00165 }
00166 

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