00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2010, 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 /*! 00020 * \file 00021 * 00022 * \brief Out-of-call text message support 00023 * 00024 * \author Russell Bryant <russell@digium.com> 00025 * 00026 * The purpose of this API is to provide support for text messages that 00027 * are not session based. The messages are passed into the Asterisk core 00028 * to be routed through the dialplan and potentially sent back out through 00029 * a message technology that has been registered through this API. 00030 */ 00031 00032 #ifndef __AST_MESSAGE_H__ 00033 #define __AST_MESSAGE_H__ 00034 00035 #if defined(__cplusplus) || defined(c_plusplus) 00036 extern "C" { 00037 #endif 00038 00039 /*! 00040 * \brief A text message. 00041 * 00042 * This is an opaque type that represents a text message. 00043 */ 00044 struct ast_msg; 00045 00046 /*! 00047 * \brief A message technology 00048 * 00049 * A message technology is capable of transmitting text messages. 00050 */ 00051 struct ast_msg_tech { 00052 /*! 00053 * \brief Name of this message technology 00054 * 00055 * This is the name that comes at the beginning of a URI for messages 00056 * that should be sent to this message technology implementation. 00057 * For example, messages sent to "xmpp:rbryant@digium.com" would be 00058 * passed to the ast_msg_tech with a name of "xmpp". 00059 */ 00060 const char * const name; 00061 /*! 00062 * \brief Send a message. 00063 * 00064 * \param msg the message to send 00065 * \param to the URI of where the message is being sent 00066 * \param from the URI of where the message was sent from 00067 * 00068 * The fields of the ast_msg are guaranteed not to change during the 00069 * duration of this function call. 00070 * 00071 * \retval 0 success 00072 * \retval non-zero failure 00073 */ 00074 int (* const msg_send)(const struct ast_msg *msg, const char *to, const char *from); 00075 }; 00076 00077 /*! 00078 * \brief Register a message technology 00079 * 00080 * \retval 0 success 00081 * \retval non-zero failure 00082 */ 00083 int ast_msg_tech_register(const struct ast_msg_tech *tech); 00084 00085 /*! 00086 * \brief Unregister a message technology. 00087 * 00088 * \retval 0 success 00089 * \retval non-zero failure 00090 */ 00091 int ast_msg_tech_unregister(const struct ast_msg_tech *tech); 00092 00093 /*! 00094 * \brief Allocate a message. 00095 * 00096 * Allocate a message for the purposes of passing it into the Asterisk core 00097 * to be routed through the dialplan. If ast_msg_queue() is not called, this 00098 * message must be destroyed using ast_msg_destroy(). Otherwise, the message 00099 * core code will take care of it. 00100 * 00101 * \return A message object. This function will return NULL if an allocation 00102 * error occurs. 00103 */ 00104 struct ast_msg *ast_msg_alloc(void); 00105 00106 /*! 00107 * \brief Destroy an ast_msg 00108 * 00109 * This should only be called on a message if it was not 00110 * passed on to ast_msg_queue(). 00111 * 00112 * \return NULL, always. 00113 */ 00114 struct ast_msg *ast_msg_destroy(struct ast_msg *msg); 00115 00116 /*! 00117 * \brief Set the 'to' URI of a message 00118 * 00119 * \retval 0 success 00120 * \retval -1 failure 00121 */ 00122 int __attribute__((format(printf, 2, 3))) 00123 ast_msg_set_to(struct ast_msg *msg, const char *fmt, ...); 00124 00125 /*! 00126 * \brief Set the 'from' URI of a message 00127 * 00128 * \retval 0 success 00129 * \retval -1 failure 00130 */ 00131 int __attribute__((format(printf, 2, 3))) 00132 ast_msg_set_from(struct ast_msg *msg, const char *fmt, ...); 00133 00134 /*! 00135 * \brief Set the 'body' text of a message (in UTF-8) 00136 * 00137 * \retval 0 success 00138 * \retval -1 failure 00139 */ 00140 int __attribute__((format(printf, 2, 3))) 00141 ast_msg_set_body(struct ast_msg *msg, const char *fmt, ...); 00142 00143 /*! 00144 * \brief Set the dialplan context for this message 00145 * 00146 * \retval 0 success 00147 * \retval -1 failure 00148 */ 00149 int __attribute__((format(printf, 2, 3))) 00150 ast_msg_set_context(struct ast_msg *msg, const char *fmt, ...); 00151 00152 /*! 00153 * \brief Set the dialplan extension for this message 00154 * 00155 * \retval 0 success 00156 * \retval -1 failure 00157 */ 00158 int __attribute__((format(printf, 2, 3))) 00159 ast_msg_set_exten(struct ast_msg *msg, const char *fmt, ...); 00160 00161 /*! 00162 * \brief Set a variable on the message 00163 * \note Setting a variable that already exists overwrites the existing variable value 00164 * 00165 * \param name Name of variable to set 00166 * \param value Value of variable to set 00167 * 00168 * \retval 0 success 00169 * \retval -1 failure 00170 */ 00171 int ast_msg_set_var(struct ast_msg *msg, const char *name, const char *value); 00172 00173 /*! 00174 * \brief Get the specified variable on the message 00175 * \note The return value is valid only as long as the ast_message is valid. Hold a reference 00176 * to the message if you plan on storing the return value. Do re-set the same 00177 * message var name while holding a pointer to the result of this function. 00178 * 00179 * \return The value associated with variable "name". NULL if variable not found. 00180 */ 00181 const char *ast_msg_get_var(struct ast_msg *msg, const char *name); 00182 00183 /*! 00184 * \brief Get the body of a message. 00185 * \note The return value is valid only as long as the ast_message is valid. Hold a reference 00186 * to the message if you plan on storing the return value. 00187 * 00188 * \return The body of the messsage, encoded in UTF-8. 00189 */ 00190 const char *ast_msg_get_body(const struct ast_msg *msg); 00191 00192 /*! 00193 * \brief Queue a message for routing through the dialplan. 00194 * 00195 * Regardless of the return value of this function, this funciton will take 00196 * care of ensuring that the message object is properly destroyed when needed. 00197 * 00198 * \retval 0 message successfully queued 00199 * \retval non-zero failure, message not sent to dialplan 00200 */ 00201 int ast_msg_queue(struct ast_msg *msg); 00202 00203 /*! 00204 * \brief Opaque iterator for msg variables 00205 */ 00206 struct ast_msg_var_iterator; 00207 00208 /*! 00209 * \brief Create a new message variable iterator 00210 * \param msg A message whose variables are to be iterated over 00211 * 00212 * \return An opaque pointer to the new iterator 00213 */ 00214 struct ast_msg_var_iterator *ast_msg_var_iterator_init(const struct ast_msg *msg); 00215 00216 /*! 00217 * \brief Get the next variable name and value that is set for sending outbound 00218 * \param msg The message with the variables 00219 * \param i An iterator created with ast_msg_var_iterator_init 00220 * \param name A pointer to the name result pointer 00221 * \param value A pointer to the value result pointer 00222 * 00223 * \retval 0 No more entries 00224 * \retval 1 Valid entry 00225 */ 00226 int ast_msg_var_iterator_next(const struct ast_msg *msg, struct ast_msg_var_iterator *i, const char **name, const char **value); 00227 00228 /*! 00229 * \brief Destroy a message variable iterator 00230 * \param i Iterator to be destroyed 00231 */ 00232 void ast_msg_var_iterator_destroy(struct ast_msg_var_iterator *i); 00233 00234 /*! 00235 * \brief Unref a message var from inside an iterator loop 00236 */ 00237 void ast_msg_var_unref_current(struct ast_msg_var_iterator *i); 00238 00239 #if defined(__cplusplus) || defined(c_plusplus) 00240 } 00241 #endif 00242 00243 #endif /* __AST_MESSAGE_H__ */
1.5.6