Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

manager.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * External call management support 
00005  * 
00006  * Copyright (C) 1999, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License.
00012  *
00013  * Includes code and algorithms from the Zapata library.
00014  *
00015  */
00016 
00017 #ifndef _ASTERISK_MANAGER_H
00018 #define _ASTERISK_MANAGER_H
00019 
00020 #include <stdarg.h>
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <netinet/in.h>
00024 #include <arpa/inet.h>
00025 
00026 #include <asterisk/lock.h>
00027 
00028 /* 
00029  * Call management packages are text fields of the form a: b.  There is
00030  * always exactly one space after the colon.
00031  *
00032  * The first header type is the "Event" header.  Other headers vary from
00033  * event to event.  Headers end with standard \r\n termination.
00034  *
00035  * Some standard headers:
00036  *
00037  * Action: <action>        -- request or notification of a particular action
00038  * Response: <response>    -- response code, like "200 OK"
00039  *
00040  */
00041  
00042 #define DEFAULT_MANAGER_PORT 5038   /* Default port for Asterisk management via TCP */
00043 
00044 #define EVENT_FLAG_SYSTEM     (1 << 0) /* System events such as module load/unload */
00045 #define EVENT_FLAG_CALL       (1 << 1) /* Call event, such as state change, etc */
00046 #define EVENT_FLAG_LOG        (1 << 2) /* Log events */
00047 #define EVENT_FLAG_VERBOSE    (1 << 3) /* Verbose messages */
00048 #define EVENT_FLAG_COMMAND    (1 << 4) /* Ability to read/set commands */
00049 #define EVENT_FLAG_AGENT      (1 << 5) /* Ability to read/set agent info */
00050 #define EVENT_FLAG_USER                 (1 << 6) /* Ability to read/set user info */
00051 
00052 /* Export manager structures */
00053 #define MAX_HEADERS 80
00054 #define MAX_LEN 256
00055 
00056 struct mansession {
00057    pthread_t t;
00058    ast_mutex_t lock;
00059    struct sockaddr_in sin;
00060    int fd;
00061    int blocking;
00062    char username[80];
00063    char challenge[10];
00064    int authenticated;
00065    int readperm;
00066    int writeperm;
00067    char inbuf[MAX_LEN];
00068    int inlen;
00069    int send_events;
00070    struct mansession *next;
00071 };
00072 
00073 
00074 struct message {
00075    int hdrcount;
00076    char headers[MAX_HEADERS][MAX_LEN];
00077 };
00078 
00079 struct manager_action {
00080    /*! Name of the action */
00081    char *action;
00082    /*! Short description of the action */
00083    char *synopsis;
00084    /*! Detailed description of the action */
00085    char *description;
00086    /*! Permission required for action.  EVENT_FLAG_* */
00087    int authority;
00088    /*! Function to be called */
00089    int (*func)(struct mansession *s, struct message *m);
00090    /*! For easy linking */
00091    struct manager_action *next;
00092 };
00093 
00094 int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
00095 
00096 /* External routines may register/unregister manager callbacks this way */
00097 #define ast_manager_register(a, b, c, d) ast_manager_register2(a, b, c, d, NULL)
00098 int ast_manager_register2( char *action, int authority, 
00099                 int (*func)(struct mansession *s, struct message *m), char *synopsis, char *description);
00100 int ast_manager_unregister( char *action );
00101 
00102 /* External routines may send asterisk manager events this way */
00103 extern int manager_event(int category, char *event, char *contents, ...)
00104    __attribute__ ((format (printf, 3,4)));
00105 
00106 extern char *astman_get_header(struct message *m, char *var);
00107 extern void astman_send_error(struct mansession *s, struct message *m, char *error);
00108 extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
00109 extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
00110 
00111 /* Called by Asterisk initialization */
00112 extern int init_manager(void);
00113 extern int reload_manager(void);
00114 #endif

Generated on Sat Nov 25 19:09:40 2006 for Asterisk by  doxygen 1.4.2