1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <dirent.h>
#include <errno.h>
#ifdef __APPLE__
#include "dlfcn-compat.h"
#include "poll-compat.h"
#else
#include <dlfcn.h>
#include <sys/poll.h>
#endif
#define BUFSIZE 150
#define MAX_HEADERS 256
#define MAX_LEN 150
#define PROXY_BANNER "Asterisk Call Manager Proxy"
#define PROXY_SHUTDOWN "ProxyMessage: Proxy Shutting Down"
#define ACTION_ID "ActionID"
struct ast_server {
char nickname[80];
char ast_host[40];
char ast_port[10];
char ast_user[80];
char ast_pass[80];
char ast_events[10];
int status; /* TODO: have this mean something */
struct ast_server *next;
};
struct proxy_user {
char username[80];
char secret[80];
char channel[80];
char icontext[80];
char ocontext[80];
struct proxy_user *next;
};
struct proxyconfig {
struct ast_server *serverlist;
struct proxy_user *userlist;
char listen_addr[INET_ADDRSTRLEN];
int listen_port;
char inputformat[80];
char outputformat[80];
int autofilter;
char key[80];
char proc_user[30];
char proc_group[30];
char logfile[80];
int retryinterval;
int maxretries;
};
struct iohandler {
int (*read) ();
int (*write) ();
int (*onconnect) ();
int *(*autodisconnect)(void);
char formatname[80];
void *dlhandle;
struct iohandler *next;
};
struct mansession {
pthread_t t;
pthread_mutex_t lock;
struct sockaddr_in sin;
int fd;
char inbuf[MAX_LEN];
int inlen;
struct iohandler *input;
struct iohandler *output;
int autofilter;
int inputcomplete;
int authenticated;
int connected;
struct ast_server *server;
struct proxy_user user;
char actionid[MAX_LEN];
struct mansession *next;
};
struct message {
int hdrcount;
char headers[MAX_HEADERS][MAX_LEN];
int in_command;
struct mansession *session;
};
struct proxyconfig pc;
extern int debug;
/* Common Function Prototypes */
void debugmsg (const char *, ...);
const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia);
int AddHeader(struct message *m, const char *fmt, ...);
void debugmsg (const char *fmt, ...);
void logmsg (const char *fmt, ...);
int StartServer(struct ast_server *srv);
int WriteAsterisk(struct message *m);
char *astman_get_header(struct message *m, char *var);
int proxyerror_do(struct mansession *s, char *err);
int get_input(struct mansession *s, char *output);
int SetIOHandlers(struct mansession *s, char *ifmt, char *ofmt);
void destroy_session(struct mansession *s);
int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec);
|