2002-09-02 15:20:28 +00:00
|
|
|
/*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2002-09-02 15:20:28 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2002-09-02 15:20:28 +00:00
|
|
|
*
|
2005-08-25 23:17:47 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2002-09-02 15:20:28 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2002-09-02 15:20:28 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2002-09-02 15:20:28 +00:00
|
|
|
#ifndef _ASTERISK_MANAGER_H
|
|
|
|
#define _ASTERISK_MANAGER_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2002-12-11 00:15:13 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2002-09-02 15:20:28 +00:00
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
2003-08-13 15:25:16 +00:00
|
|
|
|
2005-03-02 05:58:13 +00:00
|
|
|
/*!
|
2005-10-26 23:11:36 +00:00
|
|
|
\file
|
|
|
|
\brief The AMI - Asterisk Manager Interface - is a TCP protocol created to
|
|
|
|
manage Asterisk with third-party software.
|
2005-03-02 05:58:13 +00:00
|
|
|
|
|
|
|
Manager protocol packages are text fields of the form a: b. There is
|
|
|
|
always exactly one space after the colon.
|
|
|
|
|
|
|
|
The first header type is the "Event" header. Other headers vary from
|
|
|
|
event to event. Headers end with standard \r\n termination.
|
2005-08-25 23:17:47 +00:00
|
|
|
The last line of the manager response or event is an empty line.
|
|
|
|
(\r\n)
|
2005-03-02 05:58:13 +00:00
|
|
|
|
2005-08-25 23:17:47 +00:00
|
|
|
** Please try to re-use existing headers to simplify manager message parsing in clients.
|
|
|
|
Don't re-use an existing header with a new meaning, please.
|
2005-10-26 23:11:36 +00:00
|
|
|
You can find a reference of standard headers in doc/manager.txt
|
2002-09-02 15:20:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_MANAGER_PORT 5038 /* Default port for Asterisk management via TCP */
|
|
|
|
|
|
|
|
#define EVENT_FLAG_SYSTEM (1 << 0) /* System events such as module load/unload */
|
|
|
|
#define EVENT_FLAG_CALL (1 << 1) /* Call event, such as state change, etc */
|
|
|
|
#define EVENT_FLAG_LOG (1 << 2) /* Log events */
|
|
|
|
#define EVENT_FLAG_VERBOSE (1 << 3) /* Verbose messages */
|
|
|
|
#define EVENT_FLAG_COMMAND (1 << 4) /* Ability to read/set commands */
|
|
|
|
#define EVENT_FLAG_AGENT (1 << 5) /* Ability to read/set agent info */
|
2003-04-14 18:47:36 +00:00
|
|
|
#define EVENT_FLAG_USER (1 << 6) /* Ability to read/set user info */
|
2002-09-02 15:20:28 +00:00
|
|
|
|
2004-06-02 20:08:08 +00:00
|
|
|
/* Export manager structures */
|
2002-12-11 00:15:13 +00:00
|
|
|
#define MAX_HEADERS 80
|
|
|
|
#define MAX_LEN 256
|
|
|
|
|
2005-09-28 23:10:14 +00:00
|
|
|
struct eventqent {
|
|
|
|
struct eventqent *next;
|
2005-09-30 16:49:23 +00:00
|
|
|
char eventdata[1];
|
2005-09-28 23:10:14 +00:00
|
|
|
};
|
|
|
|
|
2002-12-11 00:15:13 +00:00
|
|
|
struct mansession {
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Execution thread */
|
2002-12-11 00:15:13 +00:00
|
|
|
pthread_t t;
|
2005-09-28 23:10:14 +00:00
|
|
|
/*! Thread lock -- don't use in action callbacks, it's already taken care of */
|
|
|
|
ast_mutex_t __lock;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! socket address */
|
2002-12-11 00:15:13 +00:00
|
|
|
struct sockaddr_in sin;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! TCP socket */
|
2002-12-11 00:15:13 +00:00
|
|
|
int fd;
|
2005-09-28 23:10:14 +00:00
|
|
|
/*! Whether or not we're busy doing an action */
|
|
|
|
int busy;
|
2005-09-29 20:37:01 +00:00
|
|
|
/*! Whether or not we're "dead" */
|
|
|
|
int dead;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Logged in username */
|
2002-12-11 00:15:13 +00:00
|
|
|
char username[80];
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Authentication challenge */
|
2003-03-10 06:00:17 +00:00
|
|
|
char challenge[10];
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Authentication status */
|
2002-12-11 00:15:13 +00:00
|
|
|
int authenticated;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Authorization for reading */
|
2002-12-11 00:15:13 +00:00
|
|
|
int readperm;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Authorization for writing */
|
2002-12-11 00:15:13 +00:00
|
|
|
int writeperm;
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Buffer */
|
2002-12-11 00:15:13 +00:00
|
|
|
char inbuf[MAX_LEN];
|
|
|
|
int inlen;
|
2004-03-01 21:12:32 +00:00
|
|
|
int send_events;
|
2005-09-28 23:10:14 +00:00
|
|
|
/* Queued events that we've not had the ability to send yet */
|
|
|
|
struct eventqent *eventq;
|
2005-10-04 22:25:15 +00:00
|
|
|
/* Timeout for ast_carefulwrite() */
|
|
|
|
int writetimeout;
|
2002-12-11 00:15:13 +00:00
|
|
|
struct mansession *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct message {
|
|
|
|
int hdrcount;
|
|
|
|
char headers[MAX_HEADERS][MAX_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct manager_action {
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! Name of the action */
|
2005-03-22 19:09:12 +00:00
|
|
|
const char *action;
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! Short description of the action */
|
2005-03-22 19:09:12 +00:00
|
|
|
const char *synopsis;
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! Detailed description of the action */
|
2005-03-22 19:09:12 +00:00
|
|
|
const char *description;
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! Permission required for action. EVENT_FLAG_* */
|
2002-12-11 00:15:13 +00:00
|
|
|
int authority;
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! Function to be called */
|
2002-12-11 00:15:13 +00:00
|
|
|
int (*func)(struct mansession *s, struct message *m);
|
2004-06-02 20:08:08 +00:00
|
|
|
/*! For easy linking */
|
2002-12-11 00:15:13 +00:00
|
|
|
struct manager_action *next;
|
|
|
|
};
|
|
|
|
|
2004-03-01 21:12:32 +00:00
|
|
|
int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
|
|
|
|
|
2002-12-11 00:15:13 +00:00
|
|
|
/* External routines may register/unregister manager callbacks this way */
|
2004-06-02 20:08:08 +00:00
|
|
|
#define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
|
2005-03-02 05:58:13 +00:00
|
|
|
|
|
|
|
/* Use ast_manager_register2 to register with help text for new manager commands */
|
|
|
|
|
|
|
|
/*! Register a manager command with the manager interface */
|
|
|
|
/*! \param action Name of the requested Action:
|
|
|
|
\param authority Required authority for this command
|
|
|
|
\param func Function to call for this command
|
|
|
|
\param synopsis Help text (one line, up to 30 chars) for CLI manager show commands
|
|
|
|
\param description Help text, several lines
|
|
|
|
*/
|
|
|
|
int ast_manager_register2(
|
2005-03-22 19:09:12 +00:00
|
|
|
const char *action,
|
2005-03-02 05:58:13 +00:00
|
|
|
int authority,
|
|
|
|
int (*func)(struct mansession *s, struct message *m),
|
2005-03-22 19:09:12 +00:00
|
|
|
const char *synopsis,
|
|
|
|
const char *description);
|
2005-03-02 05:58:13 +00:00
|
|
|
|
|
|
|
/*! Unregister a registred manager command */
|
|
|
|
/*! \param action Name of registred Action:
|
|
|
|
*/
|
2002-12-11 00:15:13 +00:00
|
|
|
int ast_manager_unregister( char *action );
|
|
|
|
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! External routines may send asterisk manager events this way */
|
|
|
|
/*! \param category Event category, matches manager authorization
|
|
|
|
\param event Event name
|
|
|
|
\param contents Contents of event
|
|
|
|
*/
|
2002-09-02 15:20:28 +00:00
|
|
|
extern int manager_event(int category, char *event, char *contents, ...)
|
|
|
|
__attribute__ ((format (printf, 3,4)));
|
|
|
|
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Get header from mananger transaction */
|
2003-03-31 17:40:18 +00:00
|
|
|
extern char *astman_get_header(struct message *m, char *var);
|
2005-07-15 23:24:51 +00:00
|
|
|
|
|
|
|
/*! Get a linked list of the Variable: headers */
|
|
|
|
struct ast_variable *astman_get_variables(struct message *m);
|
|
|
|
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Send error in manager transaction */
|
2003-09-08 16:44:36 +00:00
|
|
|
extern void astman_send_error(struct mansession *s, struct message *m, char *error);
|
|
|
|
extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
|
|
|
|
extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
|
2003-03-31 17:40:18 +00:00
|
|
|
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Called by Asterisk initialization */
|
2002-09-02 15:20:28 +00:00
|
|
|
extern int init_manager(void);
|
2005-03-02 05:58:13 +00:00
|
|
|
/*! Called by Asterisk initialization */
|
2002-09-02 15:20:28 +00:00
|
|
|
extern int reload_manager(void);
|
2005-08-30 18:32:10 +00:00
|
|
|
|
|
|
|
#endif /* _ASTERISK_MANAGER_H */
|