提交 5d071029 authored 作者: Brian West's avatar Brian West

unsupported

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16460 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 114cea72
include $(top_srcdir)/build/modmake.rulesam
MODNAME=mod_iax
mod_LTLIBRARIES = mod_iax.la
mod_iax_la_SOURCES = mod_iax.c iax2-parser.c iax.c md5.c jitterbuf.c iax-mutex.c
mod_iax_la_CFLAGS = $(AM_CFLAGS) -I. -DNEWJB -DLIBIAX -DDEBUG_SUPPORT
mod_iax_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_iax_la_LDFLAGS = -avoid-version -module -no-undefined -shared
差异被折叠。
/*
* libiax: An implementation of the Inter-Asterisk eXchange protocol
*
* Asterisk internal frame definitions.
*
* Copyright (C) 1999, Mark Spencer
*
* Mark Spencer <markster@linux-support.net>
*
* This program is free software, distributed under the terms of
* the GNU Lesser General Public License. Other components of
* Asterisk are distributed under The GNU General Public License
* only.
*/
#ifndef _LIBIAX_FRAME_H
#define _LIBIAX_FRAME_H
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
/* Frame types */
#define AST_FRAME_DTMF 1 /* A DTMF digit, subclass is the digit */
#define AST_FRAME_VOICE 2 /* Voice data, subclass is AST_FORMAT_* */
#define AST_FRAME_VIDEO 3 /* Video frame, maybe?? :) */
#define AST_FRAME_CONTROL 4 /* A control frame, subclass is AST_CONTROL_* */
#define AST_FRAME_NULL 5 /* An empty, useless frame */
#define AST_FRAME_IAX 6 /* Inter Aterisk Exchange private frame type */
#define AST_FRAME_TEXT 7 /* Text messages */
#define AST_FRAME_IMAGE 8 /* Image Frames */
#define AST_FRAME_HTML 9 /* HTML Frames */
#define AST_FRAME_CNG 10 /* Comfort Noise frame (subclass is level of CNG in -dBov) */
/* HTML subclasses */
#define AST_HTML_URL 1 /* Sending a URL */
#define AST_HTML_DATA 2 /* Data frame */
#define AST_HTML_BEGIN 4 /* Beginning frame */
#define AST_HTML_END 8 /* End frame */
#define AST_HTML_LDCOMPLETE 16 /* Load is complete */
#define AST_HTML_NOSUPPORT 17 /* Peer is unable to support HTML */
#define AST_HTML_LINKURL 18 /* Send URL and track */
#define AST_HTML_UNLINK 19 /* Request no more linkage */
#define AST_HTML_LINKREJECT 20 /* Reject LINKURL */
/* Data formats for capabilities and frames alike */
/*! G.723.1 compression */
#define AST_FORMAT_G723_1 (1 << 0)
/*! GSM compression */
#define AST_FORMAT_GSM (1 << 1)
/*! Raw mu-law data (G.711) */
#define AST_FORMAT_ULAW (1 << 2)
/*! Raw A-law data (G.711) */
#define AST_FORMAT_ALAW (1 << 3)
/*! ADPCM (G.726, 32kbps) */
#define AST_FORMAT_G726 (1 << 4)
/*! ADPCM (IMA) */
#define AST_FORMAT_ADPCM (1 << 5)
/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
#define AST_FORMAT_SLINEAR (1 << 6)
/*! LPC10, 180 samples/frame */
#define AST_FORMAT_LPC10 (1 << 7)
/*! G.729A audio */
#define AST_FORMAT_G729A (1 << 8)
/*! SpeeX Free Compression */
#define AST_FORMAT_SPEEX (1 << 9)
/*! iLBC Free Compression */
#define AST_FORMAT_ILBC (1 << 10)
/*! Maximum audio format */
#define AST_FORMAT_MAX_AUDIO (1 << 15)
/*! JPEG Images */
#define AST_FORMAT_JPEG (1 << 16)
/*! PNG Images */
#define AST_FORMAT_PNG (1 << 17)
/*! H.261 Video */
#define AST_FORMAT_H261 (1 << 18)
/*! H.263 Video */
#define AST_FORMAT_H263 (1 << 19)
/*! Max one */
#define AST_FORMAT_MAX_VIDEO (1 << 24)
/* Control frame types */
#define AST_CONTROL_HANGUP 1 /* Other end has hungup */
#define AST_CONTROL_RING 2 /* Local ring */
#define AST_CONTROL_RINGING 3 /* Remote end is ringing */
#define AST_CONTROL_ANSWER 4 /* Remote end has answered */
#define AST_CONTROL_BUSY 5 /* Remote end is busy */
#define AST_CONTROL_TAKEOFFHOOK 6 /* Make it go off hook */
#define AST_CONTROL_OFFHOOK 7 /* Line is off hook */
#define AST_CONTROL_CONGESTION 8 /* Congestion (circuits busy) */
#define AST_CONTROL_FLASH 9 /* Flash hook */
#define AST_CONTROL_WINK 10 /* Wink */
#define AST_CONTROL_OPTION 11 /* Set an option */
#define AST_FRIENDLY_OFFSET 64 /* Reserved header space */
struct ast_frame {
/*! Kind of frame */
int frametype;
/*! Subclass, frame dependent */
int subclass;
/*! Length of data */
int datalen;
/*! Number of 8khz samples in this frame */
int samples;
/*! Was the data malloc'd? i.e. should we free it when we discard the f
rame? */
int mallocd;
/*! How far into "data" the data really starts */
int offset;
/*! Optional source of frame for debugging */
char *src;
/*! Pointer to actual data */
void *data;
/*! Next/Prev for linking stand alone frames */
struct ast_frame *prev;
/*! Next/Prev for linking stand alone frames */
struct ast_frame *next;
/* Unused except
if debugging is turned on, but left
in the struct
so that it can be turned on without
requiring a r
ecompile of the whole thing */
};
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif
/*
* Asterisk -- A telephony toolkit for Linux.
*
* Implementation of Inter-Asterisk eXchange
*
* Copyright (C) 1999, Mark Spencer
*
* Mark Spencer <markster@linux-support.net>
*
* This program is free software, distributed under the terms of
* the GNU Lesser General Public License (LGPL)
*/
#ifndef _ASTERISK_IAX_CLIENT_H
#define _ASTERISK_IAX_CLIENT_H
#ifdef WIN32_TIME_GET_TIME
#include <Mmsystem.h>
#endif
#if defined(_MSC_VER)
/* disable zero-sized array in struct/union warning */
#pragma warning(disable:4200)
#endif
#if !defined(LINUX) && !defined(__NetBSD__)
#define socklen_t int
#endif
#include "frame.h"
#include "iax2.h"
#include "iax2-parser.h"
#define MAXSTRLEN 80
#define IAX_AUTHMETHOD_PLAINTEXT IAX_AUTH_PLAINTEXT
#define IAX_AUTHMETHOD_MD5 IAX_AUTH_MD5
extern char iax_errstr[];
struct iax_session;
#define IAX_EVENT_CONNECT 0 /* Connect a new call */
#define IAX_EVENT_ACCEPT 1 /* Accept a call */
#define IAX_EVENT_HANGUP 2 /* Hang up a call */
#define IAX_EVENT_REJECT 3 /* Rejected call */
#define IAX_EVENT_VOICE 4 /* Voice Data */
#define IAX_EVENT_DTMF 5 /* A DTMF Tone */
#define IAX_EVENT_TIMEOUT 6 /* Connection timeout... session will be
a pointer to free()'d memory! */
#define IAX_EVENT_LAGRQ 7 /* Lag request -- Internal use only */
#define IAX_EVENT_LAGRP 8 /* Lag Measurement. See event.lag */
#define IAX_EVENT_RINGA 9 /* Announce we/they are ringing */
#define IAX_EVENT_PING 10 /* Ping -- internal use only */
#define IAX_EVENT_PONG 11 /* Pong -- internal use only */
#define IAX_EVENT_BUSY 12 /* Report a line busy */
#define IAX_EVENT_ANSWER 13 /* Answer the line */
#define IAX_EVENT_IMAGE 14 /* Send/Receive an image */
#define IAX_EVENT_AUTHRQ 15 /* Authentication request */
#define IAX_EVENT_AUTHRP 16 /* Authentication reply */
#define IAX_EVENT_REGREQ 17 /* Registration request */
#define IAX_EVENT_REGACK 18 /* Registration reply */
#define IAX_EVENT_URL 19 /* URL received */
#define IAX_EVENT_LDCOMPLETE 20 /* URL loading complete */
#define IAX_EVENT_TRANSFER 21 /* Transfer has taken place */
#define IAX_EVENT_DPREQ 22 /* Dialplan request */
#define IAX_EVENT_DPREP 23 /* Dialplan reply */
#define IAX_EVENT_DIAL 24 /* Dial on a TBD call */
#define IAX_EVENT_QUELCH 25 /* Quelch Audio */
#define IAX_EVENT_UNQUELCH 26 /* Unquelch Audio */
#define IAX_EVENT_UNLINK 27 /* Unlink */
#define IAX_EVENT_LINKREJECT 28 /* Link Rejection */
#define IAX_EVENT_TEXT 29 /* Text Frame :-) */
#define IAX_EVENT_REGREJ 30 /* Registration reply */
#define IAX_EVENT_LINKURL 31 /* Unlink */
#define IAX_EVENT_CNG 32 /* Comfort-noise (almost silence) */
#define IAX_EVENT_POKE 33
/* moved from iax.c to support attended transfer */
#define IAX_EVENT_REREQUEST 999
#define IAX_EVENT_TXREPLY 1000
#define IAX_EVENT_TXREJECT 1001
#define IAX_EVENT_TXACCEPT 1002
#define IAX_EVENT_TXREADY 1003
#define IAX_SCHEDULE_FUZZ 0 /* ms of fuzz to drop */
#ifdef WIN32
#if defined(_MSC_VER)
typedef int (__stdcall *sendto_t)(SOCKET, const char *, int, int, const struct sockaddr *, int);
typedef int (__stdcall *recvfrom_t)(SOCKET, char *, int, int, struct sockaddr *, int *);
#else
typedef int PASCAL (*sendto_t)(SOCKET, const char *, int, int, const struct sockaddr *, int);
typedef int PASCAL (*recvfrom_t)(SOCKET, char *buf, int len, int flags, struct sockaddr *from, int *fromlen);
#endif
#else
typedef int (*sendto_t)(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
typedef int (*recvfrom_t)(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
#endif
struct iax_event {
int etype; /* Type of event */
int subclass; /* Subclass data (event specific) */
time_in_ms_t ts; /* Timestamp */
struct iax_session *session; /* Applicable session */
int datalen; /* Length of raw data */
struct iax_ies ies; /* IE's for IAX2 frames */
unsigned char data[]; /* Raw data if applicable */
};
#if defined(__cplusplus)
extern "C"
{
#endif
/* All functions return 0 on success and -1 on failure unless otherwise
specified */
/* Called to initialize IAX structures and sockets. Returns actual
portnumber (which it will try preferred portno first, but if not
take what it can get */
extern int iax_init(char *ip, int preferredportno);
extern int iax_shutdown(void);
/* Get filedescriptor for IAX to use with select or gtk_input_add */
extern int iax_get_fd(void);
/* Find out how many milliseconds until the next scheduled event */
extern time_in_ms_t iax_time_to_next_event(void);
/* Generate a new IAX session */
extern struct iax_session *iax_session_new(void);
/* Return exactly one iax event (if there is one pending). If blocking is
non-zero, IAX will block until some event is received */
extern struct iax_event *iax_get_event(int blocking);
extern int iax_auth_reply(struct iax_session *session, char *password,
char *challenge, int methods);
/* Free an event */
extern void iax_event_free(struct iax_event *event);
struct sockaddr_in;
/* Front ends for sending events */
extern int iax_send_dtmf(struct iax_session *session, char digit);
extern int iax_send_voice(struct iax_session *session, int format, unsigned char *data, int datalen, int samples);
extern int iax_send_cng(struct iax_session *session, int level, unsigned char *data, int datalen);
extern int iax_send_image(struct iax_session *session, int format, unsigned char *data, int datalen);
extern int iax_send_url(struct iax_session *session, char *url, int link);
extern int iax_send_text(struct iax_session *session, char *text);
extern int iax_send_ping(struct iax_session *session);
extern int iax_load_complete(struct iax_session *session);
extern int iax_reject(struct iax_session *session, const char *reason);
int iax_reject_registration(struct iax_session *session, char *reason);
int iax_ack_registration(struct iax_session *session);
int iax_auth_registration(struct iax_session *session);
extern int iax_busy(struct iax_session *session);
extern int iax_congestion(struct iax_session *session);
extern int iax_hangup(struct iax_session *session, char *byemsg);
extern int iax_call(struct iax_session *session, const char *cidnum, const char *cidname, char *ich, char *lang, int wait, int format, int capability);
extern int iax_accept(struct iax_session *session, int format);
extern int iax_answer(struct iax_session *session);
extern int iax_sendurl(struct iax_session *session, char *url);
extern int iax_send_unlink(struct iax_session *session);
extern int iax_send_link_reject(struct iax_session *session);
extern int iax_ring_announce(struct iax_session *session);
extern struct sockaddr_in iax_get_peer_addr(struct iax_session *session);
extern int iax_register(struct iax_session *session, char *hostname, char *peer, char *secret, int refresh);
extern int iax_lag_request(struct iax_session *session);
extern int iax_dial(struct iax_session *session, char *number); /* Dial on a TBD call */
extern int iax_dialplan_request(struct iax_session *session, char *number); /* Request dialplan status for number */
extern int iax_quelch(struct iax_session *session);
extern int iax_unquelch(struct iax_session * session);
extern int iax_transfer(struct iax_session *session, char *number);
extern int iax_quelch_moh(struct iax_session *session, int MOH);
extern void iax_destroy(struct iax_session * session);
extern void iax_enable_debug(void);
extern void iax_disable_debug(void);
/* For attended transfer, application create a new session,
* make a call on the new session.
* On answer of the new session, call iax_setup_transfer and wait for
* IAX_EVENT_TXREADY when both sides are completed succefully or
* IAX_EVENT_TXREJECT for either side.
* If there are music on hold the it will be stopped by this library.
*/
extern int iax_setup_transfer(struct iax_session *s0, struct iax_session *s1);
struct iax_netstat {
time_in_ms_t jitter;
int losspct;
int losscnt;
int packets;
time_in_ms_t delay;
int dropped;
int ooo;
};
/* fills in rtt, and an iax_netstat structure for each of local/remote directions of call */
extern int iax_get_netstats(struct iax_session *s, time_in_ms_t *rtt, struct iax_netstat *local, struct iax_netstat *remote);
extern void iax_set_private(struct iax_session *s, void *pvt);
extern void *iax_get_private(struct iax_session *s);
extern void iax_set_sendto(struct iax_session *s, sendto_t sendto);
/* to use application networking instead of internal, set call this instead of iax_init,
* and pass in sendto and recvfrom replacements. blocking reads may not be implemented */
extern void iax_set_networking(sendto_t st, recvfrom_t rf);
/* destroy an iax session */
extern void iax_session_destroy(struct iax_session **session);
/* Handle externally received frames */
struct iax_event *iax_net_process(unsigned char *buf, int len, struct sockaddr_in *sin);
extern unsigned int iax_session_get_capability(struct iax_session *s);
extern char iax_pref_codec_add(struct iax_session *session, unsigned int format);
extern void iax_pref_codec_del(struct iax_session *session, unsigned int format);
extern int iax_pref_codec_get(struct iax_session *session, unsigned int *array, int len);
/* Fine tune jitterbuffer */
extern void iax_set_jb_target_extra( long value );
extern char *iax_get_peer_ip(struct iax_session *session);
extern char *iax_event_get_apparent_ip(struct iax_event *event);
extern void iax_set_samplerate(struct iax_session *session, unsigned short samplemask);
#if defined(__cplusplus)
}
#endif
#endif /* _ASTERISK_IAX_CLIENT_H */
/*
* Simple Mutex abstraction
* Copyright(C) 2007 Michael Jerris
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so.
*
* This work is provided under this license on an "as is" basis, without warranty of any kind,
* either expressed or implied, including, without limitation, warranties that the covered code
* is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
* risk as to the quality and performance of the covered code is with you. Should any covered
* code prove defective in any respect, you (not the initial developer or any other contributor)
* assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
* constitutes an essential part of this license. No use of any covered code is authorized hereunder
* except under this disclaimer.
*
*/
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include "iax-mutex.h"
#ifdef WIN32
#define _WIN32_WINNT 0x0400
#include <windows.h>
struct mutex {
CRITICAL_SECTION mutex;
};
#else
#include <pthread.h>
struct mutex {
pthread_mutex_t mutex;
};
#endif
mutex_status_t iax_mutex_create(mutex_t **mutex)
{
mutex_status_t status = MUTEX_FAILURE;
#ifndef WIN32
pthread_mutexattr_t attr;
#endif
mutex_t *check = NULL;
check = (mutex_t *) malloc(sizeof(**mutex));
if (!check)
goto done;
#ifdef WIN32
InitializeCriticalSection(&check->mutex);
#else
if (pthread_mutexattr_init(&attr))
goto done;
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
goto fail;
if (pthread_mutex_init(&check->mutex, &attr))
goto fail;
goto success;
fail:
pthread_mutexattr_destroy(&attr);
goto done;
success:
#endif
*mutex = check;
status = MUTEX_SUCCESS;
done:
return status;
}
mutex_status_t iax_mutex_destroy(mutex_t *mutex)
{
#ifdef WIN32
DeleteCriticalSection(&mutex->mutex);
#else
if (pthread_mutex_destroy(&mutex->mutex))
return MUTEX_FAILURE;
#endif
free(mutex);
return MUTEX_SUCCESS;
}
mutex_status_t iax_mutex_lock(mutex_t *mutex)
{
#ifdef WIN32
EnterCriticalSection(&mutex->mutex);
#else
if (pthread_mutex_lock(&mutex->mutex))
return MUTEX_FAILURE;
#endif
return MUTEX_SUCCESS;
}
mutex_status_t iax_mutex_trylock(mutex_t *mutex)
{
#ifdef WIN32
if (!TryEnterCriticalSection(&mutex->mutex))
return MUTEX_FAILURE;
#else
if (pthread_mutex_trylock(&mutex->mutex))
return MUTEX_FAILURE;
#endif
return MUTEX_SUCCESS;
}
mutex_status_t iax_mutex_unlock(mutex_t *mutex)
{
#ifdef WIN32
LeaveCriticalSection(&mutex->mutex);
#else
if (pthread_mutex_unlock(&mutex->mutex))
return MUTEX_FAILURE;
#endif
return MUTEX_SUCCESS;
}
/*
* Simple Mutex abstraction
* Copyright(C) 2007 Michael Jerris
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so.
*
* This work is provided under this license on an "as is" basis, without warranty of any kind,
* either expressed or implied, including, without limitation, warranties that the covered code
* is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
* risk as to the quality and performance of the covered code is with you. Should any covered
* code prove defective in any respect, you (not the initial developer or any other contributor)
* assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
* constitutes an essential part of this license. No use of any covered code is authorized hereunder
* except under this disclaimer.
*
*/
#ifndef _SIMPLE_ABSTRACT_MUTEX_H
#define _SIMPLE_ABSTRACT_MUTEX_H
typedef struct mutex mutex_t;
typedef enum mutex_status {
MUTEX_SUCCESS,
MUTEX_FAILURE
} mutex_status_t;
mutex_status_t iax_mutex_create(mutex_t **mutex);
mutex_status_t iax_mutex_destroy(mutex_t *mutex);
mutex_status_t iax_mutex_lock(mutex_t *mutex);
mutex_status_t iax_mutex_trylock(mutex_t *mutex);
mutex_status_t iax_mutex_unlock(mutex_t *mutex);
#endif
差异被折叠。
/*
* libIAX
*
* Implementation of Inter-IAXerisk eXchange
*
* Copyright (C) 1999, Mark Spencer
*
* Mark Spencer <markster@linux-support.net>
*
* This program is free software, distributed under the terms of
* the GNU Lesser (Library) General Public License
*/
#ifndef _IAX_H
#define _IAX_H
/* Max version of IAX protocol we support */
#define IAX_PROTO_VERSION 1
#define IAX_MAX_CALLS 32768
#define IAX_FLAG_FULL 0x8000
#define IAX_FLAG_SC_LOG 0x80
#define IAX_MAX_SHIFT 0x1F
/* Maximum size of an IAX frame (max size of UDP frame) */
#define IAX_MAX_BUF_SIZE 65536
/* Subclass for IAX_FRAME_IAX */
#define IAX_COMMAND_NEW 1
#define IAX_COMMAND_PING 2
#define IAX_COMMAND_PONG 3
#define IAX_COMMAND_ACK 4
#define IAX_COMMAND_HANGUP 5
#define IAX_COMMAND_REJECT 6
#define IAX_COMMAND_ACCEPT 7
#define IAX_COMMAND_AUTHREQ 8
#define IAX_COMMAND_AUTHREP 9
#define IAX_COMMAND_INVAL 10
#define IAX_COMMAND_LAGRQ 11
#define IAX_COMMAND_LAGRP 12
#define IAX_COMMAND_REGREQ 13 /* Registration request */
#define IAX_COMMAND_REGAUTH 14 /* Registration authentication required */
#define IAX_COMMAND_REGACK 15 /* Registration accepted */
#define IAX_COMMAND_REGREJ 16 /* Registration rejected */
#define IAX_COMMAND_REGREL 17 /* Force release of registration */
#define IAX_COMMAND_VNAK 18 /* If we receive voice before valid first voice frame, send this */
#define IAX_COMMAND_DPREQ 19 /* Request status of a dialplan entry */
#define IAX_COMMAND_DPREP 20 /* Request status of a dialplan entry */
#define IAX_COMMAND_DIAL 21 /* Request a dial on channel brought up TBD */
#define IAX_COMMAND_TXREQ 22 /* Transfer Request */
#define IAX_COMMAND_TXCNT 23 /* Transfer Connect */
#define IAX_COMMAND_TXACC 24 /* Transfer Accepted */
#define IAX_COMMAND_TXREADY 25 /* Transfer ready */
#define IAX_COMMAND_TXREL 26 /* Transfer release */
#define IAX_COMMAND_TXREJ 27 /* Transfer reject */
#define IAX_COMMAND_QUELCH 28 /* Stop audio/video transmission */
#define IAX_COMMAND_UNQUELCH 29 /* Resume audio/video transmission */
#define IAX_DEFAULT_REG_EXPIRE 60
#define IAX_DEFAULT_PORTNO 5036
/* Full frames are always delivered reliably */
struct iax_full_hdr {
short callno; /* Source call number -- high bit must be 1 */
short dcallno; /* Destination call number */
unsigned int ts; /* 32-bit timestamp in milliseconds */
unsigned short seqno; /* Packet number */
char type; /* Frame type */
unsigned char csub; /* Compressed subclass */
char data[];
};
/* Mini header is used only for voice frames -- delivered unreliably */
struct iax_mini_hdr {
short callno; /* Source call number -- high bit must be 0 */
unsigned short ts; /* 16-bit Timestamp (high 16 bits from last IAX_full_hdr) */
/* Frametype implicitly VOICE_FRAME */
/* subclass implicit from last IAX_full_hdr */
char data[];
};
#endif
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论