2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * AMI - Asterisk Management Interface
21 * External call management support
24 #ifndef _ASTERISK_MANAGER_H
25 #define _ASTERISK_MANAGER_H
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
33 #include "asterisk/lock.h"
37 \brief The AMI - Asterisk Manager Interface - is a TCP protocol created to
38 manage Asterisk with third-party software.
40 Manager protocol packages are text fields of the form a: b. There is
41 always exactly one space after the colon.
43 The first header type is the "Event" header. Other headers vary from
44 event to event. Headers end with standard \r\n termination.
45 The last line of the manager response or event is an empty line.
48 ** Please try to re-use existing headers to simplify manager message parsing in clients.
49 Don't re-use an existing header with a new meaning, please.
50 You can find a reference of standard headers in
55 #define DEFAULT_MANAGER_PORT 5038 /* Default port for Asterisk management via TCP */
57 #define EVENT_FLAG_SYSTEM (1 << 0) /* System events such as module load/unload */
58 #define EVENT_FLAG_CALL (1 << 1) /* Call event, such as state change, etc */
59 #define EVENT_FLAG_LOG (1 << 2) /* Log events */
60 #define EVENT_FLAG_VERBOSE (1 << 3) /* Verbose messages */
61 #define EVENT_FLAG_COMMAND (1 << 4) /* Ability to read/set commands */
62 #define EVENT_FLAG_AGENT (1 << 5) /* Ability to read/set agent info */
63 #define EVENT_FLAG_USER (1 << 6) /* Ability to read/set user info */
65 /* Export manager structures */
66 #define MAX_HEADERS 80
70 struct eventqent *next;
75 /*! Execution thread */
77 /*! Thread lock -- don't use in action callbacks, it's already taken care of */
80 struct sockaddr_in sin;
83 /*! Whether or not we're busy doing an action */
85 /*! Whether or not we're "dead" */
87 /*! Logged in username */
89 /*! Authentication challenge */
91 /*! Authentication status */
93 /*! Authorization for reading */
95 /*! Authorization for writing */
101 /* Queued events that we've not had the ability to send yet */
102 struct eventqent *eventq;
103 struct mansession *next;
109 char headers[MAX_HEADERS][MAX_LEN];
112 struct manager_action {
113 /*! Name of the action */
115 /*! Short description of the action */
116 const char *synopsis;
117 /*! Detailed description of the action */
118 const char *description;
119 /*! Permission required for action. EVENT_FLAG_* */
121 /*! Function to be called */
122 int (*func)(struct mansession *s, struct message *m);
123 /*! For easy linking */
124 struct manager_action *next;
127 int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
129 /* External routines may register/unregister manager callbacks this way */
130 #define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
132 /* Use ast_manager_register2 to register with help text for new manager commands */
134 /*! Register a manager command with the manager interface */
135 /*! \param action Name of the requested Action:
136 \param authority Required authority for this command
137 \param func Function to call for this command
138 \param synopsis Help text (one line, up to 30 chars) for CLI manager show commands
139 \param description Help text, several lines
141 int ast_manager_register2(
144 int (*func)(struct mansession *s, struct message *m),
145 const char *synopsis,
146 const char *description);
148 /*! Unregister a registred manager command */
149 /*! \param action Name of registred Action:
151 int ast_manager_unregister( char *action );
153 /*! External routines may send asterisk manager events this way */
154 /*! \param category Event category, matches manager authorization
155 \param event Event name
156 \param contents Contents of event
158 extern int manager_event(int category, char *event, char *contents, ...)
159 __attribute__ ((format (printf, 3,4)));
161 /*! Get header from mananger transaction */
162 extern char *astman_get_header(struct message *m, char *var);
164 /*! Get a linked list of the Variable: headers */
165 struct ast_variable *astman_get_variables(struct message *m);
167 /*! Send error in manager transaction */
168 extern void astman_send_error(struct mansession *s, struct message *m, char *error);
169 extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
170 extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
172 /*! Called by Asterisk initialization */
173 extern int init_manager(void);
174 /*! Called by Asterisk initialization */
175 extern int reload_manager(void);
177 #endif /* _ASTERISK_MANAGER_H */