event.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2007 - 2008, Digium, Inc.
00005  *
00006  * Russell Bryant <russell@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 /*! \file
00020  *
00021  * \brief Internal generic event system
00022  *
00023  * \author Russell Bryant <russell@digium.com>
00024  */
00025 
00026 /*** MODULEINFO
00027    <support_level>core</support_level>
00028  ***/
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 434471 $")
00033 
00034 #include "asterisk/_private.h"
00035 
00036 #include "asterisk/event.h"
00037 #include "asterisk/linkedlists.h"
00038 #include "asterisk/dlinkedlists.h"
00039 #include "asterisk/lock.h"
00040 #include "asterisk/utils.h"
00041 #include "asterisk/unaligned.h"
00042 #include "asterisk/utils.h"
00043 #include "asterisk/taskprocessor.h"
00044 #include "asterisk/astobj2.h"
00045 #include "asterisk/cli.h"
00046 
00047 /*!
00048  * \brief An event information element
00049  *
00050  * \note The format of this structure is important.  Since these events may
00051  *       be sent directly over a network, changing this structure will break
00052  *       compatibility with older versions.  However, at this point, this code
00053  *       has not made it into a release, so it is still fair game for change.
00054  */
00055 struct ast_event_ie {
00056    enum ast_event_ie_type ie_type:16;
00057    /*! Total length of the IE payload */
00058    uint16_t ie_payload_len;
00059    unsigned char ie_payload[0];
00060 } __attribute__((packed));
00061 
00062 /*!
00063  * \brief The payload for a string information element
00064  */
00065 struct ast_event_ie_str_payload {
00066    /*! \brief A hash calculated with ast_str_hash(), to speed up comparisons */
00067    uint32_t hash;
00068    /*! \brief The actual string, null terminated */
00069    char str[1];
00070 } __attribute__((packed));
00071 
00072 /*!
00073  * \brief An event
00074  *
00075  * An ast_event consists of an event header (this structure), and zero or
00076  * more information elements defined by ast_event_ie.
00077  *
00078  * \note The format of this structure is important.  Since these events may
00079  *       be sent directly over a network, changing this structure will break
00080  *       compatibility with older versions.  However, at this point, this code
00081  *       has not made it into a release, so it is still fair game for change.
00082  */
00083 struct ast_event {
00084    /*! Event type */
00085    enum ast_event_type type:16;
00086    /*! Total length of the event */
00087    uint16_t event_len:16;
00088    /*! The data payload of the event, made up of information elements */
00089    unsigned char payload[0];
00090 } __attribute__((packed));
00091 
00092 
00093 struct ast_event_ie_val {
00094    AST_LIST_ENTRY(ast_event_ie_val) entry;
00095    enum ast_event_ie_type ie_type;
00096    enum ast_event_ie_pltype ie_pltype;
00097    union {
00098       uint32_t uint;
00099       struct {
00100          uint32_t hash;
00101          const char *str;
00102       };
00103       void *raw;
00104    } payload;
00105    size_t raw_datalen;
00106 };
00107 
00108 /*!
00109  * \brief Event Names
00110  */
00111 static const char * const event_names[AST_EVENT_TOTAL] = {
00112    [AST_EVENT_ALL]                 = "All",
00113    [AST_EVENT_CUSTOM]              = "Custom",
00114    [AST_EVENT_MWI]                 = "MWI",
00115    [AST_EVENT_SUB]                 = "Subscription",
00116    [AST_EVENT_UNSUB]               = "Unsubscription",
00117    [AST_EVENT_DEVICE_STATE]        = "DeviceState",
00118    [AST_EVENT_DEVICE_STATE_CHANGE] = "DeviceStateChange",
00119    [AST_EVENT_CEL]                 = "CEL",
00120    [AST_EVENT_SECURITY]            = "Security",
00121    [AST_EVENT_NETWORK_CHANGE]      = "NetworkChange",
00122    [AST_EVENT_PRESENCE_STATE]      = "PresenceState",
00123    [AST_EVENT_ACL_CHANGE]          = "ACLChange",
00124    [AST_EVENT_PING]                = "Ping",
00125 };
00126 
00127 /*!
00128  * \brief IE payload types and names
00129  */
00130 static const struct ie_map {
00131    enum ast_event_ie_pltype ie_pltype;
00132    const char *name;
00133 } ie_maps[AST_EVENT_IE_TOTAL] = {
00134    [AST_EVENT_IE_NEWMSGS]             = { AST_EVENT_IE_PLTYPE_UINT, "NewMessages" },
00135    [AST_EVENT_IE_OLDMSGS]             = { AST_EVENT_IE_PLTYPE_UINT, "OldMessages" },
00136    [AST_EVENT_IE_MAILBOX]             = { AST_EVENT_IE_PLTYPE_STR,  "Mailbox" },
00137    [AST_EVENT_IE_UNIQUEID]            = { AST_EVENT_IE_PLTYPE_UINT, "UniqueID" },
00138    [AST_EVENT_IE_EVENTTYPE]           = { AST_EVENT_IE_PLTYPE_UINT, "EventType" },
00139    [AST_EVENT_IE_EXISTS]              = { AST_EVENT_IE_PLTYPE_UINT, "Exists" },
00140    [AST_EVENT_IE_DEVICE]              = { AST_EVENT_IE_PLTYPE_STR,  "Device" },
00141    [AST_EVENT_IE_STATE]               = { AST_EVENT_IE_PLTYPE_UINT, "State" },
00142    [AST_EVENT_IE_CONTEXT]             = { AST_EVENT_IE_PLTYPE_STR,  "Context" },
00143    [AST_EVENT_IE_EID]                 = { AST_EVENT_IE_PLTYPE_RAW,  "EntityID" },
00144    [AST_EVENT_IE_CEL_EVENT_TYPE]      = { AST_EVENT_IE_PLTYPE_UINT, "CELEventType" },
00145    [AST_EVENT_IE_CEL_EVENT_TIME]      = { AST_EVENT_IE_PLTYPE_UINT, "CELEventTime" },
00146    [AST_EVENT_IE_CEL_EVENT_TIME_USEC] = { AST_EVENT_IE_PLTYPE_UINT, "CELEventTimeUSec" },
00147    [AST_EVENT_IE_CEL_USEREVENT_NAME]  = { AST_EVENT_IE_PLTYPE_STR,  "CELUserEventName" },
00148    [AST_EVENT_IE_CEL_CIDNAME]         = { AST_EVENT_IE_PLTYPE_STR,  "CELCIDName" },
00149    [AST_EVENT_IE_CEL_CIDNUM]          = { AST_EVENT_IE_PLTYPE_STR,  "CELCIDNum" },
00150    [AST_EVENT_IE_CEL_EXTEN]           = { AST_EVENT_IE_PLTYPE_STR,  "CELExten" },
00151    [AST_EVENT_IE_CEL_CONTEXT]         = { AST_EVENT_IE_PLTYPE_STR,  "CELContext" },
00152    [AST_EVENT_IE_CEL_CHANNAME]        = { AST_EVENT_IE_PLTYPE_STR,  "CELChanName" },
00153    [AST_EVENT_IE_CEL_APPNAME]         = { AST_EVENT_IE_PLTYPE_STR,  "CELAppName" },
00154    [AST_EVENT_IE_CEL_APPDATA]         = { AST_EVENT_IE_PLTYPE_STR,  "CELAppData" },
00155    [AST_EVENT_IE_CEL_AMAFLAGS]        = { AST_EVENT_IE_PLTYPE_UINT, "CELAMAFlags" },
00156    [AST_EVENT_IE_CEL_ACCTCODE]        = { AST_EVENT_IE_PLTYPE_STR,  "CELAcctCode" },
00157    [AST_EVENT_IE_CEL_UNIQUEID]        = { AST_EVENT_IE_PLTYPE_STR,  "CELUniqueID" },
00158    [AST_EVENT_IE_CEL_USERFIELD]       = { AST_EVENT_IE_PLTYPE_STR,  "CELUserField" },
00159    [AST_EVENT_IE_CEL_CIDANI]          = { AST_EVENT_IE_PLTYPE_STR,  "CELCIDani" },
00160    [AST_EVENT_IE_CEL_CIDRDNIS]        = { AST_EVENT_IE_PLTYPE_STR,  "CELCIDrdnis" },
00161    [AST_EVENT_IE_CEL_CIDDNID]         = { AST_EVENT_IE_PLTYPE_STR,  "CELCIDdnid" },
00162    [AST_EVENT_IE_CEL_PEER]            = { AST_EVENT_IE_PLTYPE_STR,  "CELPeer" },
00163    [AST_EVENT_IE_CEL_LINKEDID]        = { AST_EVENT_IE_PLTYPE_STR,  "CELLinkedID" },
00164    [AST_EVENT_IE_CEL_PEERACCT]        = { AST_EVENT_IE_PLTYPE_STR,  "CELPeerAcct" },
00165    [AST_EVENT_IE_CEL_EXTRA]           = { AST_EVENT_IE_PLTYPE_STR,  "CELExtra" },
00166    [AST_EVENT_IE_SECURITY_EVENT]      = { AST_EVENT_IE_PLTYPE_UINT, "SecurityEvent" },
00167    [AST_EVENT_IE_EVENT_VERSION]       = { AST_EVENT_IE_PLTYPE_UINT, "EventVersion" },
00168    [AST_EVENT_IE_SERVICE]             = { AST_EVENT_IE_PLTYPE_STR,  "Service" },
00169    [AST_EVENT_IE_MODULE]              = { AST_EVENT_IE_PLTYPE_STR,  "Module" },
00170    [AST_EVENT_IE_ACCOUNT_ID]          = { AST_EVENT_IE_PLTYPE_STR,  "AccountID" },
00171    [AST_EVENT_IE_SESSION_ID]          = { AST_EVENT_IE_PLTYPE_STR,  "SessionID" },
00172    [AST_EVENT_IE_SESSION_TV]          = { AST_EVENT_IE_PLTYPE_STR,  "SessionTV" },
00173    [AST_EVENT_IE_ACL_NAME]            = { AST_EVENT_IE_PLTYPE_STR,  "ACLName" },
00174    [AST_EVENT_IE_LOCAL_ADDR]          = { AST_EVENT_IE_PLTYPE_STR,  "LocalAddress" },
00175    [AST_EVENT_IE_REMOTE_ADDR]         = { AST_EVENT_IE_PLTYPE_STR,  "RemoteAddress" },
00176    [AST_EVENT_IE_EVENT_TV]            = { AST_EVENT_IE_PLTYPE_STR,  "EventTV" },
00177    [AST_EVENT_IE_REQUEST_TYPE]        = { AST_EVENT_IE_PLTYPE_STR,  "RequestType" },
00178    [AST_EVENT_IE_REQUEST_PARAMS]      = { AST_EVENT_IE_PLTYPE_STR,  "RequestParams" },
00179    [AST_EVENT_IE_AUTH_METHOD]         = { AST_EVENT_IE_PLTYPE_STR,  "AuthMethod" },
00180    [AST_EVENT_IE_SEVERITY]            = { AST_EVENT_IE_PLTYPE_STR,  "Severity" },
00181    [AST_EVENT_IE_EXPECTED_ADDR]       = { AST_EVENT_IE_PLTYPE_STR,  "ExpectedAddress" },
00182    [AST_EVENT_IE_CHALLENGE]           = { AST_EVENT_IE_PLTYPE_STR,  "Challenge" },
00183    [AST_EVENT_IE_RESPONSE]            = { AST_EVENT_IE_PLTYPE_STR,  "Response" },
00184    [AST_EVENT_IE_EXPECTED_RESPONSE]   = { AST_EVENT_IE_PLTYPE_STR,  "ExpectedResponse" },
00185    [AST_EVENT_IE_RECEIVED_CHALLENGE]  = { AST_EVENT_IE_PLTYPE_STR,  "ReceivedChallenge" },
00186    [AST_EVENT_IE_RECEIVED_HASH]       = { AST_EVENT_IE_PLTYPE_STR,  "ReceivedHash" },
00187    [AST_EVENT_IE_USING_PASSWORD]      = { AST_EVENT_IE_PLTYPE_UINT, "UsingPassword" },
00188    [AST_EVENT_IE_ATTEMPTED_TRANSPORT] = { AST_EVENT_IE_PLTYPE_STR,  "AttemptedTransport" },
00189    [AST_EVENT_IE_CACHABLE]            = { AST_EVENT_IE_PLTYPE_UINT, "Cachable" },
00190    [AST_EVENT_IE_PRESENCE_PROVIDER]   = { AST_EVENT_IE_PLTYPE_STR,  "PresenceProvider" },
00191    [AST_EVENT_IE_PRESENCE_STATE]      = { AST_EVENT_IE_PLTYPE_UINT, "PresenceState" },
00192    [AST_EVENT_IE_PRESENCE_SUBTYPE]    = { AST_EVENT_IE_PLTYPE_STR,  "PresenceSubtype" },
00193    [AST_EVENT_IE_PRESENCE_MESSAGE]    = { AST_EVENT_IE_PLTYPE_STR,  "PresenceMessage" },
00194 };
00195 
00196 const char *ast_event_get_type_name(const struct ast_event *event)
00197 {
00198    enum ast_event_type type;
00199 
00200    type = ast_event_get_type(event);
00201 
00202    if (type >= ARRAY_LEN(event_names)) {
00203       ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type);
00204       return "";
00205    }
00206 
00207    return event_names[type];
00208 }
00209 
00210 const char *ast_event_get_ie_type_name(enum ast_event_ie_type ie_type)
00211 {
00212    if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
00213       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00214       return "";
00215    }
00216 
00217    return ie_maps[ie_type].name;
00218 }
00219 
00220 enum ast_event_ie_pltype ast_event_get_ie_pltype(enum ast_event_ie_type ie_type)
00221 {
00222    if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
00223       ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
00224       return AST_EVENT_IE_PLTYPE_UNKNOWN;
00225    }
00226 
00227    return ie_maps[ie_type].ie_pltype;
00228 }
00229 
00230 size_t ast_event_get_size(const struct ast_event *event)
00231 {
00232    size_t res;
00233 
00234    res = ntohs(event->event_len);
00235 
00236    return res;
00237 }
00238 
00239 /*! \brief Subscription event check list. */
00240 struct ast_ev_check_list {
00241    AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
00242 };
00243 
00244 int ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event)
00245 {
00246    int res = 0;
00247 
00248    iterator->event_len = ast_event_get_size(event);
00249    iterator->event = event;
00250    if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) {
00251       iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
00252    } else {
00253       iterator->ie = NULL;
00254       res = -1;
00255    }
00256 
00257    return res;
00258 }
00259 
00260 int ast_event_iterator_next(struct ast_event_iterator *iterator)
00261 {
00262    iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
00263    return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
00264 }
00265 
00266 enum ast_event_ie_type ast_event_iterator_get_ie_type(struct ast_event_iterator *iterator)
00267 {
00268    return ntohs(iterator->ie->ie_type);
00269 }
00270 
00271 uint32_t ast_event_iterator_get_ie_uint(struct ast_event_iterator *iterator)
00272 {
00273    return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
00274 }
00275 
00276 const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator)
00277 {
00278    const struct ast_event_ie_str_payload *str_payload;
00279 
00280    str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
00281 
00282    return str_payload ? str_payload->str : NULL;
00283 }
00284 
00285 static void *event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
00286 {
00287    return iterator->ie->ie_payload;
00288 }
00289 
00290 enum ast_event_type ast_event_get_type(const struct ast_event *event)
00291 {
00292    return ntohs(event->type);
00293 }
00294 
00295 uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
00296 {
00297    const uint32_t *ie_val;
00298 
00299    ie_val = ast_event_get_ie_raw(event, ie_type);
00300 
00301    return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
00302 }
00303 
00304 const char *ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
00305 {
00306    const struct ast_event_ie_str_payload *str_payload;
00307 
00308    str_payload = ast_event_get_ie_raw(event, ie_type);
00309 
00310    return str_payload ? str_payload->str : NULL;
00311 }
00312 
00313 const void *ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
00314 {
00315    struct ast_event_iterator iterator;
00316    int res;
00317 
00318    for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
00319       if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
00320          return event_iterator_get_ie_raw(&iterator);
00321       }
00322    }
00323 
00324    return NULL;
00325 }
00326 
00327 static uint16_t event_iterator_get_ie_raw_payload_len(struct ast_event_iterator *iterator)
00328 {
00329    return ntohs(iterator->ie->ie_payload_len);
00330 }
00331 
00332 uint16_t ast_event_get_ie_raw_payload_len(const struct ast_event *event, enum ast_event_ie_type ie_type)
00333 {
00334    struct ast_event_iterator iterator;
00335    int res;
00336 
00337    for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
00338       if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
00339          return event_iterator_get_ie_raw_payload_len(&iterator);
00340       }
00341    }
00342 
00343    return 0;
00344 }
00345 
00346 
00347 int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_type,
00348    const char *str)
00349 {
00350    struct ast_event_ie_str_payload *str_payload;
00351    size_t payload_len;
00352 
00353    payload_len = sizeof(*str_payload) + strlen(str);
00354    str_payload = ast_alloca(payload_len);
00355 
00356    strcpy(str_payload->str, str);
00357    str_payload->hash = ast_str_hash(str);
00358 
00359    return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
00360 }
00361 
00362 int ast_event_append_ie_uint(struct ast_event **event, enum ast_event_ie_type ie_type,
00363    uint32_t data)
00364 {
00365    data = htonl(data);
00366    return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
00367 }
00368 
00369 int ast_event_append_ie_bitflags(struct ast_event **event, enum ast_event_ie_type ie_type,
00370    uint32_t flags)
00371 {
00372    flags = htonl(flags);
00373    return ast_event_append_ie_raw(event, ie_type, &flags, sizeof(flags));
00374 }
00375 
00376 int ast_event_append_ie_raw(struct ast_event **event, enum ast_event_ie_type ie_type,
00377    const void *data, size_t data_len)
00378 {
00379    struct ast_event_ie *ie;
00380    struct ast_event *old_event;
00381    unsigned int extra_len;
00382    uint16_t event_len;
00383 
00384    event_len = ntohs((*event)->event_len);
00385    extra_len = sizeof(*ie) + data_len;
00386 
00387    old_event = *event;
00388    *event = ast_realloc(*event, event_len + extra_len);
00389    if (!*event) {
00390       ast_free(old_event);
00391       return -1;
00392    }
00393 
00394    ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
00395    ie->ie_type = htons(ie_type);
00396    ie->ie_payload_len = htons(data_len);
00397    memcpy(ie->ie_payload, data, data_len);
00398 
00399    (*event)->event_len = htons(event_len + extra_len);
00400 
00401    return 0;
00402 }
00403 
00404 struct ast_event *ast_event_new(enum ast_event_type type, ...)
00405 {
00406    va_list ap;
00407    struct ast_event *event;
00408    enum ast_event_ie_type ie_type;
00409    struct ast_event_ie_val *ie_val;
00410    AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
00411 
00412    /* Invalid type */
00413    if (type >= AST_EVENT_TOTAL) {
00414       ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
00415          "type '%u'!\n", type);
00416       return NULL;
00417    }
00418 
00419    va_start(ap, type);
00420    for (ie_type = va_arg(ap, enum ast_event_ie_type);
00421       ie_type != AST_EVENT_IE_END;
00422       ie_type = va_arg(ap, enum ast_event_ie_type))
00423    {
00424       struct ast_event_ie_val *ie_value = ast_alloca(sizeof(*ie_value));
00425       int insert = 0;
00426 
00427       memset(ie_value, 0, sizeof(*ie_value));
00428       ie_value->ie_type = ie_type;
00429       ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
00430 
00431       switch (ie_value->ie_pltype) {
00432       case AST_EVENT_IE_PLTYPE_UINT:
00433          ie_value->payload.uint = va_arg(ap, uint32_t);
00434          insert = 1;
00435          break;
00436       case AST_EVENT_IE_PLTYPE_BITFLAGS:
00437          ie_value->payload.uint = va_arg(ap, uint32_t);
00438          insert = 1;
00439          break;
00440       case AST_EVENT_IE_PLTYPE_STR:
00441          ie_value->payload.str = va_arg(ap, const char *);
00442          insert = 1;
00443          break;
00444       case AST_EVENT_IE_PLTYPE_RAW:
00445       {
00446          void *data = va_arg(ap, void *);
00447          size_t datalen = va_arg(ap, size_t);
00448          ie_value->payload.raw = ast_alloca(datalen);
00449          memcpy(ie_value->payload.raw, data, datalen);
00450          ie_value->raw_datalen = datalen;
00451          insert = 1;
00452          break;
00453       }
00454       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00455       case AST_EVENT_IE_PLTYPE_EXISTS:
00456          break;
00457       }
00458 
00459       if (insert) {
00460          AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
00461       } else {
00462          ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
00463       }
00464    }
00465    va_end(ap);
00466 
00467    if (!(event = ast_calloc(1, sizeof(*event)))) {
00468       return NULL;
00469    }
00470 
00471    event->type = htons(type);
00472    event->event_len = htons(sizeof(*event));
00473 
00474    AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
00475       switch (ie_val->ie_pltype) {
00476       case AST_EVENT_IE_PLTYPE_STR:
00477          ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
00478          break;
00479       case AST_EVENT_IE_PLTYPE_UINT:
00480          ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
00481          break;
00482       case AST_EVENT_IE_PLTYPE_BITFLAGS:
00483          ast_event_append_ie_bitflags(&event, ie_val->ie_type, ie_val->payload.uint);
00484          break;
00485       case AST_EVENT_IE_PLTYPE_RAW:
00486          ast_event_append_ie_raw(&event, ie_val->ie_type,
00487                ie_val->payload.raw, ie_val->raw_datalen);
00488          break;
00489       case AST_EVENT_IE_PLTYPE_EXISTS:
00490       case AST_EVENT_IE_PLTYPE_UNKNOWN:
00491          break;
00492       }
00493 
00494       /* realloc inside one of the append functions failed */
00495       if (!event) {
00496          return NULL;
00497       }
00498    }
00499 
00500    if (!ast_event_get_ie_raw(event, AST_EVENT_IE_EID)) {
00501       /* If the event is originating on this server, add the server's
00502        * entity ID to the event. */
00503       ast_event_append_eid(&event);
00504    }
00505 
00506    return event;
00507 }
00508 
00509 int ast_event_append_eid(struct ast_event **event)
00510 {
00511    return ast_event_append_ie_raw(event, AST_EVENT_IE_EID,
00512          &ast_eid_default, sizeof(ast_eid_default));
00513 }
00514 
00515 void ast_event_destroy(struct ast_event *event)
00516 {
00517    ast_free(event);
00518 }
00519 
00520 size_t ast_event_minimum_length(void)
00521 {
00522    return sizeof(struct ast_event);
00523 }

Generated on Thu Apr 16 06:27:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6