Main Page   Compound List   File List   Compound Members   File Members  

netfone.h

Go to the documentation of this file.
00001 /*
00002 
00003                                 Master include file
00004                         
00005 */
00006 
00007 //  System include files
00008 
00009 #include <windows.h>
00010 #include <shellapi.h>
00011 #define _INC_SHELLAPI
00012 
00013 #ifndef RC_INVOKED
00014 
00015 #include <windowsx.h>
00016 #include <winsock.h>
00017 #include <mmsystem.h>
00018 
00019 #include <stdarg.h>
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <ctype.h>
00024 #include <memory.h>
00025 #include <time.h>
00026 #include <float.h>
00027 #include <io.h>
00028 #include <commdlg.h>
00029 #include <math.h>
00030 #include <wchar.h>
00031 #include <fcntl.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #include <share.h>
00035 #include <commctrl.h>
00036 
00037 #define WM_COMMAND_ID(x)        (LOWORD(x))
00038 #define WM_COMMAND_NOTIFY       (HIWORD(wParam))
00039 
00040 //      Application include files
00041 
00042 #include "md5.h"
00043 #include "aes.h"
00044 #define AES_BLOCK_SIZE    BLOCK_SIZE
00045 #include "blowfish.h"
00046 #include "des.h"
00047 #include "ndes.h"
00048 #include "idea.h"
00049 #include "ulaw.h"
00050 #include "gsm.h"
00051 #include "adpcm_u.h"
00052 #include "celp.h"
00053 #include "rtp.h"
00054 #include "rtpacket.h"
00055 #include "lpc.h"
00056 #include "vox.h"
00057 
00058 #endif
00059 
00060 #include "resource.h"
00061 
00062 #define HTML_HELP
00063 #ifdef HTML_HELP
00064 #include "HtmlHelp.h"
00065 #endif
00066 
00067 #ifdef NDEBUG
00068 /*      Generate readable compile-time message if we leave debug output in
00069         a release build.  Genuinely conditional output should be explicitly
00070         conditioned on NDEBUG.  */
00071 #ifdef OutputDebugString
00072 #undef OutputDebugString
00073 #endif    
00074 #define OutputDebugString { extern void OutputDebugString_in_release_build(void); \
00075                                                         OutputDebugString_in_release_build(1); }
00076 #define Assert(x)
00077 #else 
00078 /*      If we're building for debugging, we'll probably eventually
00079         use the hex dump, so let's compile it in.  */
00080 #define HEXDUMP
00081 
00082 //      Assertion macro with Windows application error reporting
00083 #define Assert(x) { if (!(x)) { char erm[128]; wsprintf((LPSTR) erm, \
00084         (LPSTR) "Assertion %s failed at line %d of file %s.", (LPCSTR) #x, __LINE__,(LPSTR) __FILE__); \
00085         FatalAppExit(0, (LPCSTR) erm); }}
00086 #endif
00087 #define Gag(text) OutputDebugString("Gag me with a " #text "!\r\n");
00088 
00089 //  Socket used to exchange sound packets
00090 
00091 #define NETFONE_COMMAND_PORT           2074
00092 
00093 //      If defined, show rant about serial I/O on comm errors
00094 
00095 #define RANT_ON_ERROR
00096 
00097 //  Maximum length (in characters) of a host name
00098 
00099 #define MAX_HOST                        256
00100 
00101 //  Get/SetWindowLong offsets
00102 
00103 #define GWL_CLIENT                      0               // Client-side data
00104 
00105 //  Type fields for client/server window data structures
00106 
00107 #define WINDOW_TYPE_CLIENT              1
00108 
00109 //  Various timeouts in seconds
00110 
00111 #define FRAME_TIMER_ID                  1
00112 
00113 #define TIMEOUT_CONNECTION                              30                              // Remote connection timeout
00114 #define TIMEOUT_AUDIO_OUTPUT                    4                               // Release audio output timeout
00115 #define TIMEOUT_RESEND_LWL                              (119)                   // Resend Look Who's Listening listing
00116 #define TIMEOUT_RESEND_SDES                             10                              // Reset VAT/RTP ID interval
00117 #define BroadcastUnsubscribe                    10                              // Broadcast mike blip length (seconds) 
00118 
00119 //  Maximum printf-like output allowed by MsgBox
00120 
00121 #define MAX_PRINTF_OUTPUT               1024
00122 
00123 //      LPC encoding frame size
00124 
00125 #define LPC_FRAME_SIZE                  160
00126 
00127 //      Number of recent connections to remember
00128 
00129 #define REMEMBER_CONNECTIONS    5
00130 
00131 //      Multicast definitions missing from WINSOCK.H
00132 
00133 #ifndef IN_MULTICAST
00134 #define IN_MULTICAST(i) ((ntohl((long)(i)) & 0xF0000000) == 0xE0000000)
00135 #endif
00136 
00137 //  Messages posted by the asynchronous socket APIs
00138 
00139 #define WM_SOCKET_SELECT        (WM_USER + 100)         // Data socket notifications
00140 #define WM_SOCKET_ASYNC         (WM_USER + 101)         // Asynchronous request completions
00141 #define WM_SOCKET_LWL           (WM_USER + 102)         // LWL socket notifications
00142 #define WM_SOCKET_CONTROL       (WM_USER + 103)         // Control socket notifications
00143 #define WM_CLEAN_UP_YOUR_ACT (WM_USER + 104)    // Too depressing to explain--see FRAME.C
00144 
00145 // Messages posted to start other sessions
00146 
00147 #define WM_NEW_COMMANDLINE      (WM_USER + 200)         // Second instance launched with new site
00148 
00149 #define HANDLE_WM_SOCKET_SELECT(hwnd, wParam, lParam, fn) \
00150     ((fn)((hwnd), (SOCKET)(wParam), (SOCKERR)WSAGETSELECTERROR(lParam), \
00151     (SOCKEVENT)WSAGETSELECTEVENT(lParam)), 0L)
00152 #define FORWARD_WM_SOCKET_SELECT(hwnd, socket, serr, sevent, fn) \
00153     (void)(fn)((hwnd), WM_SOCKET_SELECT, (WPARAM)(socket), \
00154     (LPARAM)WSAMAKESELECTREPLY(sevent, serr))
00155 
00156 #define HANDLE_WM_SOCKET_ASYNC(hwnd, wParam, lParam, fn) \
00157     ((fn)((hwnd), (HANDLE)(wParam), (SOCKERR)WSAGETASYNCERROR(lParam), \
00158     (WORD)WSAGETASYNCBUFLEN(lParam)), 0L)
00159 #define FORWARD_WM_GETXBYX(hwnd, hAsync, serr, cbBuffer, fn) \
00160     (void)(fn)((hwnd), WM_SOCKET_ASYNC, (WPARAM)(hAsync), \
00161     (LPARAM)WSAMAKEASYNCREPLY(cbBuffer, serr))
00162 
00163 //  Determine number of elements in an array
00164 
00165 #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
00166 
00167 //      Macro for retrieving formats from the resource file
00168 
00169 #define Format(n)   rstring(IDS_FORMATS + (n))
00170 
00171 /*      Force a resource string to be LPSTR for those (like wsprintf)
00172         who can't figure out by themselves.  */
00173         
00174 #define Lrstring(n)     ((LPSTR) rstring(n))
00175 
00176 //  Make life with RC a little easier
00177 
00178 #ifdef RC_INVOKED
00179 #define ID(x)           x
00180 #else
00181 #define ID(x)           MAKEINTRESOURCE(x)
00182 #endif
00183 
00185 
00186 #define IDI_BASE                        1000
00187 #define IDM_BASE                        2000
00188 #define IDD_BASE                        3000
00189 #define IDA_BASE                        4000
00190 
00191 //  Icon resource IDs
00192 
00193 #define IDI_FRAME                       ID(1000)        // IDI_BASE + 0
00194 #define IDI_CLIENT                      ID(1001)        // IDI_BASE + 1
00195 #define IDI_SERVER                      ID(1002)        // IDI_BASE + 2
00196 
00197 //  Menu resource IDs
00198 
00199 #define IDM_FRAME_BASE                  2000            // IDM_BASE + 0
00200 #define IDM_FRAME                       ID(IDM_FRAME_BASE)
00201 #define IDM_CONNECTION_BASE             (IDM_FRAME_BASE + 0)
00202 #define IDM_CONNECTION_EXIT             (IDM_CONNECTION_BASE + 3)
00203 
00204 #define IDM_WINDOW_BASE                 (IDM_FRAME_BASE + 100)
00205 #define IDM_WINDOW_CASCADE              (IDM_WINDOW_BASE + 0)
00206 #define IDM_WINDOW_TILE_VERTICALLY      (IDM_WINDOW_BASE + 1)
00207 #define IDM_WINDOW_TILE_HORIZONTALLY    (IDM_WINDOW_BASE + 2)
00208 #define IDM_WINDOW_ARRANGE_ICONS        (IDM_WINDOW_BASE + 3)
00209 #define IDM_WINDOW_FIRST_CHILD          (IDM_WINDOW_BASE + 4)
00210 
00211 #define IDM_HELP_BASE                   (IDM_FRAME_BASE + 200)
00212 #define IDM_HELP_ABOUT                  (IDM_HELP_BASE + 0)
00213 
00214 #define IDM_CUSTOM                                              9000                    // Custom (remembered file) menu items
00215 
00216 //  Dialog resource IDs
00217 
00218 #define IDD_ABOUT                       ID(3000)        // IDD_BASE + 0
00219 
00220 #define IDD_NEW                         ID(3100)        // IDD_BASE + 100
00221 #define IDD_NEW_HOST                    3101
00222 #define IDD_NEW_HOST_LABEL              3102
00223 
00224 //  Accelerator table resource IDs
00225 
00226 #define IDA_FRAME       ID(4000)                        // IDA_BASE + 0
00227 
00228 #define BUFL    8000                                    // Sound buffer maximum length (actually less)
00229 
00230 #define LONG    long
00231 
00232 #define SPEAK_FREE_FRAME_CLASS "SpeakFreeFrameClass"
00233 
00234 #define EXCHANGE_SAMPLE_RATE                    8000            // Samples per second in data exchanged over the network
00235 
00236 struct soundbuf {
00237         LONG compression;
00238         char sendinghost[16];
00239         struct {
00240                 LONG buffer_len;
00241                 char buffer_val[BUFL];
00242         } buffer;
00243 };
00244 typedef struct soundbuf soundbuf;
00245 
00246 // Packet mode flags
00247 
00248 #define fComp2X     1                 // Simple 2 to 1 compression
00249 #define fDebug      2                 // Debug mode
00250 #define fSetDest    4                 // Set sound output destination
00251 #define fDestSpkr   0                 // Destination: speaker
00252 #define fDestJack   8                 // Destination: audio output jack
00253 #define fLoopBack   16                // Loopback packets for testing
00254 #define fCompGSM    32                // GSM compression
00255 #define fEncDES     64                // DES encrypted
00256 #define fEncOTP     128               // One-time pad encrypted
00257 #define fEncIDEA    256               // IDEA encrypted
00258 #define fCompADPCM      512               // ADPCM compressed
00259 #define fEncPGP         1024              // PGP-protected session key encrypted
00260 #define fKeyPGP         2048              // Packet contains PGP-encrypted session key
00261 #define fCompLPC        4096              // LPC compressed
00262 #define fFaceData   8192          // Request/reply for face data
00263 #define fFaceOffer  16384         // Offer face image to remote host
00264 #define fNewProto   0x8000                // Version 7.1 Protocol Enhancements
00265 #define fCompVOX        0x10000           // VOX compressed
00266 #define fCompLPC10      0x20000           // LPC-10 compressed
00267 #define fCompRobust     0x40000           // Robust duplicate packet mode
00268 #define fEncBF          0x80000           // Blowfish encrypted
00269 #define fCompCELP   0x100000      // CELP compressed
00270 #define fEncAES         0x200000          // AES encrypted
00271 #define fProtocol   0x40000000    // Speak Freely protocol flag
00272 
00273 // Special definitions for face data packets (which have fFaceData set)
00274 
00275 #define faceRequest 1             // Face data request
00276 #define faceReply   2             // Face data reply
00277 #define faceLess    4             // No face available
00278 
00279 // Mask to extract compression modes
00280 
00281 #define fCompressionModes   (fComp2X | fCompGSM | fCompADPCM | fCompLPC | fCompVOX | fCompLPC10 | fCompCELP)
00282 
00283 /*      The following flags appear in the compression field of sound
00284         buffers but never figure in buffers actually transmitted on
00285         the network; they're used purely for internal housekeeping.
00286         In some cases flags used in network buffers are reused.  */
00287 
00288 #define fFromModem      0x8000            // From the modem
00289 #define fPlayback       0x02000000        // Answering machine playback packet
00290 #define fAnsNewMsg      0x01000000        // Start of new message on answering machine
00291 
00292 // Test if a packet actually contains sound
00293 
00294 #define isSoundPacket(c)    (((c) & (fFaceData | fKeyPGP)) == 0)
00295 
00296 // Protocol types
00297 
00298 #define PROTOCOL_SPEAKFREE  0           // Speak Freely protocol
00299 #define PROTOCOL_VAT        1           // VAT protocol
00300 #define PROTOCOL_RTP        2           // RTP protocol
00301 #define PROTOCOL_VATRTP_CRYPT 3         // Probably encrypted VAT or RTP message
00302 #define PROTOCOL_UNKNOWN    4           // No evidence as to protocol yet
00303 
00304 //      Answering machine file format
00305 
00306 struct respHeader {
00307         struct in_addr hostIPnumber;    // IP number of sending host
00308         time_t itemTime;                                // Time and date buffer received
00309         short hostNameLength;                   // Length of hostName including zero terminator
00310         short soundBufLength;                   // Length of sound buffer
00311         
00312 /*      The following items appear in the file after the header defined
00313         above, with lengths as given in the header.  */
00314 
00315 //      char hostName[hostNameLength];  // Full name of host
00316 //      soundbuf fileSoundBuf;                  // Sound buffer, truncated to soundBufLength bytes 
00317 };
00318 
00319 //      Local loopback packet buffer
00320 
00321 struct localLoop {
00322         struct localLoop *llnext;               // Next buffer in chain or NULL
00323         int lllen;                                              // Length of packet in bytes
00324         int llsamples;                                  // Number of samples in packet
00325         SOCKADDR_IN lladdr;                             // Address packet sent to
00326         char llpacket[0];                               // Packet data
00327 };
00328 
00329 #define IS_LOCALHOST(i) (ntohl((long)(i)) == 0x7F000001)
00330 #define LOOPBACK_ENABLED        1               // Enabled flag in localLoopback 
00331 #define LOOPBACK_PLAYING        2               // Flag in localLoopback for play active
00332 
00333 //      Auxiliary socket
00334 
00335 struct auxSocket {
00336         struct auxSocket *asnext;               // Next auxiliary socket
00337         short asrefc;                                   // Reference count if not permanent: 0 = socket closed
00338         unsigned short asport;                  // Port number (host byte order)
00339         SOCKET asdata;                                  // Data (even port) socket
00340         SOCKET asctrl;                                  // Control (odd port) socket 
00341 };
00342 
00343 //      Sampling rate conversion tools
00344 
00345 typedef struct ratestuff {
00346         unsigned long opos_frac;                        /* Fractional position of the output stream in input stream unit */
00347         unsigned long opos;
00348 
00349         unsigned long opos_inc_frac;            /* Fractional position increment in the output stream */
00350         unsigned long opos_inc; 
00351 
00352         unsigned long ipos;                             /* Position in the input stream (integer) */
00353 
00354         long ilast;                                             /* Last sample in the input stream */
00355 } rate_t;
00356 
00357 //  Socket-specific types
00358 
00359 typedef INT     SOCKERR;                                // A socket error code
00360 typedef WORD PORT;                              // A socket port number
00361 typedef WORD SOCKEVENT;                                 // An asynchronous socket event
00362 
00363 //  Potential states for connection windows
00364 
00365 typedef enum _CLIENT_STATE
00366 {
00367     Embryonic,                          // Newly creates connection
00368     Idle,                               // Idle
00369     SendingLiveAudio,                   // Sending live audio
00370     Transferring,                       // Sending audio file
00371     PlayingReceivedAudio                // Playing audio received from remote host
00372 
00373 } CLIENT_STATE;
00374 
00375 typedef enum {
00376         Unspecified,                                            // No package specified
00377         PGP,                                                            // PGP
00378         GPG                                                                     // GPG: Gnu Privacy Guard
00379 } public_key_package;
00380 
00381 /*  Connection window data.  A pointer to this structure is
00382         kept at offset GWL_CLIENT in each connection window. */
00383 
00384 typedef struct _CLIENT_DATA {
00385     DWORD dwType;                               // Type of window (WINDOW_TYPE_CLIENT)
00386     CLIENT_STATE state;                 // Current state.
00387     SOCKET sReply;                              // Socket waiting for reply from srv
00388     SOCKET sControl;                                    // Socket for RTP/VAT control messages
00389     int timeout;                                // Timeout counter
00390     SOCKADDR_IN inetSock;               // Client's socket address
00391     unsigned short port;                                // Destination data port number
00392     struct auxSocket *auxSock;                  // Auxiliary socket, if any
00393     CHAR szHost[MAX_HOST];                      // Target server's host name
00394     HFILE hFile;                                // Handle to open file
00395     DWORD cbSent;                               // Count of bytes sent so far.
00396     DWORD cbReceived;                           // Count of bytes received so far
00397     CHAR szFile[MAX_PATH];                      // Name of file being sent
00398     HANDLE getNameTask;                                 // Get full site name task handle
00399     BYTE hostBuffer[MAXGETHOSTSTRUCT];  // Host name reply buffer
00400     
00401     int modemConnection;                                // Connection is via the modem
00402     HMMIO mmioHandle;                                   // WAVE file MMIO handle
00403     LPWAVEFORMAT mmioFormat;                    // WAVE file format descriptor
00404     DWORD mmioDataLeft;                                 // WAVE file data left to send
00405     int quitSoundFile;                                  // Abort current sound file ?
00406     int wantsInput;                                             // Is wave input wanted ?
00407     int outputSocketBusy;                               // Output socket is busy with a sendto()
00408     DWORD broadcastBeginTime;                   // Time (ticks) when subscribed to broadcast
00409     int broadcastEnd;                                   // Terminate broadcast connection ?
00410     struct sockaddr_in name;                    // Target system address
00411     struct sockaddr_in ctrl;                    // Target system control port address
00412     char desKeyString[256];                             // DES key string
00413     char deskey[9];                     // Destination DES key, if any
00414     char rtpdeskey[9];                                  // Destination RTP DES key, if any
00415     char vatdeskey[9];                                  // Destination VAT DES key, if any
00416     char ideaKeyString[256];                    // IDEA key string
00417     char ideakey[17];                   // Destination IDEA key, if any
00418         char blowfishKeyString[256];            // Blowfish key string
00419         char blowfish_spec;                                     // Is Blowfish key specified?
00420         BF_KEY blowfishkey;                                     // Generated Blowfish key
00421         char aesKeyString[256];                         // AES key string
00422         int aesKeyHex;                                          // Is AES key hexadecimal ?
00423         char aes_spec;                                          // Is AES key specified ?
00424         aes_ctx aesEkey;                                        // AES encryption key
00425         aes_ctx aesDkey;                                        // AES decryption key
00426     char pgpkeymd5[16];                                 // Inbound MD5 signature of PGP session key
00427     char pgpkey[17];                                    // Inbound PGP-transmitted session key
00428     char pgpFileName[MAX_PATH];                 // Inbound PGP decoded file name, if strlen > 0
00429         char opgpUserList[256];                         // Outbound PGP user ID list
00430     char opgpkey[17];                                   // Outbound PGP-transmitted session key
00431     char opgpFileName[MAX_PATH];                // Outbound PGP decoded file name, if strlen > 0
00432     char otpFileName[MAX_PATH];                 // One-time pad file name
00433     char otp[BUFL];                     // One-time pad
00434     int multicast_scope;                                // Multicast scope (time-to-live)
00435     int squelch;                                                // Squelch
00436     int ring;                                                   // Ring
00437     int debugging;                                              // Debug mode
00438     int debugReq;                                               // Debug output requested by remote ?
00439     int loopback;                                               // Loopback mode
00440     int saveKeys;                                               // Save keys in connection file
00441     char connectionFileName[MAX_PATH];  // Connection file name for save
00442     gsm gsmh;                                                   // GSM handle for incoming audio
00443     lpcstate_t lpc_state;                               // LPC decoder state
00444         rate_t rateconv;                                        // Rate conversion state
00445         struct celp_context *d_celp_ctx;        // CELP decoding context (allocated when CELP data received)
00446         int rseq;                                                       // Robust mode packet sequence number
00447     
00448     short protocol;                             // Transmission protocol
00449     
00450     short localLoopback;                                // Local loopback enabled ?
00451     struct localLoop *llhead,                   // Local loopback packet chain
00452                                  *lltail;
00453                                         
00454     char session_id[4];                 // VAT/RTP session identifier
00455     int sendSDEStimer;                                  // Sent RTP/VAT ID timer
00456     int buttonUpTimer;                                  // Button up timer running
00457     LPSTR uname;                                                // User name, if known
00458     char email[256];                                    // User E-mail address, if known
00459     char szRemoteProgram[256];                  // Name of connected party's client software
00460     
00461     int face_stat;                      // Face retrieval status
00462     long face_address;                  // Address of current block request
00463     int face_retry;                     // Timeout retry count
00464     int face_timeout;                   // Timeout interval
00465     LPSTR face_bmp;                                             // In memory copy of face .bmp file
00466     int face_is_gif;                                    // Face being received as .gif file
00467     long face_file_length;                              // Length of face file being received
00468     int face_shown;                                             // Face bitmap currently displayed ?
00469     int bSentOutgoingMessage;                   // Sent outgoing message already.
00470 } CLIENT_DATA, *LPCLIENT_DATA;
00471 
00472 #define CLIENTPTR(w)            ((LPCLIENT_DATA)GetWindowLong((w), GWL_CLIENT))
00473 #define IS_CLIENT_WINDOW(w)     (CLIENTPTR(w)->dwType == WINDOW_TYPE_CLIENT)
00474 
00475 // Face retrieval status values for face_stat
00476 
00477 #define FSinit      0                   // Nothing requested yet
00478 #define FSrequest   1                   // Request sent, awaiting reply
00479 #define FSreply     2                   // Reply received, ready for next request
00480 #define FScomplete  3                   // Face file reception complete
00481 #define FSabandoned 4                   // Face file retrieval abandoned
00482 
00483 // Face retrieval configuration parameters
00484 
00485 #define FaceFetchInterval   250                 // Interval between block requests, msec
00486 #define FaceTimeout                     20              // Resend block request after this number of intervals                                    
00487 #define FaceMaxRetries      10          // Maximum retries to obtain face data
00488 
00489 //      Configuration parameters for adaptive output rate adjustment
00490 
00491 #define AORA_MINIMUM_DELAY      500                     // Minimum delay (ms) at which to act, regardless of jitter
00492 #define AORA_ACTION_DELAY       500                     // Begin adjusting rate when queue delay > this value in ms
00493 #define AORA_MAXIMUM_RATE_PERCENT 10    // Maximum output rate speed-up in percent
00494 #define AORA_MAXIMUM_RATE_DELAY 3000    // Apply maximum rate when delay greater than this number of ms
00495 
00496 //      System tray interaction
00497 
00498 #define TRAY                                                    // Enable system tray minimisation
00499 #ifdef TRAY
00500 #define WM_TRAY_NOTIFY  (WM_USER + 300) // System tray notification message
00501 extern HWND trayIconWindow;                             // Tray icon window, if active
00502 extern HWND createTrayIcon(void);               // Create tray icon window
00503 extern void updateTrayToolTipText(void);        // Update ToolTip on tray icon to current status
00504 extern void blinkTrayIcon(BOOL blink);  // Start or stop the tray icon blinking
00505 #define TRAY_TIMER_ID   7                               // Tray timer ID
00506 #endif
00507 
00508 //      Audio encoding types for RTP and VAT protocols
00509 
00510 typedef enum {
00511         AE_PCMU, AE_PCMA, AE_G721, AE_IDVI, AE_G723, AE_GSM,
00512         AE_1016, AE_LPC, 
00513         AE_L8, AE_L16, AE_L24, AE_L32,
00514         AE_G728, AE_TRUE,
00515         AE_MAX
00516 } audio_encoding_t;
00517 
00518 /* Common audio description for files and workstations */
00519 
00520 typedef struct {
00521         audio_encoding_t encoding;  /* type of encoding (differs) */
00522         unsigned sample_rate;       /* sample frames per second */
00523         unsigned channels;          /* number of interleaved channels */
00524 } audio_descr_t;
00525 
00526 //  Socket related data
00527 
00528 extern SOCKET sCommand;                                                 // Command socket
00529 extern struct auxSocket *asList;                                // List of auxiliary sockets
00530 
00531 //  Various handles
00532 
00533 extern HINSTANCE hInst;                                                 // The current instance handle
00534 extern HACCEL hAccel;                                                   // Accelerator table handle
00535 extern HWND hwndMDIFrame;                                               // MDI frame  window handle
00536 extern HWND hwndMDIClient;                                              // MDI client window handle
00537 extern HWND hDlgPropeller;                                              // Propeller head dialogue handle
00538 extern HWND hDlgAnswer;                                                 // Answering machine dialogue handle
00539 extern HWND hDlgChat;                                                   // Chat dialogue handle
00540 extern HWND hDlgConsole;                                                // Debug console dialogue handle
00541 extern HWND hDlgSpectral;                                               // Spectral display dialogue handle
00542 
00543 //  Window class names
00544 
00545 extern LPSTR pszFrameClass;                                             // MDI frame  window class
00546 extern LPSTR pszMDIClientClass;                                 // MDI client window class
00547 extern LPSTR pszClientClass;                                    // MDI child window class
00548 
00549 //  Miscellaneous data
00550 
00551 extern LPSTR pszAppName;                                                // Application name
00552 extern INT tmAveCharWidth;                                              // TEXTMETRIC.tmAveCharWidth
00553 extern INT tmHeight;                                                    // TEXTMETRIC.tmHeight
00554 extern LPSTR commandLine;                                               // Command line from invocation
00555 extern int holped;                                                              // Help was invoked somewhere
00556 #ifdef HTML_HELP
00557 extern DWORD HtmlHelpContext;                                   // HTML Help context
00558 #endif
00559 extern UINT fileOpenHelpButton;                                 // File open help button message value
00560 extern char *fileHelpKey;                                               // Help key for file open/save in progress
00561 extern UINT jitterBuf;                                                  // Milliseconds to anti-jitter output
00562 extern BOOL jitterPause;                                                // Queueing packets for anti-jitter ?
00563 
00564 extern HWAVEOUT hWaveOut;                                               // Wave output handle
00565 extern HWAVEIN hWaveIn;                                 // Wave input handle
00566 
00567 extern soundbuf ebuf;                                                   // Utility sound buffer
00568 
00569 extern int audioChannels, samplesPerSecond, bytesPerSecond, sampleAlignment, bitsPerSample;
00570 extern int currentOutputRate;                                   // Current output sample rate
00571 
00572 //      Window display modes
00573 
00574 extern int openOnAnswerMessage;                                 // Restore from icon when new answering machine message arrives
00575 
00576 //      Compression modes
00577 
00578 extern int voxmode;                                                             // VOX mode
00579 extern int breakinput;                                                  // break input audio stream for output
00580 extern int compression;                                                 // 2X compression mode
00581 extern int gsmcompress;                                                 // GSM compression mode
00582 extern int adpcmcompress;                                               // ADPCM compression mode
00583 extern int lpccompress;                                                 // LPC compression mode
00584 extern int lpc10compress;                                               // LPC-10 compression mode
00585 extern int celpcompress;                                                // CELP compression mode
00586 extern int robust;                                                              // Robust mode for LPC-10
00587 extern int voxcompress;                                                 // VOXGSM compression mode
00588 extern int protocolXmit;                                                // Default protocol to send (!protocolAuto or new connection)
00589 extern int protocolSent;                                                // Protocol we're currently sending 
00590 extern int protocolAuto;                                                // Send same protocol as received from connection
00591 extern gsm gsmh;                                                                // GSM compression handle
00592 #ifdef CELP_USE_CONTEXT
00593 struct celp_context *celp_xp;                                   // Transmit CELP context pointer
00594 #endif
00595 extern rate_t xrate;                                                    // Simple (2X) compression context
00596 extern int currentInputSamples;                                 // Samples desired in current input buffers
00597 
00598 //      Transmission modes
00599 
00600 extern int broadcasting;                                                // Broadcasting to all connections ?
00601 extern int listeners;                                                   // Current wantsInput windows
00602 extern int bConferencing;                                               // TRUE if we send to and listen to all connections.
00603 
00604 //      Audio settings for About dialogue
00605 
00606 extern int isWaveSound;                                                 // Input from wave file ?
00607 extern int inputActive, outputActive;                   // Current activity flags
00608 extern int inputPaused;                                                 // Is input paused for output ?
00609 extern int halfDuplex;                          // Is hardware half-duplex
00610 extern int aboutInSamples;                                              // Input samples per second
00611 extern int aboutInBits;                                                 // Input bits per sample
00612 extern int aboutOutSamples;                                             // Output samples per second
00613 extern int aboutOutBits;                                                // Output bits per sample
00614 
00615 //      Encryption settings
00616 
00617 extern public_key_package pk_package;                   // Public key package
00618 
00619 //      Propeller head information
00620 
00621 extern long packetsReceived, packetsSent;               // Network packet traffic counters
00622 extern long inputPacketsLost, outputPacketsLost;// Packets lost counters
00623 extern int openConnections;                                             // Number of open connections
00624 extern int halfDuplexTransition;                                // Transitioning from output to input ?
00625 extern int outputInShutdown;                                    // Close output when last buffer returned
00626 extern long outputPending;                                              // Output buffers in queue
00627 extern long microsecondsPending;                                // Microseconds of samples in buffers on queue
00628 double smoothedMicrosecondsPending;                             // Smoothed microseconds pending in queue
00629 extern int messageQueueSize;                                    // Message queue size
00630 extern long messageChecks;                                              // Anti-lockup calls on DefaultMessageLoop
00631 
00632 //      Network configuration for About dialogue
00633 
00634 extern int aboutUDPmax;                         // Longest UDP packet network handles
00635 extern int netMaxSamples;                                               // Maximum samples, possibly net constrained
00636 
00637 //      Windows and driver bug work-around options
00638 
00639 extern int alwaysBindSocket;                                    // Bind output socket to avoid
00640                                                                                                 // bug in some WINSOCK implementations
00641 extern int useSendNotSendto;                                    /* Use send() instead of sendto()
00642                                                                                                    if buggy (Microsoft) WINSOCK
00643                                                                                                    refuses to accept sendto() on
00644                                                                                                    a connect()-ed socket. */
00645 extern int waNetNoConnect;                                              // Don't connect(), use sendto()
00646 extern int waNetUseSend;                                                // Use send(), not sendto() always
00647 extern int waNetMultiTTLisChar;                                 // Argument to IP_MULTICAST_TTL setsockopt is char
00648 extern int waNetNoOutOverflow;                                  // Disable output overflow detection and recovery
00649 extern int waNetNoMsgLoopIns;                                   // Disable message loop insurance
00650 extern int waNetSynchronousGetHostname;                 // Use gethostbyaddr(), not WASAsync variant
00651 extern int waNetSynchronousGetHostnameAction;   // Action depending on above and Winsock type
00652 
00653 extern int waProtNoHeartbeat;                                   // No heartbeat in Speak Freely protocol
00654 extern int waProtUseLargerRTCPackets;                   // Use large packets with RTP protocol
00655 extern int waProtNoVAT;                                                 // Disable auto-sensing of VAT protocol
00656 extern int waProtNoRTP;                                                 // Disable auto-sensing of RTP protocol
00657 extern int waProtNoRTCPCrypt;                                   // Don't encrypt RTCP packets                    
00658 
00659 extern int waAudioHalf;                                                 // Assume audio half-duplex; don't test
00660 extern int waAudio11025;                                                // Assume audio 11025 samples/sec                                                                                               
00661 extern int waAudioRingMaxVolume;                                // Force maximum output volume for remote ring
00662 extern int waAudioNoOutputRateAdjustment;               // Disable automatic output rate adjustment based on queue length
00663 extern int waAudioBeepOnTransmit;                               // Beep when switching to transmit mode ?
00664 
00665 //      Modem configuration information
00666 
00667 #define modemInputQueue 10240
00668 #define modemOutputQueue 10240
00669 
00670 extern int modemEnable;                                                 // Modem connections enabled ?
00671 extern char modemInitString[128];                               // Modem initialisation string
00672 extern char baudrate[12];                                               // Baud rate
00673 extern char commport[12];                                               // Communications port
00674 extern int modemHandle;                                                 // Open modem comm port handle
00675 extern int modemSessions;                                               // Open sessions on modem
00676 extern int modemShowRant;                                               // Show rant about Windows serial I/O support
00677 
00678 //      Remembered connections
00679 
00680 extern int rememberedConnections;                               // Number of remembered connections
00681 extern LPSTR rememberedConnection[REMEMBER_CONNECTIONS];  // Remembered connections
00682 
00683 //      Multicast settings
00684 
00685 extern int multiMemberships;                                    // Number of multicast group memberships
00686 #ifdef IP_MAX_MEMBERSHIPS
00687 extern struct in_addr multiAddr[IP_MAX_MEMBERSHIPS]; // Multicast group IP numbers
00688 extern LPSTR multiName[IP_MAX_MEMBERSHIPS];             // Multicast group names
00689 #endif
00690 extern int multiLoop;                                                   // Multicast loop-back mode
00691 extern int multiBrainDead;                                              // Multicast loop-back option not supported
00692 
00693 //      Answering machine
00694 
00695 extern char answerFileName[MAX_PATH];                   // Answering machine file name
00696 extern char answerOutFileName[MAX_PATH];                        // Answering machine outgoing message file name
00697 extern int answerRecord;                                                // Record incoming messages
00698 
00699 //      Show Your Face
00700 
00701 extern char faceFileName[MAX_PATH];                             // Face image file name
00702 extern HFILE faceFile;                                                  // Face image file handle
00703 extern int faceShow;                                                    // Show faces ?
00704 
00705 //      Look Who's Listening
00706 
00707 extern char lwl_s_server[MAX_PATH];                             // Look Who's Listening server name
00708 extern char lwl_s_email[80];                                    //              E-mail address
00709 extern char lwl_s_fullname[80];                                 //              Full name
00710 extern char lwl_s_phone[80];                                    //              Telephone number
00711 extern char lwl_s_location[80];                                 //              Location name
00712 extern int lwl_s_publish;                                               //              Publish in directory ?
00713 extern int lwl_s_exact;                                                 //              Exact match only ?
00714 
00715 extern char lwl_a_server[MAX_PATH];                             // Look Who's Listening query server
00716 extern int lwl_a_exact;                                                 //              Exact matches only
00717 
00718 extern int lwl_t_published;                                             // Directory listing published
00719 extern int lwl_t_resend;                                                // Time to update directory listing ?
00720 extern int lwl_t_pending;                                               // LWL server update pending ?
00721 extern struct sockaddr_in lookhost;                     // Look who's listening host, if any
00722 extern void lwl_ask_set_target(const char *target);     // Preset target for Look Who's Listening
00723 
00724 //      VAT/RTP communication state
00725 
00726 extern unsigned long ssrc;                                              // RTP synchronisation source identifier
00727 extern unsigned long timestamp;                                 // RTP packet timestamp
00728 extern unsigned short seq;                                              // RTP packet sequence number
00729 extern unsigned long rtpdesrand;                                // RTP DES random RTCP prefix
00730 extern char *sdes;                                                              // RTP SDES packet
00731 extern int sdesl;                                                               // RTP SDES packet length
00732 extern int spurt;                                                               // Start of talk spurt flag     
00733 extern char *vatid;                                                             // VAT ID packet
00734 extern int vatidl;                                                              // VAT ID packet length
00735 extern char *rtpsdes;                                                   // RTP SDES packet
00736 extern int rtpsdesl;                                                    // RTP SDES packet length
00737 
00738 extern HCURSOR phoneCursor, earCursor, boltCursor;      // Cursor handles
00739 
00740 //      Anti-remote reincarnation protection
00741 
00742 extern u_long Lazarus;                                                  // Lazarus host ID
00743 extern int LazarusLong;                                                 // If nonzero, anti-reincarnation timeout
00744 #define LazarusLength   15                                              // Lazarus timeout in seconds
00745 
00746 extern char blankit[];                          // Long string of blanks
00747 
00748 #define V       (void)
00749 
00750 #ifdef RANT_ON_ERROR
00751 #define errorRant(hwnd) {if (modemShowRant) { modemRant(hwnd); } }
00752 #else
00753 #define errorRant(hwnd)
00754 #endif
00755                                                         
00756 //      Function prototypes
00757 
00758 extern void revlong(long *l);
00759 extern void revshort(short *s);                                                        
00760 
00761 //      Connection window functions
00762 
00763 extern LRESULT CALLBACK connectWndProc(HWND hwnd, UINT nMessage,
00764                                                                 WPARAM wParam, LPARAM lParam);
00765 extern HWND createNewConnection(LPCLIENT_DATA pClientData);
00766 extern void connFetchFace(HWND hwndClient, LPCLIENT_DATA pClientData);
00767 
00768 //  Dialogue functions
00769 
00770 extern VOID aboutDialogue(HWND hwndParent);
00771 extern VOID propellerHeadDialogue(HWND hwndParent);
00772 extern BOOL CALLBACK propellerHeadDlgProc(HWND hwnd,
00773                                                         UINT nMessage, WPARAM wParam, LPARAM lParam);
00774 extern void propUpdateAudio(void);                                                      
00775 extern VOID benchDialogue(HWND hwndParent);
00776 extern BOOL newHostDialogue(HWND hwndParent, LPSTR pszHostName, LPIN_ADDR paddr,
00777                                                         unsigned short *port);
00778 extern VOID genKeyDialogue(HWND hwnd);
00779 extern VOID connectionProperties(HWND hwnd, LPCLIENT_DATA d);
00780 extern VOID modemSetupDialogue(HWND hwnd);
00781 extern void modemRant(HWND hwnd);
00782 extern VOID multicastGroupsDialogue(HWND hwnd);
00783 extern VOID answerDialogue(HWND hwndParent);
00784 extern BOOL CALLBACK answerDlgProc(HWND hwnd, UINT nMessage,
00785                                                         WPARAM wParam, LPARAM lParam);
00786 extern int faceDialogue(HWND hWndParent);                                                       
00787 extern BOOL CALLBACK faceDlgProc(HWND hwnd, UINT nMessage,
00788                                                         WPARAM wParam, LPARAM lParam);                                                  
00789 extern VOID lwl_ask(HWND hwnd);
00790 extern VOID lwl_tell_settings(HWND hwnd);
00791 extern BOOL voxMonitorDialog(HWND hwndParent);
00792 extern BOOL IsVoxMonitorMessage(MSG *pmsg);
00793 extern void voxMonitorUpdate(long nAudio, long nVox);
00794 extern BOOL IsVoxMonitorOn();
00795 
00796 //  Frame window functions
00797 
00798 extern LRESULT CALLBACK Frame_WndProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
00799 extern void ParseCommandLine(HWND hwnd, LPSTR pszCmdLine);
00800 
00801 //  Initialisation functions
00802 
00803 extern BOOL InitApplication(HINSTANCE hInstance);
00804 extern BOOL InitInstance(HINSTANCE hInstance, LPSTR pszCmdLine, INT nCmdShow);
00805 void SetupICQ(void);
00806 void SetICQData(HKEY hSpeakFreelyKey, char *szSpeakFreelyPath);
00807 
00808 // Default Message Loop
00809 
00810 extern void DefaultMessageLoop();
00811 
00812 //      WAVE file I/O functions
00813 
00814 extern int readWaveInit(HWND hwndApp, LPCLIENT_DATA d, LPSTR szFileName);
00815 extern int readWaveNext(HWND hwnd, LPCLIENT_DATA d);
00816 extern void readWaveTerm(LPCLIENT_DATA d);
00817 
00818 #ifdef MODEM
00819 
00820 //      CRC calculator functions
00821 
00822 extern unsigned short crc(unsigned char *buff, int bufflen);
00823 
00824 //      Modem driver functions
00825 
00826 extern int openModem(HWND hwnd);
00827 extern int closeModem(HWND hwnd);
00828 #endif
00829 
00830 //      Encryption functions
00831 
00832 extern void AES_cbc_encrypt(unsigned char *in,                  // Connect.c
00833                                                         unsigned char *out,
00834                                                         int len, aes_ctx *ctx);
00835 extern void AES_cbc_decrypt(unsigned char *in,                  // Speaker.c
00836                                                         unsigned char *out,
00837                                                         int len, aes_ctx *ctx);
00838 
00839 //      Answering machine functions
00840 
00841 extern int answerOpen(void);
00842 extern void answerSave(struct in_addr IPaddr, LPSTR hostName, soundbuf *sb);
00843 extern void answerSync(void);
00844 extern void answerClose(void);
00845 extern int answerEnabled(void);
00846 
00847 //      Local loopback functions
00848 
00849 extern void loop_flush(LPCLIENT_DATA d);
00850 extern int loop_sendto(LPCLIENT_DATA d, const char *buf, int len,
00851                                            const struct sockaddr *to, int tolen);
00852 extern int loop_recvfrom(LPCLIENT_DATA d, char *buf, int len,
00853                                   struct sockaddr *from, int *fromlen);
00854 extern int loop_samples(LPCLIENT_DATA d);
00855 extern BOOL loop_control_port(LPCLIENT_DATA d);                                                                 
00856 
00857 //      Show Your Face functions
00858 
00859 extern void closeFaceFile(void);
00860 extern int openFaceFile(HWND hwnd);
00861 extern void processFaceRequest(soundbuf *d);
00862 extern void processFaceData(HWND hwnd, LPCLIENT_DATA c, soundbuf *d);
00863 
00864 //      Look Who's Listening interface
00865 
00866 extern int sendLwlMessage(HWND hDlg, int dobye);
00867 extern int lwl_reconnect(HWND hDlg);
00868 
00869 //      RTP protocol functions
00870 
00871 extern int rtp_make_sdes(char **pkt, unsigned long ssrc_i, int port, int exact, int strict);
00872 extern int rtp_make_bye(unsigned char *p, unsigned long ssrc_i, char *raison, int strict);
00873 extern int rtp_make_app(unsigned char *p, unsigned long ssrc_i,
00874                                                 int strict, char *type, char *content);
00875 extern LONG rtpout(soundbuf *sb, unsigned long ssrc_i,
00876                         unsigned long timestamp_i, unsigned short seq_i,
00877                         int spurt);
00878 extern int isValidRTCPpacket(unsigned char *p, int len);
00879 extern int isRTCPByepacket(unsigned char *p, int len);
00880 extern int isRTCPAPPpacket(unsigned char *p, int len, char *name, unsigned char **app_ptr);
00881 extern int isrtp(unsigned char *pkt, int len);
00882 extern int parseSDES(unsigned char *packet, struct rtcp_sdes_request *r);
00883 extern void copySDESitem(char *s, char *d);
00884 extern void string_DES_key(LPSTR key, LPBYTE des_key, char algorithm[16]);
00885 
00886 //      Text chat functions
00887 
00888 #define RTCP_APP_TEXT_CHAT      "SFtc"                  // APP packet name for text chat
00889 #define WM_CHAT_TEXT_SEND (WM_USER + 1004)      // Message sent to frame to transmit text chat
00890 extern VOID chatDialogue(HWND hwndParent);
00891 extern BOOL CALLBACK chatDlgProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
00892 extern void chatLog(HWND hwnd, char *ident, char *text);
00893 
00894 //      Diagnostic console functions
00895 
00896 extern VOID consoleDialogue(HWND hwndParent);
00897 extern BOOL CALLBACK consoleDlgProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
00898 extern void consoleLog(char *text);
00899 extern void vcPrintf(LPCSTR lpFormat, va_list arglist);
00900 extern void cPrintf(LPCSTR lpFormat, ...);
00901 
00902 //      VAT protocol functions
00903 
00904 extern int isvat(unsigned char *pkt, int len);
00905 extern LONG vatout(soundbuf *sb, unsigned long ssrc_i, unsigned long timestamp_i, int spurt);
00906 extern int makeVATid(char **vp, unsigned long ssrc_i);
00907 extern int makevatdone(unsigned char *v, unsigned long ssrc_i);
00908 
00909 //      LPC10 compression functions
00910 
00911 extern void lpc10init(void);
00912 extern int lpc10encode(unsigned char *in, unsigned char *out, int inlen);
00913 extern int lpc10decode(unsigned char *in, unsigned char *out, int inlen);
00914 
00915 //      Spectrum display functions
00916 
00917 extern BOOL spectrumBarGraph;                   // Plot spectrum as bar chart, equaliser style ?
00918 extern BOOL spectrumVoicePrint;                 // Plot spectrum as horizontal "waterfall" ?
00919 extern BOOL spectrumTransmitOnly;               // Show transmitted audio only ?
00920 extern BOOL spectrumReceiveOnly;                // Show received audio only ?
00921 extern BOOL spectrumMaxEnergy;                  // Show maximum energy in packet, not RMS
00922 extern double spectrum(short *samples, int nsamples, double *ps, int nfreqs, double maxpwr);
00923 extern void spectrumEnd(void);                          
00924 extern VOID spectralDialogue(HWND hwndParent);
00925 extern BOOL CALLBACK spectralDlgProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
00926 extern void spectrumUpdate(LPSTR buffer, WORD buflen, DWORD channels,
00927                                                    DWORD rate, DWORD bytesec, WORD align, BOOL isInput);
00928 
00929 //  Utility functions
00930 
00931 extern char *rstring(int resid);
00932 extern char *rfilter(int resid);
00933 extern INT MsgBox(HWND hwndParent, UINT fuType, LPSTR pszFormat, ...);
00934 extern VOID WinPrintf(HDC hdc, INT row, INT col, LPSTR pszFormat, ...);
00935 extern VOID displayHelpTopicString(LPCSTR topicStr);
00936 extern VOID displayHelpTopic(int topicResID);
00937 extern LPSTR SockerrToString(SOCKERR serr);
00938 extern SOCKERR ResetSocket(SOCKET sock);
00939 extern SOCKERR CreateSocket(SOCKET *psock, INT type, ULONG address, PORT port);
00940 extern void playSound(HWND hWnd, LPCLIENT_DATA pClientData, soundbuf *d,
00941                                         int bitsPerSample, int samplesPerSecond);
00942 extern void decodeAnswerPacket(soundbuf *d,
00943                                         int bitsPerSample, int samplesPerSecond,
00944                                         LPSTR *pcmData, DWORD *pcmLength);
00945 extern VOID newConnection(HWND hwnd, LPSTR connectionFile, LPSTR knownHost);                                     
00946 extern void adpcmdecomp( struct soundbuf *sb);                                    
00947 extern int startWaveInput(HWND hwnd);
00948 extern int inputSampleCount(void);
00949 extern void terminateWaveInput(void);
00950 extern void compress2X(soundbuf *asb);
00951 extern void createSoundBuffer(LPSTR buffer, WORD buflen, DWORD channels,
00952                                                           DWORD rate, DWORD bytesec, WORD align);
00953 extern void shipSoundBuffer(HWND hwnd, LPCLIENT_DATA pClientData);                                                        
00954 extern VOID startSoundFile(HWND hwnd, LPSTR pszFile);
00955 extern LPBYTE GIFtoBMP(LPBYTE gif, int imageNumber);
00956 extern void sessionKeyGenerate(LPSTR key, BOOL binary);
00957 extern int makeInternalEncryptionKeys(HWND hwnd, LPCLIENT_DATA d);
00958 extern void multicastJoin(HWND hwnd, int join);
00959 extern void propeller(int control, DWORD value);
00960 extern int obtainOutput(HWND hwnd);
00961 extern unsigned char alaw2ulaw(unsigned char aval);
00962 extern void rate_start(rate_t *rate, int inrate, int outrate);
00963 extern void rate_flow(rate_t *rate, unsigned char *ibuf, unsigned char *obuf,
00964                                           int *isamp, int *osamp);
00965 #ifdef HEXDUMP
00966 extern void xd(void *buf, int bufl, int dochar);
00967 #endif

Generated on Tue Feb 10 08:26:35 2004 for Speak-FreelyforWindows by doxygen1.2.18