Commit aa7034bd authored by Devon Kearns's avatar Devon Kearns

Imported Upstream version 3.3

parents
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors : Benjamin GAUTHIER - 24 Mar 2004
* Joseph BANINO
* Olivier JACQUES
* Richard GAYRAUD
* From Hewlett Packard Company.
*/
#ifndef _CACTIONS
#define _CACTIONS
#include "variables.hpp"
#include "message.hpp"
class CSample;
#ifdef PCAPPLAY
#include "prepare_pcap.h"
#endif
#define MAX_ACTION_MESSAGE 3
class CAction
{
public:
enum T_ActionType
{
E_AT_NO_ACTION = 0,
E_AT_ASSIGN_FROM_REGEXP,
E_AT_CHECK,
E_AT_ASSIGN_FROM_VALUE,
E_AT_ASSIGN_FROM_SAMPLE,
E_AT_ASSIGN_FROM_STRING,
E_AT_ASSIGN_FROM_INDEX,
E_AT_ASSIGN_FROM_GETTIMEOFDAY,
E_AT_JUMP,
E_AT_LOOKUP,
E_AT_INSERT,
E_AT_REPLACE,
E_AT_PAUSE_RESTORE,
E_AT_LOG_TO_FILE,
E_AT_LOG_WARNING,
E_AT_LOG_ERROR,
E_AT_EXECUTE_CMD,
E_AT_EXEC_INTCMD,
E_AT_VAR_ADD,
E_AT_VAR_SUBTRACT,
E_AT_VAR_MULTIPLY,
E_AT_VAR_DIVIDE,
E_AT_VAR_TEST,
E_AT_VAR_TO_DOUBLE,
E_AT_VAR_STRCMP,
E_AT_VAR_TRIM,
E_AT_VERIFY_AUTH,
E_AT_SET_DEST,
E_AT_CLOSE_CON,
#ifdef PCAPPLAY
E_AT_PLAY_PCAP_AUDIO,
E_AT_PLAY_PCAP_VIDEO,
#endif
E_AT_NB_ACTION
};
enum T_LookingPlace
{
E_LP_MSG = 0,
E_LP_HDR,
E_LP_BODY,
E_LP_VAR,
E_LP_NB_LOOKING_PLACE
};
enum T_Comparator
{
E_C_EQ,
E_C_NE,
E_C_GT,
E_C_LT,
E_C_GEQ,
E_C_LEQ,
E_C_NB_COMPARATOR
};
enum T_IntCmdType
{
E_INTCMD_INVALID = 0,
E_INTCMD_STOPCALL,
E_INTCMD_STOP_ALL,
E_INTCMD_STOP_NOW
};
typedef struct _T_Action
{
} T_Action;
void afficheInfo();
const char *comparatorToString(T_Comparator comp);
bool compare(VariableTable *variableTable);
T_ActionType getActionType();
T_VarType getVarType();
T_LookingPlace getLookingPlace();
T_Comparator getComparator();
bool getCheckIt();
bool getCheckItInverse();
bool getCaseIndep();
bool getHeadersOnly();
int getVarId();
int getVarInId();
int getVarIn2Id();
int getOccurence();
char* getLookingChar();
char* getRegularExpression();
SendingMessage *getMessage(int n = 0); /* log specific function */
T_IntCmdType getIntCmd(); /* exec specific function */
#ifdef PCAPPLAY
pcap_pkts *getPcapPkts(); /* send_packets specific function */
#endif
void setActionType (T_ActionType P_value);
void setLookingPlace (T_LookingPlace P_value);
void setComparator (T_Comparator P_value);
void setCheckIt (bool P_value);
void setCheckItInverse (bool P_value);
void setVarId (int P_value);
void setVarInId (int P_value);
void setVarIn2Id (int P_value);
void setLookingChar (char* P_value);
void setAction (CAction P_action);
void setCaseIndep (bool P_action);
void setOccurence (int P_value);
void setHeadersOnly (bool P_value);
void setScenario (scenario * P_scenario);
void setRegExp (char* P_value); /* ereg specific function. */
int executeRegExp (char* P_string, VariableTable *P_callVarTable);
void setMessage (char* P_value, int n = 0); /* log specific function */
void setIntCmd (T_IntCmdType P_type ); /* exec specific function */
void setDistribution (CSample * P_value); /* sample specific function */
void setDoubleValue (double P_value); /* assign value specific function */
void setStringValue (char * P_value); /* strcmp value specific function */
#ifdef PCAPPLAY
void setPcapArgs (char * P_value); /* send_packets specific function */
void setPcapArgs (pcap_pkts * P_value); /* send_packets specific function */
#endif
void setSubVarId (int P_value);
int getSubVarId (int P_index);
void setNbSubVarId (int P_value);
int getNbSubVarId ();
int* getSubVarId() ;
CSample *getDistribution (); /* sample specific function */
double getDoubleValue (); /* assign value specific function */
char * getStringValue (); /* strcmp specific function */
CAction(scenario *scenario);
~CAction();
private:
T_ActionType M_action;
T_LookingPlace M_lookingPlace;
T_Comparator M_comp;
bool M_checkIt;
bool M_checkItInverse;
bool M_caseIndep;
bool M_headersOnly;
int M_varId;
int M_varInId;
int M_varIn2Id;
int M_occurence;
int M_nbSubVarId;
int M_maxNbSubVarId;
int * M_subVarId;
char* M_lookingChar;
/* log specific member */
SendingMessage *M_message[MAX_ACTION_MESSAGE];
char * M_message_str[MAX_ACTION_MESSAGE];
/* exec specific member */
T_IntCmdType M_IntCmd;
/* sample specific member. */
CSample *M_distribution;
/* assign value specific member. */
double M_doubleValue;
/* strcmp specific member. */
char * M_stringValue;
/* what scenario we belong to. */
scenario * M_scenario;
/* Our regular expression. */
bool M_regExpSet;
regex_t M_internalRegExp;
char * M_regularExpression;
#ifdef PCAPPLAY
/* pcap specific member */
pcap_pkts * M_pcapArgs;
#endif
void setSubString(char** P_target, char* P_source, int P_start, int P_stop);
};
class CActions
{
public:
void afficheInfo();
void setAction(CAction *P_action);
void reset();
int getActionSize();
CAction* getAction(int i);
CActions();
~CActions();
private:
CAction ** M_actionList;
int M_nbAction;
int M_currentSettedAction;
};
#endif
# ======================== initialization ===============================
AC_INIT([SIPp], [3.1], [sipp-users@lists.sourceforge.net], [sipp])
AC_CANONICAL_TARGET
AC_CONFIG_SRCDIR([sipp.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign dist-xz])
AC_ARG_WITH([openssl],AC_HELP_STRING([--with-openssl], [build with OpenSSL support]), [openssl="$withval"],[openssl="no"])
AC_ARG_WITH([pcap],AC_HELP_STRING([--with-pcap], [build with pcap support]), [pcap="$withval"],[pcap="no"])
AC_ARG_WITH([unittest],AC_HELP_STRING([--with-unittest], [build with unit testing framework]), [unittest="$withval"],[unittest="no"])
AC_ARG_WITH([sctp],AC_HELP_STRING([--with-sctp], [build with SCTP support]), [sctp="$withval"],[sctp="no"])
# ==================== basic compiler settings ==========================
AC_PROG_CC
AC_PROG_CXX
AC_HEADER_STDC
case "$host" in
*-linux*)
CFLAGS="$CFLAGS -D__LINUX"
CPPFLAGS="$CPPFLAGS -D__LINUX"
;;
*-darwin*)
CFLAGS="$CFLAGS -D__DARWIN"
CPPFLAGS="$CPPFLAGS -D__DARWIN"
;;
*-hpux*)
CFLAGS="$CFLAGS -D__HPUX"
CPPFLAGS="$CPPFLAGS -D__HPUX"
;;
*-freebsd*)
CFLAGS="$CFLAGS -D__LINUX"
CPPFLAGS="$CPPFLAGS -D__LINUX"
;;
*-sunos*)
CFLAGS="$CFLAGS -D__SUNOS"
CPPFLAGS="$CPPFLAGS -D__SUNOS"
;;
*-cygwin*)
CFLAGS="$CFLAGS -D__CYGWIN"
CPPFLAGS="$CPPFLAGS -D__CYGWIN"
;;
*-tru64*)
CFLAGS="$CFLAGS -D__OSF1"
CPPFLAGS="$CPPFLAGS -D__OSF1"
;;
esac
# ==================== checks for libraries =============================
AC_CHECK_LIB(curses,initscr,,[AC_MSG_ERROR([ncurses library missing])])
AC_CHECK_LIB(pthread, pthread_mutex_init, THREAD_LIBS="-lpthread",
AC_MSG_ERROR(pthread library needed!))
# For Linux and SunOS
AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([dlerror], [dl])
AC_SEARCH_LIBS([dlsym], [dl])
# For SunOS
AC_SEARCH_LIBS([inet_addr], [nsl])
AC_SEARCH_LIBS([inet_ntoa], [nsl])
AC_SEARCH_LIBS([pthread_mutex_init], [pthread])
AC_SEARCH_LIBS([pthread_mutex_destroy], [pthread])
AC_SEARCH_LIBS([pthread_mutex_lock], [pthread])
AC_SEARCH_LIBS([pthread_mutex_unlock], [pthread])
AC_SEARCH_LIBS([pthread_self], [pthread])
AC_SEARCH_LIBS([pthread_cancel], [pthread])
AC_SEARCH_LIBS([pthread_join], [pthread])
AC_SEARCH_LIBS([pthread_attr_init], [pthread])
AC_SEARCH_LIBS([pthread_attr_setstacksize], [pthread])
AC_SEARCH_LIBS([pthread_create], [pthread])
AC_SEARCH_LIBS([pthread_attr_destroy], [pthread])
AC_SEARCH_LIBS([pthread_setschedparam], [pthread])
AC_SEARCH_LIBS([pthread_setcancelstate], [pthread])
AC_SEARCH_LIBS([pthread_setcanceltype], [pthread])
AC_SEARCH_LIBS([pthread_exit], [pthread])
AC_SEARCH_LIBS([pthread_sigmask], [pthread])
#AC_SEARCH_LIBS([pthread_cleanup_push], [pthread]) <- macro
#AC_SEARCH_LIBS([pthread_cleanup_pop], [pthread]) <- macro
AC_SEARCH_LIBS([floor], [m])
AC_SEARCH_LIBS([pow], [m])
# For SunOS
AC_SEARCH_LIBS([htons], [socket])
AC_SEARCH_LIBS([ntohs], [socket])
AC_SEARCH_LIBS([bind], [socket])
AC_SEARCH_LIBS([freeaddrinfo], [socket])
AC_SEARCH_LIBS([getaddrinfo], [socket])
AC_SEARCH_LIBS([listen], [socket])
AC_SEARCH_LIBS([recvfrom], [socket])
AC_SEARCH_LIBS([shutdown], [socket])
# For Linux, SunOS and Cygwin
#AC_CHECK_LIB(stdc++,main,,[AC_MSG_ERROR([stdc++ library missing])])
# Conditional build with OpenSSL
if test "$openssl" = 'yes'; then
AC_CHECK_HEADERS([openssl/md5.h],,[AC_MSG_ERROR([<openssl/md5.h> header missing])])
AC_CHECK_HEADERS([openssl/bio.h],,[AC_MSG_ERROR([<openssl/bio.h> header missing])])
AC_CHECK_HEADERS([openssl/err.h],,[AC_MSG_ERROR([<openssl/err.h> header missing])])
AC_CHECK_HEADERS([openssl/rand.h],,[AC_MSG_ERROR([<openssl/rand.h> header missing])])
AC_CHECK_HEADERS([openssl/ssl.h],,[AC_MSG_ERROR([<openssl/ssl.h> header missing])])
AC_CHECK_HEADERS([openssl/x509v3.h],,[AC_MSG_ERROR([<openssl/x509v3.h> header missing])])
AC_CHECK_LIB([ssl], [SSL_library_init],,[AC_MSG_ERROR([ssl library missing])])
AC_CHECK_LIB([crypto], [CRYPTO_num_locks],,[AC_MSG_ERROR([crypto library missing])])
fi
# For Makefile.am
AM_CONDITIONAL(HAVE_OPENSSL, test "$openssl" = "yes")
# Conditional build with SCTP
if test "$sctp" = 'yes'; then
AC_CHECK_HEADERS([netinet/sctp.h],,[AC_MSG_ERROR([<netinet/sctp.h> header missing])])
AC_SEARCH_LIBS([sctp_send],[sctp],,[AC_MSG_ERROR([SCTP library missing])])
AC_SEARCH_LIBS([sctp_getpaddrs],[sctp],,[AC_MSG_ERROR([SCTP library missing])])
AC_SEARCH_LIBS([sctp_freepaddrs],[sctp],,[AC_MSG_ERROR([SCTP library missing])])
AC_SEARCH_LIBS([sctp_bindx],[sctp],,[AC_MSG_ERROR([SCTP library missing])])
AC_SEARCH_LIBS([sctp_recvmsg],[sctp],,[AC_MSG_ERROR([SCTP library missing])])
fi
# For Makefile.am
AM_CONDITIONAL(HAVE_SCTP, test "$sctp" = "yes")
# Conditional build with pcap
if test "$pcap" = 'yes'; then
AC_CHECK_HEADERS([pcap.h],,[AC_MSG_ERROR([<pcap.h> header missing])])
AC_CHECK_LIB([pcap], [pcap_open_offline],,[AC_MSG_ERROR([pcap library missing])])
AC_CHECK_LIB([pcap], [pcap_next],,[AC_MSG_ERROR([pcap library missing])])
AC_CHECK_LIB([pcap], [pcap_next_ex],,[AC_MSG_ERROR([pcap library missing])])
AC_CHECK_LIB([pcap], [pcap_close],,[AC_MSG_ERROR([pcap library missing])])
fi
# For Makefile.am
AM_CONDITIONAL(HAVE_PCAP, test "$pcap" = "yes")
AM_CONDITIONAL(HAVE_UNITTEST, test "$unittest" = "yes")
# ==================== checks for header files ==========================
AC_FUNC_ALLOCA
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
# ===== checks for typedefs, structures and compiler characteristics ====
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# ==================== checks for library functions =====================
AC_FUNC_FORK
#AC_FUNC_MALLOC
#AC_FUNC_REALLOC
#AC_FUNC_STRTOD
AC_CHECK_FUNCS([alarm dup2 floor gethostname gettimeofday inet_ntoa memmove memset pow regcomp socket sqrt strcasecmp strchr strcspn strdup strerror strncasecmp strrchr strstr strtol strtoul strtoull])
# ==================== generate files ===================================
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003 - The Authors
*
* Author : Richard GAYRAUD - 04 Nov 2003
* From Hewlett Packard Company.
*/
#ifdef __cplusplus
extern "C" {
#endif
int xp_replace(char *source, char *dest, char *search, char *replace);
int xp_set_xml_buffer_from_string(char * str);
int xp_set_xml_buffer_from_file(char * filename);
char * xp_open_element(int index);
void xp_close_element();
int xp_search_element_from_name(char * element, int occurence);
char * xp_get_value(const char * name);
char * xp_get_cdata();
int xp_get_content_length(char * P_buffer);
#ifdef __cplusplus
}
#endif
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003 - The Authors
*
* Author : Richard GAYRAUD - 04 Nov 2003
* From Hewlett Packard Company.
*
*/
#define COMP_MAIN
#include "comp.h"
#include <dlfcn.h>
#include <string.h>
char * comp_load()
{
void *handle;
char *error;
comp_error[0] = 0;
handle = dlopen(COMP_PLUGGIN, RTLD_LAZY);
if (!handle) {
strcpy(comp_error, dlerror());
return comp_error;
}
*(void **)(&comp_compress) = dlsym(handle, "comp_compress");
if((error = (char *) dlerror()))
{ strcpy(comp_error, error); return comp_error; }
*(void **)(&comp_uncompress) = dlsym(handle, "comp_uncompress");
if((error = (char *) dlerror()))
{ strcpy(comp_error, error); return comp_error; }
*(void **)(&comp_free) = dlsym(handle, "comp_free");
if((error = (char *) dlerror()))
{ strcpy(comp_error, error); return comp_error; }
return 0;
}
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author : Guillaume TEISSIER from FTR&D 02/02/2006
*/
#ifndef PREPARE_PCAP_H
#define PREPARE_PCAP_H 1
#include <pcap.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <time.h>
#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
struct iphdr
{
#ifdef _HPUX_LI
unsigned int ihl:4;
unsigned int version:4;
#else
unsigned int version:4;
unsigned int ihl:4;
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};
#endif
typedef struct
{
u_char *data;
u_long pktlen;
struct timeval ts;
int partial_check;
} pcap_pkt;
#define PCAP_MAXPACKET 1500
typedef struct
{
char *file;
u_int16_t base;
u_long max_length;
pcap_pkt *max;
pcap_pkt *pkts;
} pcap_pkts;
#ifdef __cplusplus
extern "C" {
#endif
int check(u_int16_t *, int);
u_int16_t checksum_carry(int);
int prepare_pkts(char *, pcap_pkts *);
void free_pkts(pcap_pkts *);
#ifdef __cplusplus
}
#endif
#endif /* PREPARE_PCAP_H */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author : Richard GAYRAUD - 04 Nov 2003
* From Hewlett Packard Company.
* Charles P. Wright from IBM Research
*/
#ifndef __LISTENER__
#define __LISTENER__
#include <map>
#include <iterator>
#include <list>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include "sipp.hpp"
class listener {
public:
listener(char *id, bool listening);
virtual ~listener();
char *getId();
virtual bool process_incoming(char * msg, struct sockaddr_storage *src) = 0;
virtual bool process_twinSippCom(char * msg) = 0;
protected:
void startListening();
void stopListening();
char *id;
bool listening;
};
typedef std::map<std::string, listener *> listener_map;
listener * get_listener(char *);
#endif
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003 - The Authors