Add description to manager_action structure, and add some comments.
[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 #include <asterisk/lock.h>
27
28 /* 
29  * Call management packages are text fields of the form a: b.  There is
30  * always exactly one space after the colon.
31  *
32  * The first header type is the "Event" header.  Other headers vary from
33  * event to event.  Headers end with standard \r\n termination.
34  *
35  * Some standard headers:
36  *
37  * Action: <action>                     -- request or notification of a particular action
38  * Response: <response>         -- response code, like "200 OK"
39  *
40  */
41  
42 #define DEFAULT_MANAGER_PORT 5038       /* Default port for Asterisk management via TCP */
43
44 #define EVENT_FLAG_SYSTEM               (1 << 0) /* System events such as module load/unload */
45 #define EVENT_FLAG_CALL                 (1 << 1) /* Call event, such as state change, etc */
46 #define EVENT_FLAG_LOG                  (1 << 2) /* Log events */
47 #define EVENT_FLAG_VERBOSE              (1 << 3) /* Verbose messages */
48 #define EVENT_FLAG_COMMAND              (1 << 4) /* Ability to read/set commands */
49 #define EVENT_FLAG_AGENT                (1 << 5) /* Ability to read/set agent info */
50 #define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
51
52 /* Export manager structures */
53 #define MAX_HEADERS 80
54 #define MAX_LEN 256
55
56 struct mansession {
57         pthread_t t;
58         ast_mutex_t lock;
59         struct sockaddr_in sin;
60         int fd;
61         int blocking;
62         char username[80];
63         char challenge[10];
64         int authenticated;
65         int readperm;
66         int writeperm;
67         char inbuf[MAX_LEN];
68         int inlen;
69         int send_events;
70         struct mansession *next;
71 };
72
73
74 struct message {
75         int hdrcount;
76         char headers[MAX_HEADERS][MAX_LEN];
77 };
78
79 struct manager_action {
80         /*! Name of the action */
81         char *action;
82         /*! Short description of the action */
83         char *synopsis;
84         /*! Detailed description of the action */
85         char *description;
86         /*! Permission required for action.  EVENT_FLAG_* */
87         int authority;
88         /*! Function to be called */
89         int (*func)(struct mansession *s, struct message *m);
90         /*! For easy linking */
91         struct manager_action *next;
92 };
93
94 int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
95
96 /* External routines may register/unregister manager callbacks this way */
97 #define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
98 int ast_manager_register2( char *action, int authority, 
99                                          int (*func)(struct mansession *s, struct message *m), char *synopsis, char *description);
100 int ast_manager_unregister( char *action );
101
102 /* External routines may send asterisk manager events this way */
103 extern int manager_event(int category, char *event, char *contents, ...)
104         __attribute__ ((format (printf, 3,4)));
105
106 extern char *astman_get_header(struct message *m, char *var);
107 extern void astman_send_error(struct mansession *s, struct message *m, char *error);
108 extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
109 extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
110
111 /* Called by Asterisk initialization */
112 extern int init_manager(void);
113 extern int reload_manager(void);
114 #endif