Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:50 2007

Asterisk developer's documentation :: Codename Pineapple


manager.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 #ifndef _ASTERISK_MANAGER_H
00020 #define _ASTERISK_MANAGER_H
00021 
00022 #include <stdarg.h>
00023 #include <sys/types.h>
00024 #include <sys/socket.h>
00025 #include <netinet/in.h>
00026 #include <arpa/inet.h>
00027 
00028 #include "asterisk/lock.h"
00029 
00030 /*!
00031  \file
00032  \brief The AMI - Asterisk Manager Interface - is a TCP protocol created to
00033  manage Asterisk with third-party software.
00034 
00035  Manager protocol packages are text fields of the form a: b.  There is
00036  always exactly one space after the colon.
00037 
00038  The first header type is the "Event" header.  Other headers vary from
00039  event to event.  Headers end with standard \r\n termination.
00040  The last line of the manager response or event is an empty line.
00041  (\r\n)
00042 
00043  ** Please try to re-use existing headers to simplify manager message parsing in clients.
00044     Don't re-use an existing header with a new meaning, please.
00045     You can find a reference of standard headers in doc/manager.txt
00046  */
00047 
00048 #define DEFAULT_MANAGER_PORT 5038   /* Default port for Asterisk management via TCP */
00049 
00050 #define EVENT_FLAG_SYSTEM     (1 << 0) /* System events such as module load/unload */
00051 #define EVENT_FLAG_CALL       (1 << 1) /* Call event, such as state change, etc */
00052 #define EVENT_FLAG_LOG        (1 << 2) /* Log events */
00053 #define EVENT_FLAG_VERBOSE    (1 << 3) /* Verbose messages */
00054 #define EVENT_FLAG_COMMAND    (1 << 4) /* Ability to read/set commands */
00055 #define EVENT_FLAG_AGENT      (1 << 5) /* Ability to read/set agent info */
00056 #define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
00057 #define EVENT_FLAG_CONFIG     (1 << 7) /* Ability to modify configurations */
00058 
00059 /* Export manager structures */
00060 #define AST_MAX_MANHEADERS 80
00061 
00062 /* Manager Helper Function */
00063 typedef int (*manager_hook_t)(int, const char *, char *); 
00064 
00065 struct manager_custom_hook {
00066    /*! Identifier */
00067    char *file;
00068    /*! helper function */
00069    manager_hook_t helper;
00070    /*! Linked list information */
00071    AST_RWLIST_ENTRY(manager_custom_hook) list;
00072 };
00073 
00074 /*! Add a custom hook to be called when an event is fired */
00075 /*! \param hook struct manager_custom_hook object to add
00076 */
00077 void ast_manager_register_hook(struct manager_custom_hook *hook);
00078 
00079 /*! Delete a custom hook to be called when an event is fired */
00080 /*! \param hook struct manager_custom_hook object to delete
00081 */
00082 void ast_manager_unregister_hook(struct manager_custom_hook *hook);
00083 
00084 struct mansession;
00085 
00086 struct message {
00087    unsigned int hdrcount;
00088    const char *headers[AST_MAX_MANHEADERS];
00089 };
00090 
00091 struct manager_action {
00092    /*! Name of the action */
00093    const char *action;
00094    /*! Short description of the action */
00095    const char *synopsis;
00096    /*! Detailed description of the action */
00097    const char *description;
00098    /*! Permission required for action.  EVENT_FLAG_* */
00099    int authority;
00100    /*! Function to be called */
00101    int (*func)(struct mansession *s, const struct message *m);
00102    /*! For easy linking */
00103    struct manager_action *next;
00104 };
00105 
00106 /* External routines may register/unregister manager callbacks this way */
00107 #define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
00108 
00109 /* Use ast_manager_register2 to register with help text for new manager commands */
00110 
00111 /*! Register a manager command with the manager interface */
00112 /*!   \param action Name of the requested Action:
00113    \param authority Required authority for this command
00114    \param func Function to call for this command
00115    \param synopsis Help text (one line, up to 30 chars) for CLI manager show commands
00116    \param description Help text, several lines
00117 */
00118 int ast_manager_register2(
00119    const char *action,
00120    int authority,
00121    int (*func)(struct mansession *s, const struct message *m),
00122    const char *synopsis,
00123    const char *description);
00124 
00125 /*! Unregister a registred manager command */
00126 /*!   \param action Name of registred Action:
00127 */
00128 int ast_manager_unregister( char *action );
00129 
00130 /*! External routines may send asterisk manager events this way */
00131 /*!   \param category   Event category, matches manager authorization
00132    \param event   Event name
00133    \param contents   Contents of event
00134 */
00135 
00136 /* XXX the parser in gcc 2.95 gets confused if you don't put a space
00137  * between the last arg before VA_ARGS and the comma */
00138 #define manager_event(category, event, contents , ...)   \
00139         __manager_event(category, event, __FILE__, __LINE__, __PRETTY_FUNCTION__, contents , ## __VA_ARGS__)
00140 
00141 int __attribute__ ((format(printf, 6, 7))) __manager_event(int category, const char *event,
00142                         const char *file, int line, const char *func,
00143                         const char *contents, ...);
00144 
00145 /*! Get header from mananger transaction */
00146 const char *astman_get_header(const struct message *m, char *var);
00147 
00148 /*! Get a linked list of the Variable: headers */
00149 struct ast_variable *astman_get_variables(const struct message *m);
00150 
00151 /*! Send error in manager transaction */
00152 void astman_send_error(struct mansession *s, const struct message *m, char *error);
00153 void astman_send_response(struct mansession *s, const struct message *m, char *resp, char *msg);
00154 void astman_send_ack(struct mansession *s, const struct message *m, char *msg);
00155 void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag);
00156 
00157 void __attribute__ ((format (printf, 2, 3))) astman_append(struct mansession *s, const char *fmt, ...);
00158 
00159 /*! Called by Asterisk initialization */
00160 int init_manager(void);
00161 int reload_manager(void);
00162 
00163 #endif /* _ASTERISK_MANAGER_H */

Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen