| 1 |
#ifndef PROTON_MESSAGE_H |
| 2 |
#define PROTON_MESSAGE_H 1 |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <proton/import_export.h> |
| 26 |
#include <proton/types.h> |
| 27 |
#include <proton/codec.h> |
| 28 |
#include <proton/error.h> |
| 29 |
#include <proton/type_compat.h> |
| 30 |
|
| 31 |
#ifdef __cplusplus |
| 32 |
extern "C" { |
| 33 |
#endif |
| 34 |
|
| 35 |
/** |
| 36 |
* @file |
| 37 |
* |
| 38 |
* @copybrief message |
| 39 |
* |
| 40 |
* @addtogroup message |
| 41 |
* @{ |
| 42 |
*/ |
| 43 |
|
| 44 |
/** |
| 45 |
* An AMQP Message object. |
| 46 |
* |
| 47 |
* An AMQP Message object is a mutable holder of message content that |
| 48 |
* may be used to generate and encode or decode and access AMQP |
| 49 |
* formatted message data. |
| 50 |
*/ |
| 51 |
typedef struct pn_message_t pn_message_t; |
| 52 |
|
| 53 |
/** |
| 54 |
* Default priority for messages. |
| 55 |
*/ |
| 56 |
#define PN_DEFAULT_PRIORITY (4) |
| 57 |
|
| 58 |
/** |
| 59 |
* Construct a new ::pn_message_t. |
| 60 |
* |
| 61 |
* Every message that is constructed must be freed using |
| 62 |
* ::pn_message_free(). |
| 63 |
* |
| 64 |
* @return pointer to a new ::pn_message_t |
| 65 |
*/ |
| 66 |
PN_EXTERN pn_message_t * pn_message(void); |
| 67 |
|
| 68 |
/** |
| 69 |
* Free a previously constructed ::pn_message_t. |
| 70 |
* |
| 71 |
* @param[in] msg pointer to a ::pn_message_t or NULL |
| 72 |
*/ |
| 73 |
PN_EXTERN void pn_message_free(pn_message_t *msg); |
| 74 |
|
| 75 |
/** |
| 76 |
* Clears the content of a ::pn_message_t. |
| 77 |
* |
| 78 |
* When pn_message_clear returns, the supplied ::pn_message_t will be |
| 79 |
* emptied of all content and effectively returned to the same state |
| 80 |
* as if it was just created. |
| 81 |
* |
| 82 |
* @param[in] msg pointer to the ::pn_message_t to be cleared |
| 83 |
*/ |
| 84 |
PN_EXTERN void pn_message_clear(pn_message_t *msg); |
| 85 |
|
| 86 |
/** |
| 87 |
* Access the error code of a message. |
| 88 |
* |
| 89 |
* Every operation on a message that can result in an error will set |
| 90 |
* the message's error code in case of error. The pn_message_errno() |
| 91 |
* call will access the error code of the most recent failed |
| 92 |
* operation. |
| 93 |
* |
| 94 |
* @param[in] msg a message |
| 95 |
* @return the message's error code |
| 96 |
*/ |
| 97 |
PN_EXTERN int pn_message_errno(pn_message_t *msg); |
| 98 |
|
| 99 |
/** |
| 100 |
* Access the error information for a message. |
| 101 |
* |
| 102 |
* Every operation on a message that can result in an error will |
| 103 |
* update the error information held by its error descriptor should |
| 104 |
* that operation fail. The pn_message_error() call will access the |
| 105 |
* error information of the most recent failed operation. The pointer |
| 106 |
* returned by this call is valid until the message is freed. |
| 107 |
* |
| 108 |
* @param[in] msg a message |
| 109 |
* @return the message's error descriptor |
| 110 |
*/ |
| 111 |
PN_EXTERN pn_error_t *pn_message_error(pn_message_t *msg); |
| 112 |
|
| 113 |
/** |
| 114 |
* Get the inferred flag for a message. |
| 115 |
* |
| 116 |
* The inferred flag for a message indicates how the message content |
| 117 |
* is encoded into AMQP sections. If inferred is true then binary and |
| 118 |
* list values in the body of the message will be encoded as AMQP DATA |
| 119 |
* and AMQP SEQUENCE sections, respectively. If inferred is false, |
| 120 |
* then all values in the body of the message will be encoded as AMQP |
| 121 |
* VALUE sections regardless of their type. Use |
| 122 |
* ::pn_message_set_inferred to set the value. |
| 123 |
* |
| 124 |
* @param[in] msg a message object |
| 125 |
* @return the value of the inferred flag for the message |
| 126 |
*/ |
| 127 |
PN_EXTERN bool pn_message_is_inferred(pn_message_t *msg); |
| 128 |
|
| 129 |
/** |
| 130 |
* Set the inferred flag for a message. |
| 131 |
* |
| 132 |
* See ::pn_message_is_inferred() for a description of what the |
| 133 |
* inferred flag is. |
| 134 |
* |
| 135 |
* @param[in] msg a message object |
| 136 |
* @param[in] inferred the new value of the inferred flag |
| 137 |
* @return zero on success or an error code on failure |
| 138 |
*/ |
| 139 |
PN_EXTERN int pn_message_set_inferred(pn_message_t *msg, bool inferred); |
| 140 |
|
| 141 |
/** |
| 142 |
* Get the durable flag for a message. |
| 143 |
* |
| 144 |
* The durable flag indicates that any parties taking responsibility |
| 145 |
* for the message must durably store the content. |
| 146 |
* |
| 147 |
* @param[in] msg a message object |
| 148 |
* @return the value of the durable flag |
| 149 |
*/ |
| 150 |
PN_EXTERN bool pn_message_is_durable (pn_message_t *msg); |
| 151 |
|
| 152 |
/** |
| 153 |
* Set the durable flag for a message. |
| 154 |
* |
| 155 |
* See ::pn_message_is_durable() for a description of the durable |
| 156 |
* flag. |
| 157 |
* |
| 158 |
* @param[in] msg a message object |
| 159 |
* @param[in] durable the new value of the durable flag |
| 160 |
* @return zero on success or an error code on failure |
| 161 |
*/ |
| 162 |
PN_EXTERN int pn_message_set_durable (pn_message_t *msg, bool durable); |
| 163 |
|
| 164 |
/** |
| 165 |
* Get the priority for a message. |
| 166 |
* |
| 167 |
* The priority of a message impacts ordering guarantees. Within a |
| 168 |
* given ordered context, higher priority messages may jump ahead of |
| 169 |
* lower priority messages. |
| 170 |
* |
| 171 |
* @param[in] msg a message object |
| 172 |
* @return the message priority |
| 173 |
*/ |
| 174 |
PN_EXTERN uint8_t pn_message_get_priority (pn_message_t *msg); |
| 175 |
|
| 176 |
/** |
| 177 |
* Set the priority for a message. |
| 178 |
* |
| 179 |
* See ::pn_message_get_priority() for details on message priority. |
| 180 |
* |
| 181 |
* @param[in] msg a message object |
| 182 |
* @param[in] priority the new priority for the message |
| 183 |
* @return zero on success or an error code on failure |
| 184 |
*/ |
| 185 |
PN_EXTERN int pn_message_set_priority (pn_message_t *msg, uint8_t priority); |
| 186 |
|
| 187 |
/** |
| 188 |
* Get the ttl for a message. |
| 189 |
* |
| 190 |
* The ttl for a message determines how long a message is considered |
| 191 |
* live. When a message is held for retransmit, the ttl is |
| 192 |
* decremented. Once the ttl reaches zero, the message is considered |
| 193 |
* dead. Once a message is considered dead it may be dropped. Use |
| 194 |
* ::pn_message_set_ttl() to set the ttl for a message. |
| 195 |
* |
| 196 |
* @param[in] msg a message object |
| 197 |
* @return the ttl in milliseconds |
| 198 |
*/ |
| 199 |
PN_EXTERN pn_millis_t pn_message_get_ttl (pn_message_t *msg); |
| 200 |
|
| 201 |
/** |
| 202 |
* Set the ttl for a message. |
| 203 |
* |
| 204 |
* See ::pn_message_get_ttl() for a detailed description of message ttl. |
| 205 |
* |
| 206 |
* @param[in] msg a message object |
| 207 |
* @param[in] ttl the new value for the message ttl |
| 208 |
* @return zero on success or an error code on failure |
| 209 |
*/ |
| 210 |
PN_EXTERN int pn_message_set_ttl (pn_message_t *msg, pn_millis_t ttl); |
| 211 |
|
| 212 |
/** |
| 213 |
* Get the first acquirer flag for a message. |
| 214 |
* |
| 215 |
* When set to true, the first acquirer flag for a message indicates |
| 216 |
* that the recipient of the message is the first recipient to acquire |
| 217 |
* the message, i.e. there have been no failed delivery attempts to |
| 218 |
* other acquirers. Note that this does not mean the message has not |
| 219 |
* been delivered to, but not acquired, by other recipients. |
| 220 |
* |
| 221 |
* @param[in] msg a message object |
| 222 |
* @return the first acquirer flag for the message |
| 223 |
*/ |
| 224 |
PN_EXTERN bool pn_message_is_first_acquirer (pn_message_t *msg); |
| 225 |
|
| 226 |
/** |
| 227 |
* Set the first acquirer flag for a message. |
| 228 |
* |
| 229 |
* See ::pn_message_is_first_acquirer() for details on the first |
| 230 |
* acquirer flag. |
| 231 |
* |
| 232 |
* @param[in] msg a message object |
| 233 |
* @param[in] first the new value for the first acquirer flag |
| 234 |
* @return zero on success or an error code on failure |
| 235 |
*/ |
| 236 |
PN_EXTERN int pn_message_set_first_acquirer (pn_message_t *msg, bool first); |
| 237 |
|
| 238 |
/** |
| 239 |
* Get the delivery count for a message. |
| 240 |
* |
| 241 |
* The delivery count field tracks how many attempts have been made to |
| 242 |
* delivery a message. Use ::pn_message_set_delivery_count() to set |
| 243 |
* the delivery count for a message. |
| 244 |
* |
| 245 |
* @param[in] msg a message object |
| 246 |
* @return the delivery count for the message |
| 247 |
*/ |
| 248 |
PN_EXTERN uint32_t pn_message_get_delivery_count (pn_message_t *msg); |
| 249 |
|
| 250 |
/** |
| 251 |
* Set the delivery count for a message. |
| 252 |
* |
| 253 |
* See ::pn_message_get_delivery_count() for details on what the |
| 254 |
* delivery count means. |
| 255 |
* |
| 256 |
* @param[in] msg a message object |
| 257 |
* @param[in] count the new delivery count |
| 258 |
* @return zero on success or an error code on failure |
| 259 |
*/ |
| 260 |
PN_EXTERN int pn_message_set_delivery_count (pn_message_t *msg, uint32_t count); |
| 261 |
|
| 262 |
/** |
| 263 |
* Get/set the id for a message. |
| 264 |
* |
| 265 |
* The message id provides a globally unique identifier for a message. |
| 266 |
* A message id can be an a string, an unsigned long, a uuid or a |
| 267 |
* binary value. This operation returns a pointer to a ::pn_data_t |
| 268 |
* that can be used to access and/or modify the value of the message |
| 269 |
* id. The pointer is valid until the message is freed. See |
| 270 |
* ::pn_data_t for details on how to get/set the value. |
| 271 |
* |
| 272 |
* @param[in] msg a message object |
| 273 |
* @return pointer to a ::pn_data_t holding the id |
| 274 |
*/ |
| 275 |
PN_EXTERN pn_data_t * pn_message_id (pn_message_t *msg); |
| 276 |
|
| 277 |
/** |
| 278 |
* Get the id for a message. |
| 279 |
* |
| 280 |
* The message id provides a globally unique identifier for a message. |
| 281 |
* A message id can be an a string, an unsigned long, a uuid or a |
| 282 |
* binary value. This operation returns the value of the id using the |
| 283 |
* ::pn_atom_t discriminated union. See ::pn_atom_t for details on how |
| 284 |
* to access the value. |
| 285 |
* |
| 286 |
* @param[in] msg a message object |
| 287 |
* @return the message id |
| 288 |
*/ |
| 289 |
PN_EXTERN pn_msgid_t pn_message_get_id (pn_message_t *msg); |
| 290 |
|
| 291 |
/** |
| 292 |
* Set the id for a message. |
| 293 |
* |
| 294 |
* See ::pn_message_get_id() for more details on the meaning of the |
| 295 |
* message id. Note that only string, unsigned long, uuid, or binary |
| 296 |
* values are permitted. |
| 297 |
* |
| 298 |
* @param[in] msg a message object |
| 299 |
* @param[in] id the new value of the message id |
| 300 |
* @return zero on success or an error code on failure |
| 301 |
*/ |
| 302 |
PN_EXTERN int pn_message_set_id (pn_message_t *msg, pn_msgid_t id); |
| 303 |
|
| 304 |
/** |
| 305 |
* Get the user id for a message. |
| 306 |
* |
| 307 |
* The pointer referenced by the ::pn_bytes_t struct will be valid |
| 308 |
* until any one of the following operations occur: |
| 309 |
* |
| 310 |
* - ::pn_message_free() |
| 311 |
* - ::pn_message_clear() |
| 312 |
* - ::pn_message_set_user_id() |
| 313 |
* |
| 314 |
* @param[in] msg a message object |
| 315 |
* @return a pn_bytes_t referencing the message's user_id |
| 316 |
*/ |
| 317 |
PN_EXTERN pn_bytes_t pn_message_get_user_id (pn_message_t *msg); |
| 318 |
|
| 319 |
/** |
| 320 |
* Set the user id for a message. |
| 321 |
* |
| 322 |
* This operation copies the bytes referenced by the provided |
| 323 |
* ::pn_bytes_t struct. |
| 324 |
* |
| 325 |
* @param[in] msg a message object |
| 326 |
* @param[in] user_id the new user_id for the message |
| 327 |
* @return zero on success or an error code on failure |
| 328 |
*/ |
| 329 |
PN_EXTERN int pn_message_set_user_id (pn_message_t *msg, pn_bytes_t user_id); |
| 330 |
|
| 331 |
/** |
| 332 |
* Get the address for a message. |
| 333 |
* |
| 334 |
* This operation will return NULL if no address has been set or if |
| 335 |
* the address has been set to NULL. The pointer returned by this |
| 336 |
* operation is valid until any one of the following operations occur: |
| 337 |
* |
| 338 |
* - ::pn_message_free() |
| 339 |
* - ::pn_message_clear() |
| 340 |
* - ::pn_message_set_address() |
| 341 |
* |
| 342 |
* @param[in] msg a message object |
| 343 |
* @return a pointer to the address of the message (or NULL) |
| 344 |
*/ |
| 345 |
PN_EXTERN const char * pn_message_get_address (pn_message_t *msg); |
| 346 |
|
| 347 |
/** |
| 348 |
* Set the address for a message. |
| 349 |
* |
| 350 |
* The supplied address pointer must either be NULL or reference a NUL |
| 351 |
* terminated string. When the pointer is NULL, the address of the |
| 352 |
* message is set to NULL. When the pointer is non NULL, the contents |
| 353 |
* are copied into the message. |
| 354 |
* |
| 355 |
* @param[in] msg a message object |
| 356 |
* @param[in] address a pointer to the new address (or NULL) |
| 357 |
* @return zero on success or an error code on failure |
| 358 |
*/ |
| 359 |
PN_EXTERN int pn_message_set_address (pn_message_t *msg, const char *address); |
| 360 |
|
| 361 |
/** |
| 362 |
* Get the subject for a message. |
| 363 |
* |
| 364 |
* This operation will return NULL if no subject has been set or if |
| 365 |
* the subject has been set to NULL. The pointer returned by this |
| 366 |
* operation is valid until any one of the following operations occur: |
| 367 |
* |
| 368 |
* - ::pn_message_free() |
| 369 |
* - ::pn_message_clear() |
| 370 |
* - ::pn_message_set_subject() |
| 371 |
* |
| 372 |
* @param[in] msg a message object |
| 373 |
* @return a pointer to the subject of the message (or NULL) |
| 374 |
*/ |
| 375 |
PN_EXTERN const char * pn_message_get_subject (pn_message_t *msg); |
| 376 |
|
| 377 |
/** |
| 378 |
* Set the subject for a message. |
| 379 |
* |
| 380 |
* The supplied subject pointer must either be NULL or reference a NUL |
| 381 |
* terminated string. When the pointer is NULL, the subject is set to |
| 382 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 383 |
* the message. |
| 384 |
* |
| 385 |
* @param[in] msg a message object |
| 386 |
* @param[in] subject a pointer to the new subject (or NULL) |
| 387 |
* @return zero on success or an error code on failure |
| 388 |
*/ |
| 389 |
PN_EXTERN int pn_message_set_subject (pn_message_t *msg, const char *subject); |
| 390 |
|
| 391 |
/** |
| 392 |
* Get the reply_to for a message. |
| 393 |
* |
| 394 |
* This operation will return NULL if no reply_to has been set or if |
| 395 |
* the reply_to has been set to NULL. The pointer returned by this |
| 396 |
* operation is valid until any one of the following operations occur: |
| 397 |
* |
| 398 |
* - ::pn_message_free() |
| 399 |
* - ::pn_message_clear() |
| 400 |
* - ::pn_message_set_reply_to() |
| 401 |
* |
| 402 |
* @param[in] msg a message object |
| 403 |
* @return a pointer to the reply_to of the message (or NULL) |
| 404 |
*/ |
| 405 |
PN_EXTERN const char * pn_message_get_reply_to (pn_message_t *msg); |
| 406 |
|
| 407 |
/** |
| 408 |
* Set the reply_to for a message. |
| 409 |
* |
| 410 |
* The supplied reply_to pointer must either be NULL or reference a NUL |
| 411 |
* terminated string. When the pointer is NULL, the reply_to is set to |
| 412 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 413 |
* the message. |
| 414 |
* |
| 415 |
* @param[in] msg a message object |
| 416 |
* @param[in] reply_to a pointer to the new reply_to (or NULL) |
| 417 |
* @return zero on success or an error code on failure |
| 418 |
*/ |
| 419 |
PN_EXTERN int pn_message_set_reply_to (pn_message_t *msg, const char *reply_to); |
| 420 |
|
| 421 |
/** |
| 422 |
* Get/set the correlation id for a message. |
| 423 |
* |
| 424 |
* A correlation id can be an a string, an unsigned long, a uuid or a |
| 425 |
* binary value. This operation returns a pointer to a ::pn_data_t |
| 426 |
* that can be used to access and/or modify the value of the |
| 427 |
* correlation id. The pointer is valid until the message is freed. |
| 428 |
* See ::pn_data_t for details on how to get/set the value. |
| 429 |
* |
| 430 |
* @param[in] msg a message object |
| 431 |
* @return pointer to a ::pn_data_t holding the correlation id |
| 432 |
*/ |
| 433 |
PN_EXTERN pn_data_t * pn_message_correlation_id (pn_message_t *msg); |
| 434 |
|
| 435 |
/** |
| 436 |
* Get the correlation id for a message. |
| 437 |
* |
| 438 |
* A correlation id can be an a string, an unsigned long, a uuid or a |
| 439 |
* binary value. This operation returns the value of the id using the |
| 440 |
* ::pn_atom_t discriminated union. See ::pn_atom_t for details on how |
| 441 |
* to access the value. |
| 442 |
* |
| 443 |
* @param[in] msg a message object |
| 444 |
* @return the message id |
| 445 |
*/ |
| 446 |
PN_EXTERN pn_msgid_t pn_message_get_correlation_id (pn_message_t *msg); |
| 447 |
|
| 448 |
/** |
| 449 |
* Set the correlation id for a message. |
| 450 |
* |
| 451 |
* See ::pn_message_get_correlation_id() for more details on the |
| 452 |
* meaning of the correlation id. Note that only string, unsigned |
| 453 |
* long, uuid, or binary values are permitted. |
| 454 |
* |
| 455 |
* @param[in] msg a message object |
| 456 |
* @param[in] id the new value of the message id |
| 457 |
* @return zero on success or an error code on failure |
| 458 |
*/ |
| 459 |
PN_EXTERN int pn_message_set_correlation_id (pn_message_t *msg, pn_msgid_t id); |
| 460 |
|
| 461 |
/** |
| 462 |
* Get the content_type for a message. |
| 463 |
* |
| 464 |
* This operation will return NULL if no content_type has been set or if |
| 465 |
* the content_type has been set to NULL. The pointer returned by this |
| 466 |
* operation is valid until any one of the following operations occur: |
| 467 |
* |
| 468 |
* - ::pn_message_free() |
| 469 |
* - ::pn_message_clear() |
| 470 |
* - ::pn_message_set_content_type() |
| 471 |
* |
| 472 |
* @param[in] msg a message object |
| 473 |
* @return a pointer to the content_type of the message (or NULL) |
| 474 |
*/ |
| 475 |
PN_EXTERN const char * pn_message_get_content_type (pn_message_t *msg); |
| 476 |
|
| 477 |
/** |
| 478 |
* Set the content_type for a message. |
| 479 |
* |
| 480 |
* The supplied content_type pointer must either be NULL or reference a NUL |
| 481 |
* terminated string. When the pointer is NULL, the content_type is set to |
| 482 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 483 |
* the message. |
| 484 |
* |
| 485 |
* @param[in] msg a message object |
| 486 |
* @param[in] type a pointer to the new content_type (or NULL) |
| 487 |
* @return zero on success or an error code on failure |
| 488 |
*/ |
| 489 |
PN_EXTERN int pn_message_set_content_type (pn_message_t *msg, const char *type); |
| 490 |
|
| 491 |
/** |
| 492 |
* Get the content_encoding for a message. |
| 493 |
* |
| 494 |
* This operation will return NULL if no content_encoding has been set or if |
| 495 |
* the content_encoding has been set to NULL. The pointer returned by this |
| 496 |
* operation is valid until any one of the following operations occur: |
| 497 |
* |
| 498 |
* - ::pn_message_free() |
| 499 |
* - ::pn_message_clear() |
| 500 |
* - ::pn_message_set_content_encoding() |
| 501 |
* |
| 502 |
* @param[in] msg a message object |
| 503 |
* @return a pointer to the content_encoding of the message (or NULL) |
| 504 |
*/ |
| 505 |
PN_EXTERN const char * pn_message_get_content_encoding (pn_message_t *msg); |
| 506 |
|
| 507 |
/** |
| 508 |
* Set the content_encoding for a message. |
| 509 |
* |
| 510 |
* The supplied content_encoding pointer must either be NULL or reference a NUL |
| 511 |
* terminated string. When the pointer is NULL, the content_encoding is set to |
| 512 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 513 |
* the message. |
| 514 |
* |
| 515 |
* @param[in] msg a message object |
| 516 |
* @param[in] encoding a pointer to the new content_encoding (or NULL) |
| 517 |
* @return zero on success or an error code on failure |
| 518 |
*/ |
| 519 |
PN_EXTERN int pn_message_set_content_encoding (pn_message_t *msg, const char *encoding); |
| 520 |
|
| 521 |
/** |
| 522 |
* Get the expiry time for a message. |
| 523 |
* |
| 524 |
* A zero value for the expiry time indicates that the message will |
| 525 |
* never expire. This is the default value. |
| 526 |
* |
| 527 |
* @param[in] msg a message object |
| 528 |
* @return the expiry time for the message |
| 529 |
*/ |
| 530 |
PN_EXTERN pn_timestamp_t pn_message_get_expiry_time (pn_message_t *msg); |
| 531 |
|
| 532 |
/** |
| 533 |
* Set the expiry time for a message. |
| 534 |
* |
| 535 |
* See ::pn_message_get_expiry_time() for more details. |
| 536 |
* |
| 537 |
* @param[in] msg a message object |
| 538 |
* @param[in] time the new expiry time for the message |
| 539 |
* @return zero on success or an error code on failure |
| 540 |
*/ |
| 541 |
PN_EXTERN int pn_message_set_expiry_time (pn_message_t *msg, pn_timestamp_t time); |
| 542 |
|
| 543 |
/** |
| 544 |
* Get the creation time for a message. |
| 545 |
* |
| 546 |
* A zero value for the creation time indicates that the creation time |
| 547 |
* has not been set. This is the default value. |
| 548 |
* |
| 549 |
* @param[in] msg a message object |
| 550 |
* @return the creation time for the message |
| 551 |
*/ |
| 552 |
PN_EXTERN pn_timestamp_t pn_message_get_creation_time (pn_message_t *msg); |
| 553 |
|
| 554 |
/** |
| 555 |
* Set the creation time for a message. |
| 556 |
* |
| 557 |
* See ::pn_message_get_creation_time() for more details. |
| 558 |
* |
| 559 |
* @param[in] msg a message object |
| 560 |
* @param[in] time the new creation time for the message |
| 561 |
* @return zero on success or an error code on failure |
| 562 |
*/ |
| 563 |
PN_EXTERN int pn_message_set_creation_time (pn_message_t *msg, pn_timestamp_t time); |
| 564 |
|
| 565 |
/** |
| 566 |
* Get the group_id for a message. |
| 567 |
* |
| 568 |
* This operation will return NULL if no group_id has been set or if |
| 569 |
* the group_id has been set to NULL. The pointer returned by this |
| 570 |
* operation is valid until any one of the following operations occur: |
| 571 |
* |
| 572 |
* - ::pn_message_free() |
| 573 |
* - ::pn_message_clear() |
| 574 |
* - ::pn_message_set_group_id() |
| 575 |
* |
| 576 |
* @param[in] msg a message object |
| 577 |
* @return a pointer to the group_id of the message (or NULL) |
| 578 |
*/ |
| 579 |
PN_EXTERN const char * pn_message_get_group_id (pn_message_t *msg); |
| 580 |
|
| 581 |
/** |
| 582 |
* Set the group_id for a message. |
| 583 |
* |
| 584 |
* The supplied group_id pointer must either be NULL or reference a NUL |
| 585 |
* terminated string. When the pointer is NULL, the group_id is set to |
| 586 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 587 |
* the message. |
| 588 |
* |
| 589 |
* @param[in] msg a message object |
| 590 |
* @param[in] group_id a pointer to the new group_id (or NULL) |
| 591 |
* @return zero on success or an error code on failure |
| 592 |
*/ |
| 593 |
PN_EXTERN int pn_message_set_group_id (pn_message_t *msg, const char *group_id); |
| 594 |
|
| 595 |
/** |
| 596 |
* Get the group sequence for a message. |
| 597 |
* |
| 598 |
* The group sequence of a message identifies the relative ordering of |
| 599 |
* messages within a group. The default value for the group sequence |
| 600 |
* of a message is zero. |
| 601 |
* |
| 602 |
* @param[in] msg a message object |
| 603 |
* @return the group sequence for the message |
| 604 |
*/ |
| 605 |
PN_EXTERN pn_sequence_t pn_message_get_group_sequence (pn_message_t *msg); |
| 606 |
|
| 607 |
/** |
| 608 |
* Set the group sequence for a message. |
| 609 |
* |
| 610 |
* See ::pn_message_get_group_sequence() for details on what the group |
| 611 |
* sequence means. |
| 612 |
* |
| 613 |
* @param[in] msg a message object |
| 614 |
* @param[in] n the new group sequence for the message |
| 615 |
* @return zero on success or an error code on failure |
| 616 |
*/ |
| 617 |
PN_EXTERN int pn_message_set_group_sequence (pn_message_t *msg, pn_sequence_t n); |
| 618 |
|
| 619 |
/** |
| 620 |
* Get the reply_to_group_id for a message. |
| 621 |
* |
| 622 |
* This operation will return NULL if no reply_to_group_id has been set or if |
| 623 |
* the reply_to_group_id has been set to NULL. The pointer returned by this |
| 624 |
* operation is valid until any one of the following operations occur: |
| 625 |
* |
| 626 |
* - ::pn_message_free() |
| 627 |
* - ::pn_message_clear() |
| 628 |
* - ::pn_message_set_reply_to_group_id() |
| 629 |
* |
| 630 |
* @param[in] msg a message object |
| 631 |
* @return a pointer to the reply_to_group_id of the message (or NULL) |
| 632 |
*/ |
| 633 |
PN_EXTERN const char * pn_message_get_reply_to_group_id (pn_message_t *msg); |
| 634 |
|
| 635 |
/** |
| 636 |
* Set the reply_to_group_id for a message. |
| 637 |
* |
| 638 |
* The supplied reply_to_group_id pointer must either be NULL or reference a NUL |
| 639 |
* terminated string. When the pointer is NULL, the reply_to_group_id is set to |
| 640 |
* NULL. When the pointer is non NULL, the contents are copied into |
| 641 |
* the message. |
| 642 |
* |
| 643 |
* @param[in] msg a message object |
| 644 |
* @param[in] reply_to_group_id a pointer to the new reply_to_group_id (or NULL) |
| 645 |
* @return zero on success or an error code on failure |
| 646 |
*/ |
| 647 |
PN_EXTERN int pn_message_set_reply_to_group_id (pn_message_t *msg, const char *reply_to_group_id); |
| 648 |
|
| 649 |
/** |
| 650 |
* Get/set the delivery instructions for a message. |
| 651 |
* |
| 652 |
* This operation returns a pointer to a ::pn_data_t representing the |
| 653 |
* content of the delivery instructions section of a message. The |
| 654 |
* pointer is valid until the message is freed and may be used to both |
| 655 |
* access and modify the content of the delivery instructions section |
| 656 |
* of a message. |
| 657 |
* |
| 658 |
* The ::pn_data_t must either be empty or consist of a symbol keyed |
| 659 |
* map in order to be considered valid delivery instructions. |
| 660 |
* |
| 661 |
* @param[in] msg a message object |
| 662 |
* @return a pointer to the delivery instructions |
| 663 |
*/ |
| 664 |
PN_EXTERN pn_data_t *pn_message_instructions(pn_message_t *msg); |
| 665 |
|
| 666 |
/** |
| 667 |
* Get/set the annotations for a message. |
| 668 |
* |
| 669 |
* This operation returns a pointer to a ::pn_data_t representing the |
| 670 |
* content of the annotations section of a message. The pointer is |
| 671 |
* valid until the message is freed and may be used to both access and |
| 672 |
* modify the content of the annotations section of a message. |
| 673 |
* |
| 674 |
* The ::pn_data_t must either be empty or consist of a symbol keyed |
| 675 |
* map in order to be considered valid message annotations. |
| 676 |
* |
| 677 |
* @param[in] msg a message object |
| 678 |
* @return a pointer to the message annotations |
| 679 |
*/ |
| 680 |
PN_EXTERN pn_data_t *pn_message_annotations(pn_message_t *msg); |
| 681 |
|
| 682 |
/** |
| 683 |
* Get and set the properties for a message. |
| 684 |
* |
| 685 |
* This operation returns a pointer to a ::pn_data_t representing the |
| 686 |
* content of the properties section of a message. The pointer is |
| 687 |
* valid until the message is freed and may be used to both access and |
| 688 |
* modify the content of the properties section of a message. |
| 689 |
* |
| 690 |
* The ::pn_data_t must either be empty or consist of a string keyed |
| 691 |
* map in order to be considered valid message properties. |
| 692 |
* |
| 693 |
* @param[in] msg a message object |
| 694 |
* @return a pointer to the message properties |
| 695 |
*/ |
| 696 |
PN_EXTERN pn_data_t *pn_message_properties(pn_message_t *msg); |
| 697 |
|
| 698 |
/** |
| 699 |
* Get and set the body of a message. |
| 700 |
* |
| 701 |
* This operation returns a pointer to a ::pn_data_t representing the |
| 702 |
* body of a message. The pointer is valid until the message is freed |
| 703 |
* and may be used to both access and modify the content of the |
| 704 |
* message body. |
| 705 |
* |
| 706 |
* @param[in] msg a message object |
| 707 |
* @return a pointer to the message body |
| 708 |
*/ |
| 709 |
PN_EXTERN pn_data_t *pn_message_body(pn_message_t *msg); |
| 710 |
|
| 711 |
/** |
| 712 |
* Decode/load message content from AMQP formatted binary data. |
| 713 |
* |
| 714 |
* Upon invoking this operation, any existing message content will be |
| 715 |
* cleared and replaced with the content from the provided binary |
| 716 |
* data. |
| 717 |
* |
| 718 |
* @param[in] msg a message object |
| 719 |
* @param[in] bytes the start of the encoded AMQP data |
| 720 |
* @param[in] size the size of the encoded AMQP data |
| 721 |
* @return zero on success or an error code on failure |
| 722 |
*/ |
| 723 |
PN_EXTERN int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size); |
| 724 |
|
| 725 |
/** |
| 726 |
* Encode a message as AMQP formatted binary data. |
| 727 |
* |
| 728 |
* If the buffer space provided is insufficient to store the content |
| 729 |
* held in the message, the operation will fail and return a |
| 730 |
* PN_OVERFLOW error code. |
| 731 |
* |
| 732 |
* @param[in] msg a message object |
| 733 |
* @param[in] bytes the start of empty buffer space |
| 734 |
* @param[inout] size the amount of empty buffer space. |
| 735 |
* On return size holds the amount of data written |
| 736 |
* @return zero on success or an error code on failure |
| 737 |
*/ |
| 738 |
PN_EXTERN int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size); |
| 739 |
|
| 740 |
/** |
| 741 |
* **Unsettled API**: Encode a message, allocating space if necessary |
| 742 |
* |
| 743 |
* @param[in] msg A message object. |
| 744 |
* @param[inout] buf Used to encode msg. |
| 745 |
* If buf->start == NULL memory is allocated with malloc(). |
| 746 |
* If buf->size is not large enough, buffer is expanded with realloc(). |
| 747 |
* On return buf holds the address and size of the final buffer. |
| 748 |
* buf->size may be larger than the length of the encoded message. |
| 749 |
* @return The length of the encoded message or an error code (<0). |
| 750 |
* On error pn_message_error(msg) will provide more information. |
| 751 |
*/ |
| 752 |
PN_EXTERN ssize_t pn_message_encode2(pn_message_t *msg, pn_rwbytes_t *buf); |
| 753 |
|
| 754 |
struct pn_link_t; |
| 755 |
|
| 756 |
/** |
| 757 |
* **Unsettled API** |
| 758 |
* |
| 759 |
* Encode and send a message on a sender link. |
| 760 |
* |
| 761 |
* Performs the following steps: |
| 762 |
* - call pn_message_encode2() to encode the message to a buffer |
| 763 |
* - call pn_link_send() to send the encoded message bytes |
| 764 |
* - call pn_link_advance() to indicate the message is complete |
| 765 |
* |
| 766 |
* Note: you must create a delivery for the message before calling |
| 767 |
* pn_message_send() see pn_delivery() |
| 768 |
* |
| 769 |
* @param[in] msg A message object. |
| 770 |
* @param[in] sender A sending link. |
| 771 |
* @param[inout] buf See pn_message_encode2. If buf == NULL then |
| 772 |
* any memory needed for encoding will be allocated and freed by pn_message_send(). |
| 773 |
* |
| 774 |
* @return The length of the encoded message or an error code (<0). |
| 775 |
* On error pn_message_error(msg) will provide more information. |
| 776 |
*/ |
| 777 |
PN_EXTERN ssize_t pn_message_send(pn_message_t *msg, pn_link_t *sender, pn_rwbytes_t *buf); |
| 778 |
|
| 779 |
/** |
| 780 |
* Save message content into a pn_data_t object data. The data object will first be cleared. |
| 781 |
*/ |
| 782 |
PN_EXTERN int pn_message_data(pn_message_t *msg, pn_data_t *data); |
| 783 |
|
| 784 |
/** @} |
| 785 |
*/ |
| 786 |
|
| 787 |
#ifdef __cplusplus |
| 788 |
} |
| 789 |
#endif |
| 790 |
|
| 791 |
#endif /* message.h */ |