00001
00002
00003
00004
00005
00006
00007 #define RTP_SUPPORT
00008 #define PUSH_TO_TALK
00009 #define FACE_SET_GEOMETRY
00010 #define NAT_LAUNCH
00011
00012 #if defined(sun) && !defined(Solaris)
00013 #define BSD_like
00014 #endif
00015
00016 #ifdef __FreeBSD__
00017 #define BSD_like
00018 #endif
00019
00020 #ifdef sgi
00021 #define _BSD_SIGNALS
00022 #endif
00023
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <fcntl.h>
00027 #include <assert.h>
00028 #include <string.h>
00029 #include <ctype.h>
00030 #include <time.h>
00031 #ifdef PUSH_TO_TALK
00032 #include <curses.h>
00033 #endif
00034 #include <sys/types.h>
00035 #include <sys/time.h>
00036 #include <sys/wait.h>
00037 #include <sys/stat.h>
00038 #include <unistd.h>
00039 #ifdef BSD_like
00040 #include <sys/timeb.h>
00041 #endif
00042 #ifdef Solaris
00043 #include <sys/systeminfo.h>
00044 #endif
00045 #ifdef sgi
00046 #include <dmedia/audio.h>
00047 #include <limits.h>
00048 #endif
00049 #include <errno.h>
00050 #include <signal.h>
00051 #include <sys/socket.h>
00052 #include <netinet/in.h>
00053 #include <arpa/inet.h>
00054 #include <netdb.h>
00055 #ifdef LINUX_FPU_FIX
00056 #include <fpu_control.h>
00057 #endif
00058
00059 #define NOLONGLONG
00060 #include "types.h"
00061
00062 #ifndef NOCRYPTO
00063 #define CRYPTO
00064 #endif
00065
00066 #ifdef CRYPTO
00067 #include "aes.h"
00068 #define AES_BLOCK_SIZE BLOCK_SIZE
00069 #include "blowfish.h"
00070 #include "des.h"
00071 #include "des_sf.h"
00072 #include "idea.h"
00073 #endif
00074
00075 #include "ulaw2linear.h"
00076 #include "adpcm-u.h"
00077 #include "celp.h"
00078 #include "lpc.h"
00079 #include "gsm.h"
00080 #include "lpc10.h"
00081 #include "md5.h"
00082 #include "rtp.h"
00083 #include "rtpacket.h"
00084 #include "audio_descr.h"
00085 #include "common.h"
00086
00087 #define SAMPLE_RATE 8000
00088
00089 #define TINY_PACKETS 512
00090
00091 #define FACEDIR "/tmp/"
00092
00093 #define BUFL 8000
00094
00095 #define LONG long
00096
00097
00098
00099
00100
00101
00102
00103 #define AUDIO_DEVICE_FILE
00104
00105 #ifdef sgi
00106 #undef AUDIO_DEVICE_FILE
00107 #endif
00108 #ifdef HEWLETT_PACKARD
00109 #undef AUDIO_DEVICE_FILE
00110 #endif
00111 #ifdef LINUX_ALSA
00112 #undef AUDIO_DEVICE_FILE
00113 #endif
00114
00115
00116
00117 #ifdef Solaris
00118 #define bcmp(a, b, n) memcmp(a, b, n)
00119 #define bcopy(a, b, n) memmove(b, a, n)
00120 #define bzero(a, n) memset(a, 0, n)
00121
00122 typedef void (*signalFUNC)(int);
00123 #define signal(a, b) sigset(a, (signalFUNC) b)
00124 #define signalFUNCreturn (signalFUNC)
00125 #endif
00126
00127 #ifndef signalFUNCreturn
00128 #define signalFUNCreturn
00129 #endif
00130
00131
00132
00133 #ifdef IP_ADD_MEMBERSHIP
00134 #define MULTICAST
00135 #endif
00136
00137 #define LPC_FRAME_SIZE 160
00138
00139 struct soundbuf {
00140 LONG compression;
00141 char sendinghost[16];
00142 struct {
00143 LONG buffer_len;
00144 char buffer_val[BUFL];
00145 } buffer;
00146 };
00147 typedef struct soundbuf soundbuf;
00148
00149 struct sbhead {
00150 LONG compression;
00151 char sendinghost[16];
00152 struct {
00153 LONG buffer_len;
00154 char buffer_val[16];
00155 } buffer;
00156 };
00157 typedef struct sbhead sbhead;
00158
00159 #ifndef TRUE
00160 #define TRUE 1
00161 #endif
00162 #ifndef FALSE
00163 #define FALSE 0
00164 #endif
00165
00166 #define V (void)
00167
00168 #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
00169
00170
00171
00172 #define fComp2X 1
00173 #define fDebug 2
00174 #define fSetDest 4
00175 #define fDestSpkr 0
00176 #define fDestJack 8
00177 #define fLoopBack 16
00178 #define fCompGSM 32
00179 #define fEncDES 64
00180 #define fEncOTP 128
00181 #define fEncIDEA 256
00182 #define fCompADPCM 512
00183 #define fEncPGP 1024
00184 #define fKeyPGP 2048
00185 #define fCompLPC 4096
00186 #define fFaceData 8192
00187 #define fFaceOffer 16384
00188 #define fCompVOX 0x10000
00189 #define fCompLPC10 0x20000
00190 #define fCompRobust 0x40000
00191 #define fEncBF 0x80000
00192 #define fCompCELP 0x100000
00193 #define fEncAES 0x200000
00194 #define fProtocol 0x40000000
00195
00196
00197
00198 #define faceRequest 1
00199 #define faceReply 2
00200 #define faceLess 4
00201
00202
00203
00204 #define fCompressionModes (fComp2X | fCompGSM | fCompADPCM | fCompLPC | fCompLPC10 | fCompCELP)
00205 #define isEncrypted(x) (((x) & (fEncDES | fEncOTP | fEncOTP | fEncPGP)) != 0)
00206
00207
00208
00209 #define fHalfDuplex 0x10000000
00210 #ifdef HALF_DUPLEX
00211 #define fHalfDuplexMute 1
00212 #define fHalfDuplexResume 2
00213 #endif
00214
00215
00216
00217 #define isSoundPacket(c) (((c) & (fFaceData | fKeyPGP | fHalfDuplex)) == 0)
00218
00219
00220
00221 struct connection {
00222 struct connection *con_next;
00223 struct in_addr con_addr;
00224 char pgpkey[17];
00225 char keymd5[16];
00226 long con_timeout;
00227 long con_busy;
00228 char con_hostname[264];
00229 #ifdef NAT_LAUNCH
00230 struct {
00231 int dport;
00232 int cport;
00233 } con_ports;
00234 int sfmike_pid;
00235 #endif
00236 long con_compmodes;
00237 #ifdef NAT_LAUNCH
00238 long con_compression;
00239 #endif
00240 short con_protocol;
00241 int con_reply_current;
00242 #ifndef CRYPTO
00243 int con_crypt_warning;
00244 #endif
00245 char con_session[4];
00246 lpcstate_t lpcc;
00247 int con_rseq;
00248
00249 char con_uname[4096];
00250 char con_email[256];
00251
00252 char face_filename[300];
00253 FILE *face_file;
00254 pid_t face_viewer;
00255 int face_stat;
00256 long face_address;
00257 int face_retry;
00258 int face_timeout;
00259 };
00260
00261
00262
00263 #define FSinit 0
00264 #define FSrequest 1
00265 #define FSreply 2
00266 #define FScomplete 3
00267 #define FSabandoned 4
00268
00269
00270
00271 #define FaceFetchInterval 250000
00272
00273 #define FaceTimeout (FaceFetchInterval * 20)
00274 #define FaceMaxRetries 10
00275
00276
00277
00278 #define PROTOCOL_SPEAKFREE 0
00279 #define PROTOCOL_VAT 1
00280 #define PROTOCOL_RTP 2
00281 #define PROTOCOL_VATRTP_CRYPT 3
00282 #define PROTOCOL_UNKNOWN 4
00283
00284
00285
00286 #define RTCP_APP_TEXT_CHAT "SFtc"
00287
00288
00289
00290 #define LWL_MAX_SITES 5
00291
00292 #ifdef MYDOMAIN
00293 #define getdomainname(s, n) strncpy(s, MYDOMAIN, n)
00294 #endif
00295
00296
00297
00298 extern void adpcmdecomp(struct soundbuf *sb);
00299
00300
00301
00302 extern char *StrReplace(char *Str, char *OldStr, char *NewStr);
00303
00304
00305
00306 extern void string_DES_key(char *key, unsigned char des_key[8], char algorithm[16]);
00307
00308
00309
00310 #ifdef NEEDED_LINEAR
00311 extern unsigned char linear2alaw(int pcm_val);
00312 extern int alaw2linear(unsigned char a_val);
00313 extern unsigned char linear2ulaw(int pcm_val);
00314 extern int ulaw2linear(unsigned char u_val);
00315 extern unsigned char ulaw2alaw(unsigned char uval);
00316 #endif
00317 extern unsigned char alaw2ulaw(unsigned char aval);
00318
00319
00320
00321 extern void outHTML(FILE *fp, char *s);
00322
00323
00324
00325 extern void rate_start(int inrate, int outrate);
00326 extern void rate_flow(unsigned char *ibuf, unsigned char *obuf, int *isamp, int *osamp);
00327
00328
00329
00330 extern int isrtp(unsigned char *pkt, int len);
00331 extern int isValidRTCPpacket(unsigned char *p, int len);
00332 extern int isRTCPByepacket(unsigned char *p, int len);
00333 extern int isRTCPAPPpacket(unsigned char *p, int len, char *name, unsigned char **app_ptr);
00334 extern int rtp_make_sdes(char **pkt, unsigned long ssrc_i, int port, int strict);
00335 extern int rtp_make_bye(unsigned char *p, unsigned long ssrc_i, char *raison, int strict);
00336 extern int rtp_make_app(unsigned char *p, unsigned long ssrc_i, int strict, char *type, char *content);
00337 extern int rtpout(soundbuf *sb, unsigned long ssrc_i, unsigned long timestamp_i,
00338 unsigned short seq_i, int spurt);
00339 extern int parseSDES(unsigned char *packet, struct rtcp_sdes_request *r);
00340 extern void copySDESitem(char *s, char *d);
00341
00342
00343
00344 extern void setaubufsize(int size);
00345 extern int soundinit(int iomode);
00346 extern void soundterm(void);
00347 extern void sound_open_file_descriptors(int *audio_io, int *audio_ctl);
00348 extern void soundplay(int len, unsigned char *buf);
00349 extern void soundplayvol(int value);
00350 extern void soundrecgain(int value);
00351 extern void sounddest(int where);
00352 extern int soundgrab(char *buf, int len);
00353 extern void soundflush(void);
00354
00355
00356
00357 extern FILE *create_tempfile(char *temp_filename_pattern, const int uMask, const int unLink);
00358 extern FILE *create_tempfile_in_tempdir(const char *tag, char **genName, const int uMask, const int unLink);
00359
00360
00361
00362 extern void sf_usleep(unsigned t);
00363
00364
00365
00366 extern int isvat(unsigned char *pkt, int len);
00367 extern int vatout(soundbuf *sb, unsigned long ssrc_i, unsigned long timestamp_i, int spurt);
00368 extern int makeVATid(char **vp, unsigned long ssrc_i);
00369 extern int makevatdone(char *v, unsigned long ssrc_i);
00370
00371
00372
00373 #include "vox.h"
00374
00375
00376
00377 #ifdef HEXDUMP
00378 extern void xd(FILE *out, void *buf, int bufl, int dochar);
00379 #endif