980909e8879ae70f25c3af5223625dd9f2d457b3
[asterisk/asterisk.git] / include / asterisk / manager.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * External call management support 
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License.
12  *
13  * Includes code and algorithms from the Zapata library.
14  *
15  */
16
17 #ifndef _ASTERISK_MANAGER_H
18 #define _ASTERISK_MANAGER_H
19
20 #include <stdarg.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25
26 /* 
27  * Call management packages are text fields of the form a: b.  There is
28  * always exactly one space after the colon.
29  *
30  * The first header type is the "Event" header.  Other headers vary from
31  * event to event.  Headers end with standard \r\n termination.
32  *
33  * Some standard headers:
34  *
35  * Action: <action>                     -- request or notification of a particular action
36  * Response: <response>         -- response code, like "200 OK"
37  *
38  */
39  
40 #define DEFAULT_MANAGER_PORT 5038       /* Default port for Asterisk management via TCP */
41
42 #define EVENT_FLAG_SYSTEM               (1 << 0) /* System events such as module load/unload */
43 #define EVENT_FLAG_CALL                 (1 << 1) /* Call event, such as state change, etc */
44 #define EVENT_FLAG_LOG                  (1 << 2) /* Log events */
45 #define EVENT_FLAG_VERBOSE              (1 << 3) /* Verbose messages */
46 #define EVENT_FLAG_COMMAND              (1 << 4) /* Ability to read/set commands */
47 #define EVENT_FLAG_AGENT                (1 << 5) /* Ability to read/set agent info */
48
49 /* JDG: export manager structures */
50 #define MAX_HEADERS 80
51 #define MAX_LEN 256
52
53 struct mansession {
54         pthread_t t;
55         pthread_mutex_t lock;
56         struct sockaddr_in sin;
57         int fd;
58         int blocking;
59         char username[80];
60         char challenge[10];
61         int authenticated;
62         int readperm;
63         int writeperm;
64         char inbuf[MAX_LEN];
65         int inlen;
66         
67         struct mansession *next;
68 };
69
70
71 struct message {
72         int hdrcount;
73         char headers[MAX_HEADERS][MAX_LEN];
74 };
75
76 struct manager_action {
77         char action[256];
78         char *synopsis;
79         int authority;
80         int (*func)(struct mansession *s, struct message *m);
81         struct manager_action *next;
82 };
83
84 /* External routines may register/unregister manager callbacks this way */
85 int ast_manager_register( char *action, int authority, 
86                                          int (*func)(struct mansession *s, struct message *m), char *synopsis);
87 int ast_manager_unregister( char *action );
88 /* /JDG */
89
90 /* External routines may send asterisk manager events this way */
91 extern int manager_event(int category, char *event, char *contents, ...)
92         __attribute__ ((format (printf, 3,4)));
93
94 /* Called by Asterisk initialization */
95 extern int init_manager(void);
96 extern int reload_manager(void);
97 #endif