amqp.h 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  1. // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.
  2. // SPDX-License-Identifier: mit
  3. /** \file */
  4. #include <rabbitmq-c/export.h>
  5. #ifndef RABBITMQ_C_RABBITMQ_C_H
  6. #define RABBITMQ_C_RABBITMQ_C_H
  7. /** \cond HIDE_FROM_DOXYGEN */
  8. #ifdef __cplusplus
  9. #define AMQP_BEGIN_DECLS extern "C" {
  10. #define AMQP_END_DECLS }
  11. #else
  12. #define AMQP_BEGIN_DECLS
  13. #define AMQP_END_DECLS
  14. #endif
  15. /*
  16. * \internal
  17. * AMQP_CALL - calling convension (used on Win32)
  18. */
  19. #ifdef _WIN32
  20. #define AMQP_CALL __cdecl
  21. #else
  22. #define AMQP_CALL
  23. #endif
  24. /* Define ssize_t on Win32/64 platforms
  25. See: http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-April/030649.html for
  26. details
  27. */
  28. #if !defined(_W64)
  29. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  30. #define _W64 __w64
  31. #else
  32. #define _W64
  33. #endif
  34. #endif
  35. #if defined(_MSC_VER) || (defined(__BORLANDC__) && (__BORLANDC__ <= 0x0564))
  36. #ifdef _WIN64
  37. typedef __int64 ssize_t;
  38. #else
  39. typedef _W64 int ssize_t;
  40. #endif
  41. #endif
  42. #if defined(_WIN32) && defined(__MINGW32__)
  43. #include <sys/types.h>
  44. #endif
  45. /** \endcond */
  46. #include <stddef.h>
  47. #include <stdint.h>
  48. struct timeval;
  49. AMQP_BEGIN_DECLS
  50. /**
  51. * \def AMQP_VERSION_MAJOR
  52. *
  53. * Major library version number compile-time constant
  54. *
  55. * The major version is incremented when backwards incompatible API changes
  56. * are made.
  57. *
  58. * \sa AMQP_VERSION, AMQP_VERSION_STRING
  59. *
  60. * \since v0.4.0
  61. */
  62. /**
  63. * \def AMQP_VERSION_MINOR
  64. *
  65. * Minor library version number compile-time constant
  66. *
  67. * The minor version is incremented when new APIs are added. Existing APIs
  68. * are left alone.
  69. *
  70. * \sa AMQP_VERSION, AMQP_VERSION_STRING
  71. *
  72. * \since v0.4.0
  73. */
  74. /**
  75. * \def AMQP_VERSION_PATCH
  76. *
  77. * Patch library version number compile-time constant
  78. *
  79. * The patch version is incremented when library code changes, but the API
  80. * is not changed.
  81. *
  82. * \sa AMQP_VERSION, AMQP_VERSION_STRING
  83. *
  84. * \since v0.4.0
  85. */
  86. /**
  87. * \def AMQP_VERSION_IS_RELEASE
  88. *
  89. * Version constant set to 1 for tagged release, 0 otherwise
  90. *
  91. * NOTE: versions that are not tagged releases are not guaranteed to be API/ABI
  92. * compatible with older releases, and may change commit-to-commit.
  93. *
  94. * \sa AMQP_VERSION, AMQP_VERSION_STRING
  95. *
  96. * \since v0.4.0
  97. */
  98. /*
  99. * Developer note: when changing these, be sure to update SOVERSION constants
  100. * in CMakeLists.txt and configure.ac
  101. */
  102. #define AMQP_VERSION_MAJOR 0
  103. #define AMQP_VERSION_MINOR 13
  104. #define AMQP_VERSION_PATCH 0
  105. #define AMQP_VERSION_IS_RELEASE 1
  106. /**
  107. * \def AMQP_VERSION_CODE
  108. *
  109. * Helper macro to geneate a packed version code suitable for
  110. * comparison with AMQP_VERSION.
  111. *
  112. * \sa amqp_version_number() AMQP_VERSION_MAJOR, AMQP_VERSION_MINOR,
  113. * AMQP_VERSION_PATCH, AMQP_VERSION_IS_RELEASE, AMQP_VERSION
  114. *
  115. * \since v0.6.1
  116. */
  117. #define AMQP_VERSION_CODE(major, minor, patch, release) \
  118. ((major << 24) | (minor << 16) | (patch << 8) | (release))
  119. /**
  120. * \def AMQP_VERSION
  121. *
  122. * Packed version number
  123. *
  124. * AMQP_VERSION is a 4-byte unsigned integer with the most significant byte
  125. * set to AMQP_VERSION_MAJOR, the second most significant byte set to
  126. * AMQP_VERSION_MINOR, third most significant byte set to AMQP_VERSION_PATCH,
  127. * and the lowest byte set to AMQP_VERSION_IS_RELEASE.
  128. *
  129. * For example version 2.3.4 which is released version would be encoded as
  130. * 0x02030401
  131. *
  132. * \sa amqp_version_number() AMQP_VERSION_MAJOR, AMQP_VERSION_MINOR,
  133. * AMQP_VERSION_PATCH, AMQP_VERSION_IS_RELEASE, AMQP_VERSION_CODE
  134. *
  135. * \since v0.4.0
  136. */
  137. #define AMQP_VERSION \
  138. AMQP_VERSION_CODE(AMQP_VERSION_MAJOR, AMQP_VERSION_MINOR, \
  139. AMQP_VERSION_PATCH, AMQP_VERSION_IS_RELEASE)
  140. /** \cond HIDE_FROM_DOXYGEN */
  141. #define AMQ_STRINGIFY(s) AMQ_STRINGIFY_HELPER(s)
  142. #define AMQ_STRINGIFY_HELPER(s) #s
  143. #define AMQ_VERSION_STRING \
  144. AMQ_STRINGIFY(AMQP_VERSION_MAJOR) \
  145. "." AMQ_STRINGIFY(AMQP_VERSION_MINOR) "." AMQ_STRINGIFY(AMQP_VERSION_PATCH)
  146. /** \endcond */
  147. /**
  148. * \def AMQP_VERSION_STRING
  149. *
  150. * Version string compile-time constant
  151. *
  152. * Non-released versions of the library will have "-pre" appended to the
  153. * version string
  154. *
  155. * \sa amqp_version()
  156. *
  157. * \since v0.4.0
  158. */
  159. #if AMQP_VERSION_IS_RELEASE
  160. #define AMQP_VERSION_STRING AMQ_VERSION_STRING
  161. #else
  162. #define AMQP_VERSION_STRING AMQ_VERSION_STRING "-pre"
  163. #endif
  164. /**
  165. * Returns the rabbitmq-c version as a packed integer.
  166. *
  167. * See \ref AMQP_VERSION
  168. *
  169. * \return packed 32-bit integer representing version of library at runtime
  170. *
  171. * \sa AMQP_VERSION, amqp_version()
  172. *
  173. * \since v0.4.0
  174. */
  175. AMQP_EXPORT
  176. uint32_t AMQP_CALL amqp_version_number(void);
  177. /**
  178. * Returns the rabbitmq-c version as a string.
  179. *
  180. * See \ref AMQP_VERSION_STRING
  181. *
  182. * \return a statically allocated string describing the version of rabbitmq-c.
  183. *
  184. * \sa amqp_version_number(), AMQP_VERSION_STRING, AMQP_VERSION
  185. *
  186. * \since v0.1
  187. */
  188. AMQP_EXPORT
  189. char const *AMQP_CALL amqp_version(void);
  190. /**
  191. * \def AMQP_DEFAULT_FRAME_SIZE
  192. *
  193. * Default frame size (128Kb)
  194. *
  195. * \sa amqp_login(), amqp_login_with_properties()
  196. *
  197. * \since v0.4.0
  198. */
  199. #define AMQP_DEFAULT_FRAME_SIZE 131072
  200. /**
  201. * \def AMQP_DEFAULT_MAX_CHANNELS
  202. *
  203. * Default maximum number of channels (2047, RabbitMQ default limit of 2048,
  204. * minus 1 for channel 0). RabbitMQ set a default limit of 2048 channels per
  205. * connection in v3.7.5 to prevent broken clients from leaking too many
  206. * channels.
  207. *
  208. * \sa amqp_login(), amqp_login_with_properties()
  209. *
  210. * \since v0.4.0
  211. */
  212. #define AMQP_DEFAULT_MAX_CHANNELS 2047
  213. /**
  214. * \def AMQP_DEFAULT_HEARTBEAT
  215. *
  216. * Default heartbeat interval (0, heartbeat disabled)
  217. *
  218. * \sa amqp_login(), amqp_login_with_properties()
  219. *
  220. * \since v0.4.0
  221. */
  222. #define AMQP_DEFAULT_HEARTBEAT 0
  223. /**
  224. * \def AMQP_DEFAULT_VHOST
  225. *
  226. * Default RabbitMQ vhost: "/"
  227. *
  228. * \sa amqp_login(), amqp_login_with_properties()
  229. *
  230. * \since v0.9.0
  231. */
  232. #define AMQP_DEFAULT_VHOST "/"
  233. /**
  234. * boolean type 0 = false, true otherwise
  235. *
  236. * \since v0.1
  237. */
  238. typedef int amqp_boolean_t;
  239. /**
  240. * Method number
  241. *
  242. * \since v0.1
  243. */
  244. typedef uint32_t amqp_method_number_t;
  245. /**
  246. * Bitmask for flags
  247. *
  248. * \since v0.1
  249. */
  250. typedef uint32_t amqp_flags_t;
  251. /**
  252. * Channel type
  253. *
  254. * \since v0.1
  255. */
  256. typedef uint16_t amqp_channel_t;
  257. /**
  258. * Buffer descriptor
  259. *
  260. * \since v0.1
  261. */
  262. typedef struct amqp_bytes_t_ {
  263. size_t len; /**< length of the buffer in bytes */
  264. void *bytes; /**< pointer to the beginning of the buffer */
  265. } amqp_bytes_t;
  266. /**
  267. * Decimal data type
  268. *
  269. * \since v0.1
  270. */
  271. typedef struct amqp_decimal_t_ {
  272. uint8_t decimals; /**< the location of the decimal point */
  273. uint32_t value; /**< the value before the decimal point is applied */
  274. } amqp_decimal_t;
  275. /**
  276. * AMQP field table
  277. *
  278. * An AMQP field table is a set of key-value pairs.
  279. * A key is a UTF-8 encoded string up to 128 bytes long, and are not null
  280. * terminated.
  281. * A value can be one of several different datatypes. \sa
  282. * amqp_field_value_kind_t
  283. *
  284. * \sa amqp_table_entry_t
  285. *
  286. * \since v0.1
  287. */
  288. typedef struct amqp_table_t_ {
  289. int num_entries; /**< length of entries array */
  290. struct amqp_table_entry_t_ *entries; /**< an array of table entries */
  291. } amqp_table_t;
  292. /**
  293. * An AMQP Field Array
  294. *
  295. * A repeated set of field values, all must be of the same type
  296. *
  297. * \since v0.1
  298. */
  299. typedef struct amqp_array_t_ {
  300. int num_entries; /**< Number of entries in the table */
  301. struct amqp_field_value_t_ *entries; /**< linked list of field values */
  302. } amqp_array_t;
  303. /*
  304. 0-9 0-9-1 Qpid/Rabbit Type Remarks
  305. ---------------------------------------------------------------------------
  306. t t Boolean
  307. b b Signed 8-bit
  308. B Unsigned 8-bit
  309. U s Signed 16-bit (A1)
  310. u Unsigned 16-bit
  311. I I I Signed 32-bit
  312. i Unsigned 32-bit
  313. L l Signed 64-bit (B)
  314. l Unsigned 64-bit
  315. f f 32-bit float
  316. d d 64-bit float
  317. D D D Decimal
  318. s Short string (A2)
  319. S S S Long string
  320. A Nested Array
  321. T T T Timestamp (u64)
  322. F F F Nested Table
  323. V V V Void
  324. x Byte array
  325. Remarks:
  326. A1, A2: Notice how the types **CONFLICT** here. In Qpid and Rabbit,
  327. 's' means a signed 16-bit integer; in 0-9-1, it means a
  328. short string.
  329. B: Notice how the signednesses **CONFLICT** here. In Qpid and Rabbit,
  330. 'l' means a signed 64-bit integer; in 0-9-1, it means an unsigned
  331. 64-bit integer.
  332. I'm going with the Qpid/Rabbit types, where there's a conflict, and
  333. the 0-9-1 types otherwise. 0-8 is a subset of 0-9, which is a subset
  334. of the other two, so this will work for both 0-8 and 0-9-1 branches of
  335. the code.
  336. */
  337. /**
  338. * A field table value
  339. *
  340. * \since v0.1
  341. */
  342. typedef struct amqp_field_value_t_ {
  343. uint8_t kind; /**< the type of the entry /sa amqp_field_value_kind_t */
  344. union {
  345. amqp_boolean_t boolean; /**< boolean type AMQP_FIELD_KIND_BOOLEAN */
  346. int8_t i8; /**< int8_t type AMQP_FIELD_KIND_I8 */
  347. uint8_t u8; /**< uint8_t type AMQP_FIELD_KIND_U8 */
  348. int16_t i16; /**< int16_t type AMQP_FIELD_KIND_I16 */
  349. uint16_t u16; /**< uint16_t type AMQP_FIELD_KIND_U16 */
  350. int32_t i32; /**< int32_t type AMQP_FIELD_KIND_I32 */
  351. uint32_t u32; /**< uint32_t type AMQP_FIELD_KIND_U32 */
  352. int64_t i64; /**< int64_t type AMQP_FIELD_KIND_I64 */
  353. uint64_t u64; /**< uint64_t type AMQP_FIELD_KIND_U64,
  354. AMQP_FIELD_KIND_TIMESTAMP */
  355. float f32; /**< float type AMQP_FIELD_KIND_F32 */
  356. double f64; /**< double type AMQP_FIELD_KIND_F64 */
  357. amqp_decimal_t decimal; /**< amqp_decimal_t AMQP_FIELD_KIND_DECIMAL */
  358. amqp_bytes_t bytes; /**< amqp_bytes_t type AMQP_FIELD_KIND_UTF8,
  359. AMQP_FIELD_KIND_BYTES */
  360. amqp_table_t table; /**< amqp_table_t type AMQP_FIELD_KIND_TABLE */
  361. amqp_array_t array; /**< amqp_array_t type AMQP_FIELD_KIND_ARRAY */
  362. } value; /**< a union of the value */
  363. } amqp_field_value_t;
  364. /**
  365. * An entry in a field-table
  366. *
  367. * \sa amqp_table_encode(), amqp_table_decode(), amqp_table_clone()
  368. *
  369. * \since v0.1
  370. */
  371. typedef struct amqp_table_entry_t_ {
  372. amqp_bytes_t key; /**< the table entry key. Its a null-terminated UTF-8
  373. * string, with a maximum size of 128 bytes */
  374. amqp_field_value_t value; /**< the table entry values */
  375. } amqp_table_entry_t;
  376. /**
  377. * Field value types
  378. *
  379. * \since v0.1
  380. */
  381. typedef enum {
  382. AMQP_FIELD_KIND_BOOLEAN =
  383. 't', /**< boolean type. 0 = false, 1 = true @see amqp_boolean_t */
  384. AMQP_FIELD_KIND_I8 = 'b', /**< 8-bit signed integer, datatype: int8_t */
  385. AMQP_FIELD_KIND_U8 = 'B', /**< 8-bit unsigned integer, datatype: uint8_t */
  386. AMQP_FIELD_KIND_I16 = 's', /**< 16-bit signed integer, datatype: int16_t */
  387. AMQP_FIELD_KIND_U16 = 'u', /**< 16-bit unsigned integer, datatype: uint16_t */
  388. AMQP_FIELD_KIND_I32 = 'I', /**< 32-bit signed integer, datatype: int32_t */
  389. AMQP_FIELD_KIND_U32 = 'i', /**< 32-bit unsigned integer, datatype: uint32_t */
  390. AMQP_FIELD_KIND_I64 = 'l', /**< 64-bit signed integer, datatype: int64_t */
  391. AMQP_FIELD_KIND_U64 = 'L', /**< 64-bit unsigned integer, datatype: uint64_t */
  392. AMQP_FIELD_KIND_F32 =
  393. 'f', /**< single-precision floating point value, datatype: float */
  394. AMQP_FIELD_KIND_F64 =
  395. 'd', /**< double-precision floating point value, datatype: double */
  396. AMQP_FIELD_KIND_DECIMAL =
  397. 'D', /**< amqp-decimal value, datatype: amqp_decimal_t */
  398. AMQP_FIELD_KIND_UTF8 = 'S', /**< UTF-8 null-terminated character string,
  399. datatype: amqp_bytes_t */
  400. AMQP_FIELD_KIND_ARRAY = 'A', /**< field array (repeated values of another
  401. datatype. datatype: amqp_array_t */
  402. AMQP_FIELD_KIND_TIMESTAMP = 'T', /**< 64-bit timestamp. datatype uint64_t */
  403. AMQP_FIELD_KIND_TABLE = 'F', /**< field table. encapsulates a table inside a
  404. table entry. datatype: amqp_table_t */
  405. AMQP_FIELD_KIND_VOID = 'V', /**< empty entry */
  406. AMQP_FIELD_KIND_BYTES =
  407. 'x' /**< unformatted byte string, datatype: amqp_bytes_t */
  408. } amqp_field_value_kind_t;
  409. /**
  410. * A list of allocation blocks
  411. *
  412. * \since v0.1
  413. */
  414. typedef struct amqp_pool_blocklist_t_ {
  415. int num_blocks; /**< Number of blocks in the block list */
  416. void **blocklist; /**< Array of memory blocks */
  417. } amqp_pool_blocklist_t;
  418. /**
  419. * A memory pool
  420. *
  421. * \since v0.1
  422. */
  423. typedef struct amqp_pool_t_ {
  424. size_t pagesize; /**< the size of the page in bytes. Allocations less than or
  425. * equal to this size are allocated in the pages block list.
  426. * Allocations greater than this are allocated in their own
  427. * own block in the large_blocks block list */
  428. amqp_pool_blocklist_t pages; /**< blocks that are the size of pagesize */
  429. amqp_pool_blocklist_t large_blocks; /**< allocations larger than the pagesize
  430. */
  431. int next_page; /**< an index to the next unused page block */
  432. char *alloc_block; /**< pointer to the current allocation block */
  433. size_t alloc_used; /**< number of bytes in the current allocation block that
  434. has been used */
  435. } amqp_pool_t;
  436. /**
  437. * An amqp method
  438. *
  439. * \since v0.1
  440. */
  441. typedef struct amqp_method_t_ {
  442. amqp_method_number_t id; /**< the method id number */
  443. void *decoded; /**< pointer to the decoded method,
  444. * cast to the appropriate type to use */
  445. } amqp_method_t;
  446. /**
  447. * An AMQP frame
  448. *
  449. * \since v0.1
  450. */
  451. typedef struct amqp_frame_t_ {
  452. uint8_t frame_type; /**< frame type. The types:
  453. * - AMQP_FRAME_METHOD - use the method union member
  454. * - AMQP_FRAME_HEADER - use the properties union member
  455. * - AMQP_FRAME_BODY - use the body_fragment union member
  456. */
  457. amqp_channel_t channel; /**< the channel the frame was received on */
  458. union {
  459. amqp_method_t method; /**< a method, use if frame_type == AMQP_FRAME_METHOD
  460. */
  461. struct {
  462. uint16_t class_id; /**< the class for the properties */
  463. uint64_t body_size; /**< size of the body in bytes */
  464. void *decoded; /**< the decoded properties */
  465. amqp_bytes_t raw; /**< amqp-encoded properties structure */
  466. } properties; /**< message header, a.k.a., properties,
  467. use if frame_type == AMQP_FRAME_HEADER */
  468. amqp_bytes_t body_fragment; /**< a body fragment, use if frame_type ==
  469. AMQP_FRAME_BODY */
  470. struct {
  471. uint8_t transport_high; /**< @internal first byte of handshake */
  472. uint8_t transport_low; /**< @internal second byte of handshake */
  473. uint8_t protocol_version_major; /**< @internal third byte of handshake */
  474. uint8_t protocol_version_minor; /**< @internal fourth byte of handshake */
  475. } protocol_header; /**< Used only when doing the initial handshake with the
  476. broker, don't use otherwise */
  477. } payload; /**< the payload of the frame */
  478. } amqp_frame_t;
  479. /**
  480. * Response type
  481. *
  482. * \since v0.1
  483. */
  484. typedef enum amqp_response_type_enum_ {
  485. AMQP_RESPONSE_NONE = 0, /**< the library got an EOF from the socket */
  486. AMQP_RESPONSE_NORMAL, /**< response normal, the RPC completed successfully */
  487. AMQP_RESPONSE_LIBRARY_EXCEPTION, /**< library error, an error occurred in the
  488. library, examine the library_error */
  489. AMQP_RESPONSE_SERVER_EXCEPTION /**< server exception, the broker returned an
  490. error, check replay */
  491. } amqp_response_type_enum;
  492. /**
  493. * Reply from a RPC method on the broker
  494. *
  495. * \since v0.1
  496. */
  497. typedef struct amqp_rpc_reply_t_ {
  498. amqp_response_type_enum reply_type; /**< the reply type:
  499. * - AMQP_RESPONSE_NORMAL - the RPC
  500. * completed successfully
  501. * - AMQP_RESPONSE_SERVER_EXCEPTION - the
  502. * broker returned
  503. * an exception, check the reply field
  504. * - AMQP_RESPONSE_LIBRARY_EXCEPTION - the
  505. * library
  506. * encountered an error, check the
  507. * library_error field
  508. */
  509. amqp_method_t reply; /**< in case of AMQP_RESPONSE_SERVER_EXCEPTION this
  510. * field will be set to the method returned from the
  511. * broker */
  512. int library_error; /**< in case of AMQP_RESPONSE_LIBRARY_EXCEPTION this
  513. * field will be set to an error code. An error
  514. * string can be retrieved using amqp_error_string */
  515. } amqp_rpc_reply_t;
  516. /**
  517. * SASL method type
  518. *
  519. * \since v0.1
  520. */
  521. typedef enum amqp_sasl_method_enum_ {
  522. AMQP_SASL_METHOD_UNDEFINED = -1, /**< Invalid SASL method */
  523. AMQP_SASL_METHOD_PLAIN =
  524. 0, /**< the PLAIN SASL method for authentication to the broker */
  525. AMQP_SASL_METHOD_EXTERNAL =
  526. 1 /**< the EXTERNAL SASL method for authentication to the broker */
  527. } amqp_sasl_method_enum;
  528. /**
  529. * connection state object
  530. *
  531. * \since v0.1
  532. */
  533. typedef struct amqp_connection_state_t_ *amqp_connection_state_t;
  534. /**
  535. * Socket object
  536. *
  537. * \since v0.4.0
  538. */
  539. typedef struct amqp_socket_t_ amqp_socket_t;
  540. /**
  541. * Status codes
  542. *
  543. * \since v0.4.0
  544. */
  545. /* NOTE: When updating this enum, update the strings in librabbitmq/amqp_api.c
  546. */
  547. typedef enum amqp_status_enum_ {
  548. AMQP_STATUS_OK = 0x0, /**< Operation successful */
  549. AMQP_STATUS_NO_MEMORY = -0x0001, /**< Memory allocation
  550. failed */
  551. AMQP_STATUS_BAD_AMQP_DATA = -0x0002, /**< Incorrect or corrupt
  552. data was received from
  553. the broker. This is a
  554. protocol error. */
  555. AMQP_STATUS_UNKNOWN_CLASS = -0x0003, /**< An unknown AMQP class
  556. was received. This is
  557. a protocol error. */
  558. AMQP_STATUS_UNKNOWN_METHOD = -0x0004, /**< An unknown AMQP method
  559. was received. This is
  560. a protocol error. */
  561. AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED = -0x0005, /**< Unable to resolve the
  562. * hostname */
  563. AMQP_STATUS_INCOMPATIBLE_AMQP_VERSION = -0x0006, /**< The broker advertised
  564. an incompaible AMQP
  565. version */
  566. AMQP_STATUS_CONNECTION_CLOSED = -0x0007, /**< The connection to the
  567. broker has been closed
  568. */
  569. AMQP_STATUS_BAD_URL = -0x0008, /**< malformed AMQP URL */
  570. AMQP_STATUS_SOCKET_ERROR = -0x0009, /**< A socket error
  571. occurred */
  572. AMQP_STATUS_INVALID_PARAMETER = -0x000A, /**< An invalid parameter
  573. was passed into the
  574. function */
  575. AMQP_STATUS_TABLE_TOO_BIG = -0x000B, /**< The amqp_table_t object
  576. cannot be serialized
  577. because the output
  578. buffer is too small */
  579. AMQP_STATUS_WRONG_METHOD = -0x000C, /**< The wrong method was
  580. received */
  581. AMQP_STATUS_TIMEOUT = -0x000D, /**< Operation timed out */
  582. AMQP_STATUS_TIMER_FAILURE = -0x000E, /**< The underlying system
  583. timer facility failed */
  584. AMQP_STATUS_HEARTBEAT_TIMEOUT = -0x000F, /**< Timed out waiting for
  585. heartbeat */
  586. AMQP_STATUS_UNEXPECTED_STATE = -0x0010, /**< Unexpected protocol
  587. state */
  588. AMQP_STATUS_SOCKET_CLOSED = -0x0011, /**< Underlying socket is
  589. closed */
  590. AMQP_STATUS_SOCKET_INUSE = -0x0012, /**< Underlying socket is
  591. already open */
  592. AMQP_STATUS_BROKER_UNSUPPORTED_SASL_METHOD = -0x0013, /**< Broker does not
  593. support the requested
  594. SASL mechanism */
  595. AMQP_STATUS_UNSUPPORTED = -0x0014, /**< Parameter is unsupported
  596. in this version */
  597. _AMQP_STATUS_NEXT_VALUE = -0x0015, /**< Internal value */
  598. AMQP_STATUS_TCP_ERROR = -0x0100, /**< A generic TCP error
  599. occurred */
  600. AMQP_STATUS_TCP_SOCKETLIB_INIT_ERROR = -0x0101, /**< An error occurred trying
  601. to initialize the
  602. socket library*/
  603. _AMQP_STATUS_TCP_NEXT_VALUE = -0x0102, /**< Internal value */
  604. AMQP_STATUS_SSL_ERROR = -0x0200, /**< A generic SSL error
  605. occurred. */
  606. AMQP_STATUS_SSL_HOSTNAME_VERIFY_FAILED = -0x0201, /**< SSL validation of
  607. hostname against
  608. peer certificate
  609. failed */
  610. AMQP_STATUS_SSL_PEER_VERIFY_FAILED = -0x0202, /**< SSL validation of peer
  611. certificate failed. */
  612. AMQP_STATUS_SSL_CONNECTION_FAILED = -0x0203, /**< SSL handshake failed. */
  613. AMQP_STATUS_SSL_SET_ENGINE_FAILED = -0x0204, /**< SSL setting engine failed */
  614. _AMQP_STATUS_SSL_NEXT_VALUE = -0x0205 /**< Internal value */
  615. } amqp_status_enum;
  616. /**
  617. * AMQP delivery modes.
  618. * Use these values for the #amqp_basic_properties_t::delivery_mode field.
  619. *
  620. * \since v0.5
  621. */
  622. typedef enum {
  623. AMQP_DELIVERY_NONPERSISTENT = 1, /**< Non-persistent message */
  624. AMQP_DELIVERY_PERSISTENT = 2 /**< Persistent message */
  625. } amqp_delivery_mode_enum;
  626. AMQP_END_DECLS
  627. #include <rabbitmq-c/framing.h>
  628. AMQP_BEGIN_DECLS
  629. /**
  630. * Empty bytes structure
  631. *
  632. * \since v0.2
  633. */
  634. AMQP_EXPORT extern const amqp_bytes_t amqp_empty_bytes;
  635. /**
  636. * Empty table structure
  637. *
  638. * \since v0.2
  639. */
  640. AMQP_EXPORT extern const amqp_table_t amqp_empty_table;
  641. /**
  642. * Empty table array structure
  643. *
  644. * \since v0.2
  645. */
  646. AMQP_EXPORT extern const amqp_array_t amqp_empty_array;
  647. /* Compatibility macros for the above, to avoid the need to update
  648. code written against earlier versions of librabbitmq. */
  649. /**
  650. * \def AMQP_EMPTY_BYTES
  651. *
  652. * Deprecated, use \ref amqp_empty_bytes instead
  653. *
  654. * \deprecated use \ref amqp_empty_bytes instead
  655. *
  656. * \since v0.1
  657. */
  658. #define AMQP_EMPTY_BYTES amqp_empty_bytes
  659. /**
  660. * \def AMQP_EMPTY_TABLE
  661. *
  662. * Deprecated, use \ref amqp_empty_table instead
  663. *
  664. * \deprecated use \ref amqp_empty_table instead
  665. *
  666. * \since v0.1
  667. */
  668. #define AMQP_EMPTY_TABLE amqp_empty_table
  669. /**
  670. * \def AMQP_EMPTY_ARRAY
  671. *
  672. * Deprecated, use \ref amqp_empty_array instead
  673. *
  674. * \deprecated use \ref amqp_empty_array instead
  675. *
  676. * \since v0.1
  677. */
  678. #define AMQP_EMPTY_ARRAY amqp_empty_array
  679. /**
  680. * Initializes an amqp_pool_t memory allocation pool for use
  681. *
  682. * Readies an allocation pool for use. An amqp_pool_t
  683. * must be initialized before use
  684. *
  685. * \param [in] pool the amqp_pool_t structure to initialize.
  686. * Calling this function on a pool a pool that has
  687. * already been initialized will result in undefined
  688. * behavior
  689. * \param [in] pagesize the unit size that the pool will allocate
  690. * memory chunks in. Anything allocated against the pool
  691. * with a requested size will be carved out of a block
  692. * this size. Allocations larger than this will be
  693. * allocated individually
  694. *
  695. * \sa recycle_amqp_pool(), empty_amqp_pool(), amqp_pool_alloc(),
  696. * amqp_pool_alloc_bytes(), amqp_pool_t
  697. *
  698. * \since v0.1
  699. */
  700. AMQP_EXPORT
  701. void AMQP_CALL init_amqp_pool(amqp_pool_t *pool, size_t pagesize);
  702. /**
  703. * Recycles an amqp_pool_t memory allocation pool
  704. *
  705. * Recycles the space allocate by the pool
  706. *
  707. * This invalidates all allocations made against the pool before this call is
  708. * made, any use of any allocations made before recycle_amqp_pool() is called
  709. * will result in undefined behavior.
  710. *
  711. * Note: this may or may not release memory, to force memory to be released
  712. * call empty_amqp_pool().
  713. *
  714. * \param [in] pool the amqp_pool_t to recycle
  715. *
  716. * \sa recycle_amqp_pool(), empty_amqp_pool(), amqp_pool_alloc(),
  717. * amqp_pool_alloc_bytes()
  718. *
  719. * \since v0.1
  720. *
  721. */
  722. AMQP_EXPORT
  723. void AMQP_CALL recycle_amqp_pool(amqp_pool_t *pool);
  724. /**
  725. * Empties an amqp memory pool
  726. *
  727. * Releases all memory associated with an allocation pool
  728. *
  729. * \param [in] pool the amqp_pool_t to empty
  730. *
  731. * \since v0.1
  732. */
  733. AMQP_EXPORT
  734. void AMQP_CALL empty_amqp_pool(amqp_pool_t *pool);
  735. /**
  736. * Allocates a block of memory from an amqp_pool_t memory pool
  737. *
  738. * Memory will be aligned on a 8-byte boundary. If a 0-length allocation is
  739. * requested, a NULL pointer will be returned.
  740. *
  741. * \param [in] pool the allocation pool to allocate the memory from
  742. * \param [in] amount the size of the allocation in bytes.
  743. * \return a pointer to the memory block, or NULL if the allocation cannot
  744. * be satisfied.
  745. *
  746. * \sa init_amqp_pool(), recycle_amqp_pool(), empty_amqp_pool(),
  747. * amqp_pool_alloc_bytes()
  748. *
  749. * \since v0.1
  750. */
  751. AMQP_EXPORT
  752. void *AMQP_CALL amqp_pool_alloc(amqp_pool_t *pool, size_t amount);
  753. /**
  754. * Allocates a block of memory from an amqp_pool_t to an amqp_bytes_t
  755. *
  756. * Memory will be aligned on a 8-byte boundary. If a 0-length allocation is
  757. * requested, output.bytes = NULL.
  758. *
  759. * \param [in] pool the allocation pool to allocate the memory from
  760. * \param [in] amount the size of the allocation in bytes
  761. * \param [in] output the location to store the pointer. On success
  762. * output.bytes will be set to the beginning of the buffer
  763. * output.len will be set to amount
  764. * On error output.bytes will be set to NULL and output.len
  765. * set to 0
  766. *
  767. * \sa init_amqp_pool(), recycle_amqp_pool(), empty_amqp_pool(),
  768. * amqp_pool_alloc()
  769. *
  770. * \since v0.1
  771. */
  772. AMQP_EXPORT
  773. void AMQP_CALL amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount,
  774. amqp_bytes_t *output);
  775. /**
  776. * Wraps a c string in an amqp_bytes_t
  777. *
  778. * Takes a string, calculates its length and creates an
  779. * amqp_bytes_t that points to it. The string is not duplicated.
  780. *
  781. * For a given input cstr, The amqp_bytes_t output.bytes is the
  782. * same as cstr, output.len is the length of the string not including
  783. * the \0 terminator
  784. *
  785. * This function uses strlen() internally so cstr must be properly
  786. * terminated
  787. *
  788. * \param [in] cstr the c string to wrap
  789. * \return an amqp_bytes_t that describes the string
  790. *
  791. * \since v0.1
  792. */
  793. AMQP_EXPORT
  794. amqp_bytes_t AMQP_CALL amqp_cstring_bytes(char const *cstr);
  795. /**
  796. * Duplicates an amqp_bytes_t buffer.
  797. *
  798. * The buffer is cloned and the contents copied.
  799. *
  800. * The memory associated with the output is allocated
  801. * with amqp_bytes_malloc() and should be freed with
  802. * amqp_bytes_free()
  803. *
  804. * \param [in] src
  805. * \return a clone of the src
  806. *
  807. * \sa amqp_bytes_free(), amqp_bytes_malloc()
  808. *
  809. * \since v0.1
  810. */
  811. AMQP_EXPORT
  812. amqp_bytes_t AMQP_CALL amqp_bytes_malloc_dup(amqp_bytes_t src);
  813. /**
  814. * Allocates a amqp_bytes_t buffer
  815. *
  816. * Creates an amqp_bytes_t buffer of the specified amount, the buffer should be
  817. * freed using amqp_bytes_free()
  818. *
  819. * \param [in] amount the size of the buffer in bytes
  820. * \returns an amqp_bytes_t with amount bytes allocated.
  821. * output.bytes will be set to NULL on error
  822. *
  823. * \sa amqp_bytes_free(), amqp_bytes_malloc_dup()
  824. *
  825. * \since v0.1
  826. */
  827. AMQP_EXPORT
  828. amqp_bytes_t AMQP_CALL amqp_bytes_malloc(size_t amount);
  829. /**
  830. * Frees an amqp_bytes_t buffer
  831. *
  832. * Frees a buffer allocated with amqp_bytes_malloc() or amqp_bytes_malloc_dup()
  833. *
  834. * Calling amqp_bytes_free on buffers not allocated with one
  835. * of those two functions will result in undefined behavior
  836. *
  837. * \param [in] bytes the buffer to free
  838. *
  839. * \sa amqp_bytes_malloc(), amqp_bytes_malloc_dup()
  840. *
  841. * \since v0.1
  842. */
  843. AMQP_EXPORT
  844. void AMQP_CALL amqp_bytes_free(amqp_bytes_t bytes);
  845. /**
  846. * Allocate and initialize a new amqp_connection_state_t object
  847. *
  848. * amqp_connection_state_t objects created with this function
  849. * should be freed with amqp_destroy_connection()
  850. *
  851. * \returns an opaque pointer on success, NULL or 0 on failure.
  852. *
  853. * \sa amqp_destroy_connection()
  854. *
  855. * \since v0.1
  856. */
  857. AMQP_EXPORT
  858. amqp_connection_state_t AMQP_CALL amqp_new_connection(void);
  859. /**
  860. * Get the underlying socket descriptor for the connection
  861. *
  862. * \warning Use the socket returned from this function carefully, incorrect use
  863. * of the socket outside of the library will lead to undefined behavior.
  864. * Additionally rabbitmq-c may use the socket differently version-to-version,
  865. * what may work in one version, may break in the next version. Be sure to
  866. * thoroughly test any applications that use the socket returned by this
  867. * function especially when using a newer version of rabbitmq-c
  868. *
  869. * \param [in] state the connection object
  870. * \returns the socket descriptor if one has been set, -1 otherwise
  871. *
  872. * \sa amqp_tcp_socket_new(), amqp_ssl_socket_new(), amqp_socket_open()
  873. *
  874. * \since v0.1
  875. */
  876. AMQP_EXPORT
  877. int AMQP_CALL amqp_get_sockfd(amqp_connection_state_t state);
  878. /**
  879. * Deprecated, use amqp_tcp_socket_new() or amqp_ssl_socket_new()
  880. *
  881. * \deprecated Use amqp_tcp_socket_new() or amqp_ssl_socket_new()
  882. *
  883. * Sets the socket descriptor associated with the connection. The socket
  884. * should be connected to a broker, and should not be read to or written from
  885. * before calling this function. A socket descriptor can be created and opened
  886. * using amqp_open_socket()
  887. *
  888. * \param [in] state the connection object
  889. * \param [in] sockfd the socket
  890. *
  891. * \sa amqp_open_socket(), amqp_tcp_socket_new(), amqp_ssl_socket_new()
  892. *
  893. * \since v0.1
  894. */
  895. AMQP_DEPRECATED_EXPORT void AMQP_CALL
  896. amqp_set_sockfd(amqp_connection_state_t state, int sockfd);
  897. /**
  898. * Tune client side parameters
  899. *
  900. * \warning This function may call abort() if the connection is in a certain
  901. * state. As such it should probably not be called code outside the library.
  902. * connection parameters should be specified when calling amqp_login() or
  903. * amqp_login_with_properties()
  904. *
  905. * This function changes channel_max, frame_max, and heartbeat parameters, on
  906. * the client side only. It does not try to renegotiate these parameters with
  907. * the broker. Using this function will lead to unexpected results.
  908. *
  909. * \param [in] state the connection object
  910. * \param [in] channel_max the maximum number of channels.
  911. * The largest this can be is 65535
  912. * \param [in] frame_max the maximum size of an frame.
  913. * The smallest this can be is 4096
  914. * The largest this can be is 2147483647
  915. * Unless you know what you're doing the recommended
  916. * size is 131072 or 128KB
  917. * \param [in] heartbeat the number of seconds between heartbeats
  918. *
  919. * \return AMQP_STATUS_OK on success, an amqp_status_enum value otherwise.
  920. * Possible error codes include:
  921. * - AMQP_STATUS_NO_MEMORY memory allocation failed.
  922. * - AMQP_STATUS_TIMER_FAILURE the underlying system timer indicated it
  923. * failed.
  924. *
  925. * \sa amqp_login(), amqp_login_with_properties()
  926. *
  927. * \since v0.1
  928. */
  929. AMQP_EXPORT
  930. int AMQP_CALL amqp_tune_connection(amqp_connection_state_t state,
  931. int channel_max, int frame_max,
  932. int heartbeat);
  933. /**
  934. * Get the maximum number of channels the connection can handle
  935. *
  936. * The maximum number of channels is set when connection negotiation takes
  937. * place in amqp_login() or amqp_login_with_properties().
  938. *
  939. * \param [in] state the connection object
  940. * \return the maximum number of channels. 0 if there is no limit
  941. *
  942. * \since v0.1
  943. */
  944. AMQP_EXPORT
  945. int AMQP_CALL amqp_get_channel_max(amqp_connection_state_t state);
  946. /**
  947. * Get the maximum size of an frame the connection can handle
  948. *
  949. * The maximum size of an frame is set when connection negotiation takes
  950. * place in amqp_login() or amqp_login_with_properties().
  951. *
  952. * \param [in] state the connection object
  953. * \return the maximum size of an frame.
  954. *
  955. * \since v0.6
  956. */
  957. AMQP_EXPORT
  958. int AMQP_CALL amqp_get_frame_max(amqp_connection_state_t state);
  959. /**
  960. * Get the number of seconds between heartbeats of the connection
  961. *
  962. * The number of seconds between heartbeats is set when connection
  963. * negotiation takes place in amqp_login() or amqp_login_with_properties().
  964. *
  965. * \param [in] state the connection object
  966. * \return the number of seconds between heartbeats.
  967. *
  968. * \since v0.6
  969. */
  970. AMQP_EXPORT
  971. int AMQP_CALL amqp_get_heartbeat(amqp_connection_state_t state);
  972. /**
  973. * Destroys an amqp_connection_state_t object
  974. *
  975. * Destroys a amqp_connection_state_t object that was created with
  976. * amqp_new_connection(). If the connection with the broker is open, it will be
  977. * implicitly closed with a reply code of 200 (success). Any memory that
  978. * would be freed with amqp_maybe_release_buffers() or
  979. * amqp_maybe_release_buffers_on_channel() will be freed, and use of that
  980. * memory will caused undefined behavior.
  981. *
  982. * \param [in] state the connection object
  983. * \return AMQP_STATUS_OK on success. amqp_status_enum value failure
  984. *
  985. * \sa amqp_new_connection()
  986. *
  987. * \since v0.1
  988. */
  989. AMQP_EXPORT
  990. int AMQP_CALL amqp_destroy_connection(amqp_connection_state_t state);
  991. /**
  992. * Process incoming data
  993. *
  994. * \warning This is a low-level function intended for those who want to
  995. * have greater control over input and output over the socket from the
  996. * broker. Correctly using this function requires in-depth knowledge of AMQP
  997. * and rabbitmq-c.
  998. *
  999. * For a given buffer of data received from the broker, decode the first
  1000. * frame in the buffer. If more than one frame is contained in the input buffer
  1001. * the return value will be less than the received_data size, the caller should
  1002. * adjust received_data buffer descriptor to point to the beginning of the
  1003. * buffer + the return value.
  1004. *
  1005. * \param [in] state the connection object
  1006. * \param [in] received_data a buffer of data received from the broker. The
  1007. * function will return the number of bytes of the buffer it used. The
  1008. * function copies these bytes to an internal buffer: this part of the buffer
  1009. * may be reused after this function successfully completes.
  1010. * \param [in,out] decoded_frame caller should pass in a pointer to an
  1011. * amqp_frame_t struct. If there is enough data in received_data for a
  1012. * complete frame, decoded_frame->frame_type will be set to something OTHER
  1013. * than 0. decoded_frame may contain members pointing to memory owned by
  1014. * the state object. This memory can be recycled with
  1015. * amqp_maybe_release_buffers() or amqp_maybe_release_buffers_on_channel().
  1016. * \return number of bytes consumed from received_data or 0 if a 0-length
  1017. * buffer was passed. A negative return value indicates failure. Possible
  1018. * errors:
  1019. * - AMQP_STATUS_NO_MEMORY failure in allocating memory. The library is likely
  1020. * in an indeterminate state making recovery unlikely. Client should note the
  1021. * error and terminate the application
  1022. * - AMQP_STATUS_BAD_AMQP_DATA bad AMQP data was received. The connection
  1023. * should be shutdown immediately
  1024. * - AMQP_STATUS_UNKNOWN_METHOD: an unknown method was received from the
  1025. * broker. This is likely a protocol error and the connection should be
  1026. * shutdown immediately
  1027. * - AMQP_STATUS_UNKNOWN_CLASS: a properties frame with an unknown class
  1028. * was received from the broker. This is likely a protocol error and the
  1029. * connection should be shutdown immediately
  1030. *
  1031. * \since v0.1
  1032. */
  1033. AMQP_EXPORT
  1034. int AMQP_CALL amqp_handle_input(amqp_connection_state_t state,
  1035. amqp_bytes_t received_data,
  1036. amqp_frame_t *decoded_frame);
  1037. /**
  1038. * Check to see if connection memory can be released
  1039. *
  1040. * \deprecated This function is deprecated in favor of
  1041. * amqp_maybe_release_buffers() or amqp_maybe_release_buffers_on_channel()
  1042. *
  1043. * Checks the state of an amqp_connection_state_t object to see if
  1044. * amqp_release_buffers() can be called successfully.
  1045. *
  1046. * \param [in] state the connection object
  1047. * \returns TRUE if the buffers can be released FALSE otherwise
  1048. *
  1049. * \sa amqp_release_buffers() amqp_maybe_release_buffers()
  1050. * amqp_maybe_release_buffers_on_channel()
  1051. *
  1052. * \since v0.1
  1053. */
  1054. AMQP_EXPORT
  1055. amqp_boolean_t AMQP_CALL amqp_release_buffers_ok(amqp_connection_state_t state);
  1056. /**
  1057. * Release amqp_connection_state_t owned memory
  1058. *
  1059. * \deprecated This function is deprecated in favor of
  1060. * amqp_maybe_release_buffers() or amqp_maybe_release_buffers_on_channel()
  1061. *
  1062. * \warning caller should ensure amqp_release_buffers_ok() returns true before
  1063. * calling this function. Failure to do so may result in abort() being called.
  1064. *
  1065. * Release memory owned by the amqp_connection_state_t for reuse by the
  1066. * library. Use of any memory returned by the library before this function is
  1067. * called will result in undefined behavior.
  1068. *
  1069. * \note internally rabbitmq-c tries to reuse memory when possible. As a result
  1070. * its possible calling this function may not have a noticeable effect on
  1071. * memory usage.
  1072. *
  1073. * \param [in] state the connection object
  1074. *
  1075. * \sa amqp_release_buffers_ok() amqp_maybe_release_buffers()
  1076. * amqp_maybe_release_buffers_on_channel()
  1077. *
  1078. * \since v0.1
  1079. */
  1080. AMQP_EXPORT
  1081. void AMQP_CALL amqp_release_buffers(amqp_connection_state_t state);
  1082. /**
  1083. * Release amqp_connection_state_t owned memory
  1084. *
  1085. * Release memory owned by the amqp_connection_state_t object related to any
  1086. * channel, allowing reuse by the library. Use of any memory returned by the
  1087. * library before this function is called with result in undefined behavior.
  1088. *
  1089. * \note internally rabbitmq-c tries to reuse memory when possible. As a result
  1090. * its possible calling this function may not have a noticeable effect on
  1091. * memory usage.
  1092. *
  1093. * \param [in] state the connection object
  1094. *
  1095. * \sa amqp_maybe_release_buffers_on_channel()
  1096. *
  1097. * \since v0.1
  1098. */
  1099. AMQP_EXPORT
  1100. void AMQP_CALL amqp_maybe_release_buffers(amqp_connection_state_t state);
  1101. /**
  1102. * Release amqp_connection_state_t owned memory related to a channel
  1103. *
  1104. * Release memory owned by the amqp_connection_state_t object related to the
  1105. * specified channel, allowing reuse by the library. Use of any memory returned
  1106. * the library for a specific channel will result in undefined behavior.
  1107. *
  1108. * \note internally rabbitmq-c tries to reuse memory when possible. As a result
  1109. * its possible calling this function may not have a noticeable effect on
  1110. * memory usage.
  1111. *
  1112. * \param [in] state the connection object
  1113. * \param [in] channel the channel specifier for which memory should be
  1114. * released. Note that the library does not care about the state of the
  1115. * channel when calling this function
  1116. *
  1117. * \sa amqp_maybe_release_buffers()
  1118. *
  1119. * \since v0.4.0
  1120. */
  1121. AMQP_EXPORT
  1122. void AMQP_CALL amqp_maybe_release_buffers_on_channel(
  1123. amqp_connection_state_t state, amqp_channel_t channel);
  1124. /**
  1125. * Send a frame to the broker
  1126. *
  1127. * \param [in] state the connection object
  1128. * \param [in] frame the frame to send to the broker
  1129. * \return AMQP_STATUS_OK on success, an amqp_status_enum value on error.
  1130. * Possible error codes:
  1131. * - AMQP_STATUS_BAD_AMQP_DATA the serialized form of the method or
  1132. * properties was too large to fit in a single AMQP frame, or the
  1133. * method contains an invalid value. The frame was not sent.
  1134. * - AMQP_STATUS_TABLE_TOO_BIG the serialized form of an amqp_table_t is
  1135. * too large to fit in a single AMQP frame. Frame was not sent.
  1136. * - AMQP_STATUS_UNKNOWN_METHOD an invalid method type was passed in
  1137. * - AMQP_STATUS_UNKNOWN_CLASS an invalid properties type was passed in
  1138. * - AMQP_STATUS_TIMER_FAILURE system timer indicated failure. The frame
  1139. * was sent
  1140. * - AMQP_STATUS_SOCKET_ERROR
  1141. * - AMQP_STATUS_SSL_ERROR
  1142. *
  1143. * \since v0.1
  1144. */
  1145. AMQP_EXPORT
  1146. int AMQP_CALL amqp_send_frame(amqp_connection_state_t state,
  1147. amqp_frame_t const *frame);
  1148. /**
  1149. * Compare two table entries
  1150. *
  1151. * Works just like strcmp(), comparing two the table keys, datatype, then values
  1152. *
  1153. * \param [in] entry1 the entry on the left
  1154. * \param [in] entry2 the entry on the right
  1155. * \return 0 if entries are equal, 0 < if left is greater, 0 > if right is
  1156. * greater
  1157. *
  1158. * \since v0.1
  1159. */
  1160. AMQP_EXPORT
  1161. int AMQP_CALL amqp_table_entry_cmp(void const *entry1, void const *entry2);
  1162. /**
  1163. * Open a socket to a remote host
  1164. *
  1165. * \deprecated This function is deprecated in favor of amqp_socket_open()
  1166. *
  1167. * Looks up the hostname, then attempts to open a socket to the host using
  1168. * the specified portnumber. It also sets various options on the socket to
  1169. * improve performance and correctness.
  1170. *
  1171. * \param [in] hostname this can be a hostname or IP address.
  1172. * Both IPv4 and IPv6 are acceptable
  1173. * \param [in] portnumber the port to connect on. RabbitMQ brokers
  1174. * listen on port 5672, and 5671 for SSL
  1175. * \return a positive value indicates success and is the sockfd. A negative
  1176. * value (see amqp_status_enum)is returned on failure. Possible error codes:
  1177. * - AMQP_STATUS_TCP_SOCKETLIB_INIT_ERROR Initialization of underlying socket
  1178. * library failed.
  1179. * - AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED hostname lookup failed.
  1180. * - AMQP_STATUS_SOCKET_ERROR a socket error occurred. errno or
  1181. * WSAGetLastError() may return more useful information.
  1182. *
  1183. * \note IPv6 support was added in v0.3
  1184. *
  1185. * \sa amqp_socket_open() amqp_set_sockfd()
  1186. *
  1187. * \since v0.1
  1188. */
  1189. AMQP_EXPORT
  1190. int AMQP_CALL amqp_open_socket(char const *hostname, int portnumber);
  1191. /**
  1192. * Send initial AMQP header to the broker
  1193. *
  1194. * \warning this is a low level function intended for those who want to
  1195. * interact with the broker at a very low level. Use of this function without
  1196. * understanding what it does will result in AMQP protocol errors.
  1197. *
  1198. * This function sends the AMQP protocol header to the broker.
  1199. *
  1200. * \param [in] state the connection object
  1201. * \return AMQP_STATUS_OK on success, a negative value on failure. Possible
  1202. * error codes:
  1203. * - AMQP_STATUS_CONNECTION_CLOSED the connection to the broker was closed.
  1204. * - AMQP_STATUS_SOCKET_ERROR a socket error occurred. It is likely the
  1205. * underlying socket has been closed. errno or WSAGetLastError() may provide
  1206. * further information.
  1207. * - AMQP_STATUS_SSL_ERROR a SSL error occurred. The connection to the broker
  1208. * was closed.
  1209. *
  1210. * \since v0.1
  1211. */
  1212. AMQP_EXPORT
  1213. int AMQP_CALL amqp_send_header(amqp_connection_state_t state);
  1214. /**
  1215. * Checks to see if there are any incoming frames ready to be read
  1216. *
  1217. * Checks to see if there are any amqp_frame_t objects buffered by the
  1218. * amqp_connection_state_t object. Having one or more frames buffered means
  1219. * that amqp_simple_wait_frame() or amqp_simple_wait_frame_noblock() will
  1220. * return a frame without potentially blocking on a read() call.
  1221. *
  1222. * \param [in] state the connection object
  1223. * \return TRUE if there are frames enqueued, FALSE otherwise
  1224. *
  1225. * \sa amqp_simple_wait_frame() amqp_simple_wait_frame_noblock()
  1226. * amqp_data_in_buffer()
  1227. *
  1228. * \since v0.1
  1229. */
  1230. AMQP_EXPORT
  1231. amqp_boolean_t AMQP_CALL amqp_frames_enqueued(amqp_connection_state_t state);
  1232. /**
  1233. * Read a single amqp_frame_t
  1234. *
  1235. * Waits for the next amqp_frame_t frame to be read from the broker.
  1236. * This function has the potential to block for a long time in the case of
  1237. * waiting for a basic.deliver method frame from the broker.
  1238. *
  1239. * The library may buffer frames. When an amqp_connection_state_t object
  1240. * has frames buffered calling amqp_simple_wait_frame() will return an
  1241. * amqp_frame_t without entering a blocking read(). You can test to see if
  1242. * an amqp_connection_state_t object has frames buffered by calling the
  1243. * amqp_frames_enqueued() function.
  1244. *
  1245. * The library has a socket read buffer. When there is data in an
  1246. * amqp_connection_state_t read buffer, amqp_simple_wait_frame() may return an
  1247. * amqp_frame_t without entering a blocking read(). You can test to see if an
  1248. * amqp_connection_state_t object has data in its read buffer by calling the
  1249. * amqp_data_in_buffer() function.
  1250. *
  1251. * \param [in] state the connection object
  1252. * \param [out] decoded_frame the frame
  1253. * \return AMQP_STATUS_OK on success, an amqp_status_enum value
  1254. * is returned otherwise. Possible errors include:
  1255. * - AMQP_STATUS_NO_MEMORY failure in allocating memory. The library is likely
  1256. * in an indeterminate state making recovery unlikely. Client should note the
  1257. * error and terminate the application
  1258. * - AMQP_STATUS_BAD_AMQP_DATA bad AMQP data was received. The connection
  1259. * should be shutdown immediately
  1260. * - AMQP_STATUS_UNKNOWN_METHOD: an unknown method was received from the
  1261. * broker. This is likely a protocol error and the connection should be
  1262. * shutdown immediately
  1263. * - AMQP_STATUS_UNKNOWN_CLASS: a properties frame with an unknown class
  1264. * was received from the broker. This is likely a protocol error and the
  1265. * connection should be shutdown immediately
  1266. * - AMQP_STATUS_HEARTBEAT_TIMEOUT timed out while waiting for heartbeat
  1267. * from the broker. The connection has been closed.
  1268. * - AMQP_STATUS_TIMER_FAILURE system timer indicated failure.
  1269. * - AMQP_STATUS_SOCKET_ERROR a socket error occurred. The connection has
  1270. * been closed
  1271. * - AMQP_STATUS_SSL_ERROR a SSL socket error occurred. The connection has
  1272. * been closed.
  1273. *
  1274. * \sa amqp_simple_wait_frame_noblock() amqp_frames_enqueued()
  1275. * amqp_data_in_buffer()
  1276. *
  1277. * \note as of v0.4.0 this function will no longer return heartbeat frames
  1278. * when enabled by specifying a non-zero heartbeat value in amqp_login().
  1279. * Heartbeating is handled internally by the library.
  1280. *
  1281. * \since v0.1
  1282. */
  1283. AMQP_EXPORT
  1284. int AMQP_CALL amqp_simple_wait_frame(amqp_connection_state_t state,
  1285. amqp_frame_t *decoded_frame);
  1286. /**
  1287. * Read a single amqp_frame_t with a timeout.
  1288. *
  1289. * Waits for the next amqp_frame_t frame to be read from the broker, up to
  1290. * a timespan specified by tv. The function will return AMQP_STATUS_TIMEOUT
  1291. * if the timeout is reached. The tv value is not modified by the function.
  1292. *
  1293. * If a 0 timeval is specified, the function behaves as if its non-blocking: it
  1294. * will test to see if a frame can be read from the broker, and return
  1295. * immediately.
  1296. *
  1297. * If NULL is passed in for tv, the function will behave like
  1298. * amqp_simple_wait_frame() and block until a frame is received from the broker
  1299. *
  1300. * The library may buffer frames. When an amqp_connection_state_t object
  1301. * has frames buffered calling amqp_simple_wait_frame_noblock() will return an
  1302. * amqp_frame_t without entering a blocking read(). You can test to see if an
  1303. * amqp_connection_state_t object has frames buffered by calling the
  1304. * amqp_frames_enqueued() function.
  1305. *
  1306. * The library has a socket read buffer. When there is data in an
  1307. * amqp_connection_state_t read buffer, amqp_simple_wait_frame_noblock() may
  1308. * return
  1309. * an amqp_frame_t without entering a blocking read(). You can test to see if an
  1310. * amqp_connection_state_t object has data in its read buffer by calling the
  1311. * amqp_data_in_buffer() function.
  1312. *
  1313. * \note This function does not return heartbeat frames. When enabled,
  1314. * heartbeating is handled internally by the library.
  1315. *
  1316. * \param [in,out] state the connection object
  1317. * \param [out] decoded_frame the frame
  1318. * \param [in] tv the maximum time to wait for a frame to be read. Setting
  1319. * tv->tv_sec = 0 and tv->tv_usec = 0 will do a non-blocking read. Specifying
  1320. * NULL for tv will make the function block until a frame is read.
  1321. * \return AMQP_STATUS_OK on success. An amqp_status_enum value is returned
  1322. * otherwise. Possible errors include:
  1323. * - AMQP_STATUS_TIMEOUT the timeout was reached while waiting for a frame
  1324. * from the broker.
  1325. * - AMQP_STATUS_INVALID_PARAMETER the tv parameter contains an invalid value.
  1326. * - AMQP_STATUS_NO_MEMORY failure in allocating memory. The library is likely
  1327. * in an indeterminate state making recovery unlikely. Client should note the
  1328. * error and terminate the application
  1329. * - AMQP_STATUS_BAD_AMQP_DATA bad AMQP data was received. The connection
  1330. * should be shutdown immediately
  1331. * - AMQP_STATUS_UNKNOWN_METHOD: an unknown method was received from the
  1332. * broker. This is likely a protocol error and the connection should be
  1333. * shutdown immediately
  1334. * - AMQP_STATUS_UNKNOWN_CLASS: a properties frame with an unknown class
  1335. * was received from the broker. This is likely a protocol error and the
  1336. * connection should be shutdown immediately
  1337. * - AMQP_STATUS_HEARTBEAT_TIMEOUT timed out while waiting for heartbeat
  1338. * from the broker. The connection has been closed.
  1339. * - AMQP_STATUS_TIMER_FAILURE system timer indicated failure.
  1340. * - AMQP_STATUS_SOCKET_ERROR a socket error occurred. The connection has
  1341. * been closed
  1342. * - AMQP_STATUS_SSL_ERROR a SSL socket error occurred. The connection has
  1343. * been closed.
  1344. *
  1345. * \sa amqp_simple_wait_frame() amqp_frames_enqueued() amqp_data_in_buffer()
  1346. *
  1347. * \since v0.4.0
  1348. */
  1349. AMQP_EXPORT
  1350. int AMQP_CALL amqp_simple_wait_frame_noblock(amqp_connection_state_t state,
  1351. amqp_frame_t *decoded_frame,
  1352. const struct timeval *tv);
  1353. /**
  1354. * Waits for a specific method from the broker
  1355. *
  1356. * \warning You probably don't want to use this function. If this function
  1357. * doesn't receive exactly the frame requested it closes the whole connection.
  1358. *
  1359. * Waits for a single method on a channel from the broker.
  1360. * If a frame is received that does not match expected_channel
  1361. * or expected_method the program will abort
  1362. *
  1363. * \param [in] state the connection object
  1364. * \param [in] expected_channel the channel that the method should be delivered
  1365. * on
  1366. * \param [in] expected_method the method to wait for
  1367. * \param [out] output the method
  1368. * \returns AMQP_STATUS_OK on success. An amqp_status_enum value is returned
  1369. * otherwise. Possible errors include:
  1370. * - AMQP_STATUS_WRONG_METHOD a frame containing the wrong method, wrong frame
  1371. * type or wrong channel was received. The connection is closed.
  1372. * - AMQP_STATUS_NO_MEMORY failure in allocating memory. The library is likely
  1373. * in an indeterminate state making recovery unlikely. Client should note the
  1374. * error and terminate the application
  1375. * - AMQP_STATUS_BAD_AMQP_DATA bad AMQP data was received. The connection
  1376. * should be shutdown immediately
  1377. * - AMQP_STATUS_UNKNOWN_METHOD: an unknown method was received from the
  1378. * broker. This is likely a protocol error and the connection should be
  1379. * shutdown immediately
  1380. * - AMQP_STATUS_UNKNOWN_CLASS: a properties frame with an unknown class
  1381. * was received from the broker. This is likely a protocol error and the
  1382. * connection should be shutdown immediately
  1383. * - AMQP_STATUS_HEARTBEAT_TIMEOUT timed out while waiting for heartbeat
  1384. * from the broker. The connection has been closed.
  1385. * - AMQP_STATUS_TIMER_FAILURE system timer indicated failure.
  1386. * - AMQP_STATUS_SOCKET_ERROR a socket error occurred. The connection has
  1387. * been closed
  1388. * - AMQP_STATUS_SSL_ERROR a SSL socket error occurred. The connection has
  1389. * been closed.
  1390. *
  1391. * \since v0.1
  1392. */
  1393. AMQP_EXPORT
  1394. int AMQP_CALL amqp_simple_wait_method(amqp_connection_state_t state,
  1395. amqp_channel_t expected_channel,
  1396. amqp_method_number_t expected_method,
  1397. amqp_method_t *output);
  1398. /**
  1399. * Sends a method to the broker
  1400. *
  1401. * This is a thin wrapper around amqp_send_frame(), providing a way to send
  1402. * a method to the broker on a specified channel.
  1403. *
  1404. * \param [in] state the connection object
  1405. * \param [in] channel the channel object
  1406. * \param [in] id the method number
  1407. * \param [in] decoded the method object
  1408. * \returns AMQP_STATUS_OK on success, an amqp_status_enum value otherwise.
  1409. * Possible errors include:
  1410. * - AMQP_STATUS_BAD_AMQP_DATA the serialized form of the method or
  1411. * properties was too large to fit in a single AMQP frame, or the
  1412. * method contains an invalid value. The frame was not sent.
  1413. * - AMQP_STATUS_TABLE_TOO_BIG the serialized form of an amqp_table_t is
  1414. * too large to fit in a single AMQP frame. Frame was not sent.
  1415. * - AMQP_STATUS_UNKNOWN_METHOD an invalid method type was passed in
  1416. * - AMQP_STATUS_UNKNOWN_CLASS an invalid properties type was passed in
  1417. * - AMQP_STATUS_TIMER_FAILURE system timer indicated failure. The frame
  1418. * was sent
  1419. * - AMQP_STATUS_SOCKET_ERROR
  1420. * - AMQP_STATUS_SSL_ERROR
  1421. *
  1422. * \since v0.1
  1423. */
  1424. AMQP_EXPORT
  1425. int AMQP_CALL amqp_send_method(amqp_connection_state_t state,
  1426. amqp_channel_t channel, amqp_method_number_t id,
  1427. void *decoded);
  1428. /**
  1429. * Sends a method to the broker and waits for a method response
  1430. *
  1431. * \param [in] state the connection object
  1432. * \param [in] channel the channel object
  1433. * \param [in] request_id the method number of the request
  1434. * \param [in] expected_reply_ids a 0 terminated array of expected response
  1435. * method numbers
  1436. * \param [in] decoded_request_method the method to be sent to the broker
  1437. * \return a amqp_rpc_reply_t:
  1438. * - r.reply_type == AMQP_RESPONSE_NORMAL. RPC completed successfully
  1439. * - r.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION. The broker returned an
  1440. * exception:
  1441. * - If r.reply.id == AMQP_CHANNEL_CLOSE_METHOD a channel exception
  1442. * occurred, cast r.reply.decoded to amqp_channel_close_t* to see details
  1443. * of the exception. The client should amqp_send_method() a
  1444. * amqp_channel_close_ok_t. The channel must be re-opened before it
  1445. * can be used again. Any resources associated with the channel
  1446. * (auto-delete exchanges, auto-delete queues, consumers) are invalid
  1447. * and must be recreated before attempting to use them again.
  1448. * - If r.reply.id == AMQP_CONNECTION_CLOSE_METHOD a connection exception
  1449. * occurred, cast r.reply.decoded to amqp_connection_close_t* to see
  1450. * details of the exception. The client amqp_send_method() a
  1451. * amqp_connection_close_ok_t and disconnect from the broker.
  1452. * - r.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION. An exception occurred
  1453. * within the library. Examine r.library_error and compare it against
  1454. * amqp_status_enum values to determine the error.
  1455. *
  1456. * \sa amqp_simple_rpc_decoded()
  1457. *
  1458. * \since v0.1
  1459. */
  1460. AMQP_EXPORT
  1461. amqp_rpc_reply_t AMQP_CALL amqp_simple_rpc(
  1462. amqp_connection_state_t state, amqp_channel_t channel,
  1463. amqp_method_number_t request_id, amqp_method_number_t *expected_reply_ids,
  1464. void *decoded_request_method);
  1465. /**
  1466. * Sends a method to the broker and waits for a method response
  1467. *
  1468. * \param [in] state the connection object
  1469. * \param [in] channel the channel object
  1470. * \param [in] request_id the method number of the request
  1471. * \param [in] reply_id the method number expected in response
  1472. * \param [in] decoded_request_method the request method
  1473. * \return a pointer to the method returned from the broker, or NULL on error.
  1474. * On error amqp_get_rpc_reply() will return an amqp_rpc_reply_t with
  1475. * details on the error that occurred.
  1476. *
  1477. * \since v0.1
  1478. */
  1479. AMQP_EXPORT
  1480. void *AMQP_CALL amqp_simple_rpc_decoded(amqp_connection_state_t state,
  1481. amqp_channel_t channel,
  1482. amqp_method_number_t request_id,
  1483. amqp_method_number_t reply_id,
  1484. void *decoded_request_method);
  1485. /**
  1486. * Get the last global amqp_rpc_reply
  1487. *
  1488. * The API methods corresponding to most synchronous AMQP methods
  1489. * return a pointer to the decoded method result. Upon error, they
  1490. * return NULL, and we need some way of discovering what, if anything,
  1491. * went wrong. amqp_get_rpc_reply() returns the most recent
  1492. * amqp_rpc_reply_t instance corresponding to such an API operation
  1493. * for the given connection.
  1494. *
  1495. * Only use it for operations that do not themselves return
  1496. * amqp_rpc_reply_t; operations that do return amqp_rpc_reply_t
  1497. * generally do NOT update this per-connection-global amqp_rpc_reply_t
  1498. * instance.
  1499. *
  1500. * \param [in] state the connection object
  1501. * \return the most recent amqp_rpc_reply_t:
  1502. * - r.reply_type == AMQP_RESPONSE_NORMAL. RPC completed successfully
  1503. * - r.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION. The broker returned an
  1504. * exception:
  1505. * - If r.reply.id == AMQP_CHANNEL_CLOSE_METHOD a channel exception
  1506. * occurred, cast r.reply.decoded to amqp_channel_close_t* to see details
  1507. * of the exception. The client should amqp_send_method() a
  1508. * amqp_channel_close_ok_t. The channel must be re-opened before it
  1509. * can be used again. Any resources associated with the channel
  1510. * (auto-delete exchanges, auto-delete queues, consumers) are invalid
  1511. * and must be recreated before attempting to use them again.
  1512. * - If r.reply.id == AMQP_CONNECTION_CLOSE_METHOD a connection exception
  1513. * occurred, cast r.reply.decoded to amqp_connection_close_t* to see
  1514. * details of the exception. The client amqp_send_method() a
  1515. * amqp_connection_close_ok_t and disconnect from the broker.
  1516. * - r.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION. An exception occurred
  1517. * within the library. Examine r.library_error and compare it against
  1518. * amqp_status_enum values to determine the error.
  1519. *
  1520. * \sa amqp_simple_rpc_decoded()
  1521. *
  1522. * \since v0.1
  1523. */
  1524. AMQP_EXPORT
  1525. amqp_rpc_reply_t AMQP_CALL amqp_get_rpc_reply(amqp_connection_state_t state);
  1526. /**
  1527. * Login to the broker
  1528. *
  1529. * After using amqp_open_socket and amqp_set_sockfd, call
  1530. * amqp_login to complete connecting to the broker
  1531. *
  1532. * \param [in] state the connection object
  1533. * \param [in] vhost the virtual host to connect to on the broker. The default
  1534. * on most brokers is "/"
  1535. * \param [in] channel_max the limit for number of channels for the connection.
  1536. * 0 means no limit, and is a good default
  1537. * (AMQP_DEFAULT_MAX_CHANNELS)
  1538. * Note that the maximum number of channels the protocol supports
  1539. * is 65535 (2^16, with the 0-channel reserved). The server can
  1540. * set a lower channel_max and then the client will use the lowest
  1541. * of the two
  1542. * \param [in] frame_max the maximum size of an AMQP frame on the wire to
  1543. * request of the broker for this connection. 4096 is the minimum
  1544. * size, 2^31-1 is the maximum, a good default is 131072 (128KB),
  1545. * or AMQP_DEFAULT_FRAME_SIZE
  1546. * \param [in] heartbeat the number of seconds between heartbeat frames to
  1547. * request of the broker. A value of 0 disables heartbeats.
  1548. * Note rabbitmq-c only has partial support for heartbeats, as of
  1549. * v0.4.0 they are only serviced during amqp_basic_publish() and
  1550. * amqp_simple_wait_frame()/amqp_simple_wait_frame_noblock()
  1551. * \param [in] sasl_method the SASL method to authenticate with the broker.
  1552. * followed by the authentication information. The following SASL
  1553. * methods are implemented:
  1554. * - AMQP_SASL_METHOD_PLAIN, the AMQP_SASL_METHOD_PLAIN argument
  1555. * should be followed by two arguments in this order:
  1556. * const char* username, and const char* password.
  1557. * - AMQP_SASL_METHOD_EXTERNAL, the AMQP_SASL_METHOD_EXTERNAL
  1558. * argument should be followed one argument:
  1559. * const char* identity.
  1560. * \return amqp_rpc_reply_t indicating success or failure.
  1561. * - r.reply_type == AMQP_RESPONSE_NORMAL. Login completed successfully
  1562. * - r.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION. In most cases errors
  1563. * from the broker when logging in will be represented by the broker closing
  1564. * the socket. In this case r.library_error will be set to
  1565. * AMQP_STATUS_CONNECTION_CLOSED. This error can represent a number of
  1566. * error conditions including: invalid vhost, authentication failure.
  1567. * - r.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION. The broker returned an
  1568. * exception:
  1569. * - If r.reply.id == AMQP_CHANNEL_CLOSE_METHOD a channel exception
  1570. * occurred, cast r.reply.decoded to amqp_channel_close_t* to see details
  1571. * of the exception. The client should amqp_send_method() a
  1572. * amqp_channel_close_ok_t. The channel must be re-opened before it
  1573. * can be used again. Any resources associated with the channel
  1574. * (auto-delete exchanges, auto-delete queues, consumers) are invalid
  1575. * and must be recreated before attempting to use them again.
  1576. * - If r.reply.id == AMQP_CONNECTION_CLOSE_METHOD a connection exception
  1577. * occurred, cast r.reply.decoded to amqp_connection_close_t* to see
  1578. * details of the exception. The client amqp_send_method() a
  1579. * amqp_connection_close_ok_t and disconnect from the broker.
  1580. *
  1581. * \since v0.1
  1582. */
  1583. AMQP_EXPORT
  1584. amqp_rpc_reply_t AMQP_CALL amqp_login(amqp_connection_state_t state,
  1585. char const *vhost, int channel_max,
  1586. int frame_max, int heartbeat,
  1587. amqp_sasl_method_enum sasl_method, ...);
  1588. /**
  1589. * Login to the broker passing a properties table
  1590. *
  1591. * This function is similar to amqp_login() and differs in that it provides a
  1592. * way to pass client properties to the broker. This is commonly used to
  1593. * negotiate newer protocol features as they are supported by the broker.
  1594. *
  1595. * \param [in] state the connection object
  1596. * \param [in] vhost the virtual host to connect to on the broker. The default
  1597. * on most brokers is "/"
  1598. * \param [in] channel_max the limit for the number of channels for the
  1599. * connection.
  1600. * 0 means no limit, and is a good default
  1601. * (AMQP_DEFAULT_MAX_CHANNELS)
  1602. * Note that the maximum number of channels the protocol supports
  1603. * is 65535 (2^16, with the 0-channel reserved). The server can
  1604. * set a lower channel_max and then the client will use the lowest
  1605. * of the two
  1606. * \param [in] frame_max the maximum size of an AMQP frame ont he wire to
  1607. * request of the broker for this connection. 4096 is the minimum
  1608. * size, 2^31-1 is the maximum, a good default is 131072 (128KB),
  1609. * or AMQP_DEFAULT_FRAME_SIZE
  1610. * \param [in] heartbeat the number of seconds between heartbeat frame to
  1611. * request of the broker. A value of 0 disables heartbeats.
  1612. * Note rabbitmq-c only has partial support for hearts, as of
  1613. * v0.4.0 heartbeats are only serviced during amqp_basic_publish(),
  1614. * and amqp_simple_wait_frame()/amqp_simple_wait_frame_noblock()
  1615. * \param [in] properties a table of properties to send the broker.
  1616. * \param [in] sasl_method the SASL method to authenticate with the broker
  1617. * followed by the authentication information. The following SASL
  1618. * methods are implemented:
  1619. * - AMQP_SASL_METHOD_PLAIN, the AMQP_SASL_METHOD_PLAIN argument
  1620. * should be followed by two arguments in this order:
  1621. * const char* username, and const char* password.
  1622. * - AMQP_SASL_METHOD_EXTERNAL, the AMQP_SASL_METHOD_EXTERNAL
  1623. * argument should be followed one argument:
  1624. * const char* identity.
  1625. * \return amqp_rpc_reply_t indicating success or failure.
  1626. * - r.reply_type == AMQP_RESPONSE_NORMAL. Login completed successfully
  1627. * - r.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION. In most cases errors
  1628. * from the broker when logging in will be represented by the broker closing
  1629. * the socket. In this case r.library_error will be set to
  1630. * AMQP_STATUS_CONNECTION_CLOSED. This error can represent a number of
  1631. * error conditions including: invalid vhost, authentication failure.
  1632. * - r.reply_type == AMQP_RESPONSE_SERVER_EXCEPTION. The broker returned an
  1633. * exception:
  1634. * - If r.reply.id == AMQP_CHANNEL_CLOSE_METHOD a channel exception
  1635. * occurred, cast r.reply.decoded to amqp_channel_close_t* to see details
  1636. * of the exception. The client should amqp_send_method() a
  1637. * amqp_channel_close_ok_t. The channel must be re-opened before it
  1638. * can be used again. Any resources associated with the channel
  1639. * (auto-delete exchanges, auto-delete queues, consumers) are invalid
  1640. * and must be recreated before attempting to use them again.
  1641. * - If r.reply.id == AMQP_CONNECTION_CLOSE_METHOD a connection exception
  1642. * occurred, cast r.reply.decoded to amqp_connection_close_t* to see
  1643. * details of the exception. The client amqp_send_method() a
  1644. * amqp_connection_close_ok_t and disconnect from the broker.
  1645. *
  1646. * \since v0.4.0
  1647. */
  1648. AMQP_EXPORT
  1649. amqp_rpc_reply_t AMQP_CALL amqp_login_with_properties(
  1650. amqp_connection_state_t state, char const *vhost, int channel_max,
  1651. int frame_max, int heartbeat, const amqp_table_t *properties,
  1652. amqp_sasl_method_enum sasl_method, ...);
  1653. struct amqp_basic_properties_t_;
  1654. /**
  1655. * Publish a message to the broker
  1656. *
  1657. * Publish a message on an exchange with a routing key.
  1658. *
  1659. * Note that at the AMQ protocol level basic.publish is an async method:
  1660. * this means error conditions that occur on the broker (such as publishing to
  1661. * a non-existent exchange) will not be reflected in the return value of this
  1662. * function.
  1663. *
  1664. * \param [in] state the connection object
  1665. * \param [in] channel the channel identifier
  1666. * \param [in] exchange the exchange on the broker to publish to
  1667. * \param [in] routing_key the routing key to use when publishing the message
  1668. * \param [in] mandatory indicate to the broker that the message MUST be routed
  1669. * to a queue. If the broker cannot do this it should respond with
  1670. * a basic.return method.
  1671. * \param [in] immediate indicate to the broker that the message MUST be
  1672. * delivered to a consumer immediately. If the broker cannot do this
  1673. * it should respond with a basic.return method.
  1674. * \param [in] properties the properties associated with the message
  1675. * \param [in] body the message body
  1676. * \return AMQP_STATUS_OK on success, amqp_status_enum value on failure. Note
  1677. * that basic.publish is an async method, the return value from this
  1678. * function only indicates that the message data was successfully
  1679. * transmitted to the broker. It does not indicate failures that occur
  1680. * on the broker, such as publishing to a non-existent exchange.
  1681. * Possible error values:
  1682. * - AMQP_STATUS_TIMER_FAILURE: system timer facility returned an error
  1683. * the message was not sent.
  1684. * - AMQP_STATUS_HEARTBEAT_TIMEOUT: connection timed out waiting for a
  1685. * heartbeat from the broker. The message was not sent.
  1686. * - AMQP_STATUS_NO_MEMORY: memory allocation failed. The message was
  1687. * not sent.
  1688. * - AMQP_STATUS_TABLE_TOO_BIG: a table in the properties was too large
  1689. * to fit in a single frame. Message was not sent.
  1690. * - AMQP_STATUS_CONNECTION_CLOSED: the connection was closed.
  1691. * - AMQP_STATUS_SSL_ERROR: a SSL error occurred.
  1692. * - AMQP_STATUS_TCP_ERROR: a TCP error occurred. errno or
  1693. * WSAGetLastError() may provide more information
  1694. *
  1695. * Note: this function does heartbeat processing as of v0.4.0
  1696. *
  1697. * \since v0.1
  1698. */
  1699. AMQP_EXPORT
  1700. int AMQP_CALL amqp_basic_publish(
  1701. amqp_connection_state_t state, amqp_channel_t channel,
  1702. amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_boolean_t mandatory,
  1703. amqp_boolean_t immediate, struct amqp_basic_properties_t_ const *properties,
  1704. amqp_bytes_t body);
  1705. /**
  1706. * Closes an channel
  1707. *
  1708. * \param [in] state the connection object
  1709. * \param [in] channel the channel identifier
  1710. * \param [in] code the reason for closing the channel, AMQP_REPLY_SUCCESS is a
  1711. * good default
  1712. * \return amqp_rpc_reply_t indicating success or failure
  1713. *
  1714. * \since v0.1
  1715. */
  1716. AMQP_EXPORT
  1717. amqp_rpc_reply_t AMQP_CALL amqp_channel_close(amqp_connection_state_t state,
  1718. amqp_channel_t channel, int code);
  1719. /**
  1720. * Closes the entire connection
  1721. *
  1722. * Implicitly closes all channels and informs the broker the connection
  1723. * is being closed, after receiving acknowledgment from the broker it closes
  1724. * the socket.
  1725. *
  1726. * \param [in] state the connection object
  1727. * \param [in] code the reason code for closing the connection.
  1728. * AMQP_REPLY_SUCCESS is a good default.
  1729. * \return amqp_rpc_reply_t indicating the result
  1730. *
  1731. * \since v0.1
  1732. */
  1733. AMQP_EXPORT
  1734. amqp_rpc_reply_t AMQP_CALL amqp_connection_close(amqp_connection_state_t state,
  1735. int code);
  1736. /**
  1737. * Acknowledges a message
  1738. *
  1739. * Does a basic.ack on a received message
  1740. *
  1741. * \param [in] state the connection object
  1742. * \param [in] channel the channel identifier
  1743. * \param [in] delivery_tag the delivery tag of the message to be ack'd
  1744. * \param [in] multiple if true, ack all messages up to this delivery tag, if
  1745. * false ack only this delivery tag
  1746. * \return 0 on success, 0 > on failing to send the ack to the broker.
  1747. * this will not indicate failure if something goes wrong on the
  1748. * broker
  1749. *
  1750. * \since v0.1
  1751. */
  1752. AMQP_EXPORT
  1753. int AMQP_CALL amqp_basic_ack(amqp_connection_state_t state,
  1754. amqp_channel_t channel, uint64_t delivery_tag,
  1755. amqp_boolean_t multiple);
  1756. /**
  1757. * Do a basic.get
  1758. *
  1759. * Synchonously polls the broker for a message in a queue, and
  1760. * retrieves the message if a message is in the queue.
  1761. *
  1762. * \param [in] state the connection object
  1763. * \param [in] channel the channel identifier to use
  1764. * \param [in] queue the queue name to retrieve from
  1765. * \param [in] no_ack if true the message is automatically ack'ed
  1766. * if false amqp_basic_ack should be called once the message
  1767. * retrieved has been processed
  1768. * \return amqp_rpc_reply indicating success or failure
  1769. *
  1770. * \since v0.1
  1771. */
  1772. AMQP_EXPORT
  1773. amqp_rpc_reply_t AMQP_CALL amqp_basic_get(amqp_connection_state_t state,
  1774. amqp_channel_t channel,
  1775. amqp_bytes_t queue,
  1776. amqp_boolean_t no_ack);
  1777. /**
  1778. * Do a basic.reject
  1779. *
  1780. * Actively reject a message that has been delivered
  1781. *
  1782. * \param [in] state the connection object
  1783. * \param [in] channel the channel identifier
  1784. * \param [in] delivery_tag the delivery tag of the message to reject
  1785. * \param [in] requeue indicate to the broker whether it should requeue the
  1786. * message or just discard it.
  1787. * \return 0 on success, 0 > on failing to send the reject method to the broker.
  1788. * This will not indicate failure if something goes wrong on the
  1789. * broker.
  1790. *
  1791. * \since v0.1
  1792. */
  1793. AMQP_EXPORT
  1794. int AMQP_CALL amqp_basic_reject(amqp_connection_state_t state,
  1795. amqp_channel_t channel, uint64_t delivery_tag,
  1796. amqp_boolean_t requeue);
  1797. /**
  1798. * Do a basic.nack
  1799. *
  1800. * Actively reject a message, this has the same effect as amqp_basic_reject()
  1801. * however, amqp_basic_nack() can negatively acknowledge multiple messages with
  1802. * one call much like amqp_basic_ack() can acknowledge mutliple messages with
  1803. * one call.
  1804. *
  1805. * \param [in] state the connection object
  1806. * \param [in] channel the channel identifier
  1807. * \param [in] delivery_tag the delivery tag of the message to reject
  1808. * \param [in] multiple if set to 1 negatively acknowledge all unacknowledged
  1809. * messages on this channel.
  1810. * \param [in] requeue indicate to the broker whether it should requeue the
  1811. * message or dead-letter it.
  1812. * \return AMQP_STATUS_OK on success, an amqp_status_enum value otherwise.
  1813. *
  1814. * \since v0.5.0
  1815. */
  1816. AMQP_EXPORT
  1817. int AMQP_CALL amqp_basic_nack(amqp_connection_state_t state,
  1818. amqp_channel_t channel, uint64_t delivery_tag,
  1819. amqp_boolean_t multiple, amqp_boolean_t requeue);
  1820. /**
  1821. * Check to see if there is data left in the receive buffer
  1822. *
  1823. * Can be used to see if there is data still in the buffer, if so
  1824. * calling amqp_simple_wait_frame will not immediately enter a
  1825. * blocking read.
  1826. *
  1827. * \param [in] state the connection object
  1828. * \return true if there is data in the recieve buffer, false otherwise
  1829. *
  1830. * \since v0.1
  1831. */
  1832. AMQP_EXPORT
  1833. amqp_boolean_t AMQP_CALL amqp_data_in_buffer(amqp_connection_state_t state);
  1834. /**
  1835. * Get the error string for the given error code.
  1836. *
  1837. * \deprecated This function has been deprecated in favor of
  1838. * \ref amqp_error_string2() which returns statically allocated
  1839. * string which do not need to be freed by the caller.
  1840. *
  1841. * The returned string resides on the heap; the caller is responsible
  1842. * for freeing it.
  1843. *
  1844. * \param [in] err return error code
  1845. * \return the error string
  1846. *
  1847. * \since v0.1
  1848. */
  1849. AMQP_DEPRECATED_EXPORT char *AMQP_CALL amqp_error_string(int err);
  1850. /**
  1851. * Get the error string for the given error code.
  1852. *
  1853. * Get an error string associated with an error code. The string is statically
  1854. * allocated and does not need to be freed
  1855. *
  1856. * \param [in] err the error code
  1857. * \return the error string
  1858. *
  1859. * \since v0.4.0
  1860. */
  1861. AMQP_EXPORT
  1862. const char *AMQP_CALL amqp_error_string2(int err);
  1863. /**
  1864. * Deserialize an amqp_table_t from AMQP wireformat
  1865. *
  1866. * This is an internal function and is not typically used by
  1867. * client applications
  1868. *
  1869. * \param [in] encoded the buffer containing the serialized data
  1870. * \param [in] pool memory pool used to allocate the table entries from
  1871. * \param [in] output the amqp_table_t structure to fill in. Any existing
  1872. * entries will be erased
  1873. * \param [in,out] offset The offset into the encoded buffer to start
  1874. * reading the serialized table. It will be updated
  1875. * by this function to end of the table
  1876. * \return AMQP_STATUS_OK on success, an amqp_status_enum value on failure
  1877. * Possible error codes:
  1878. * - AMQP_STATUS_NO_MEMORY out of memory
  1879. * - AMQP_STATUS_BAD_AMQP_DATA invalid wireformat
  1880. *
  1881. * \since v0.1
  1882. */
  1883. AMQP_EXPORT
  1884. int AMQP_CALL amqp_decode_table(amqp_bytes_t encoded, amqp_pool_t *pool,
  1885. amqp_table_t *output, size_t *offset);
  1886. /**
  1887. * Serializes an amqp_table_t to the AMQP wireformat
  1888. *
  1889. * This is an internal function and is not typically used by
  1890. * client applications
  1891. *
  1892. * \param [in] encoded the buffer where to serialize the table to
  1893. * \param [in] input the amqp_table_t to serialize
  1894. * \param [in,out] offset The offset into the encoded buffer to start
  1895. * writing the serialized table. It will be updated
  1896. * by this function to where writing left off
  1897. * \return AMQP_STATUS_OK on success, an amqp_status_enum value on failure
  1898. * Possible error codes:
  1899. * - AMQP_STATUS_TABLE_TOO_BIG the serialized form is too large for the
  1900. * buffer
  1901. * - AMQP_STATUS_BAD_AMQP_DATA invalid table
  1902. *
  1903. * \since v0.1
  1904. */
  1905. AMQP_EXPORT
  1906. int AMQP_CALL amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input,
  1907. size_t *offset);
  1908. /**
  1909. * Create a deep-copy of an amqp_table_t object
  1910. *
  1911. * Creates a deep-copy of an amqp_table_t object, using the provided pool
  1912. * object to allocate the necessary memory. This memory can be freed later by
  1913. * call recycle_amqp_pool(), or empty_amqp_pool()
  1914. *
  1915. * \param [in] original the table to copy
  1916. * \param [in,out] clone the table to copy to
  1917. * \param [in] pool the initialized memory pool to do allocations for the table
  1918. * from
  1919. * \return AMQP_STATUS_OK on success, amqp_status_enum value on failure.
  1920. * Possible error values:
  1921. * - AMQP_STATUS_NO_MEMORY - memory allocation failure.
  1922. * - AMQP_STATUS_INVALID_PARAMETER - invalid table (e.g., no key name)
  1923. *
  1924. * \since v0.4.0
  1925. */
  1926. AMQP_EXPORT
  1927. int AMQP_CALL amqp_table_clone(const amqp_table_t *original,
  1928. amqp_table_t *clone, amqp_pool_t *pool);
  1929. /**
  1930. * A message object
  1931. *
  1932. * \since v0.4.0
  1933. */
  1934. typedef struct amqp_message_t_ {
  1935. amqp_basic_properties_t properties; /**< message properties */
  1936. amqp_bytes_t body; /**< message body */
  1937. amqp_pool_t pool; /**< pool used to allocate properties */
  1938. } amqp_message_t;
  1939. /**
  1940. * Reads the next message on a channel
  1941. *
  1942. * Reads a complete message (header + body) on a specified channel. This
  1943. * function is intended to be used with amqp_basic_get() or when an
  1944. * AMQP_BASIC_DELIVERY_METHOD method is received.
  1945. *
  1946. * \param [in,out] state the connection object
  1947. * \param [in] channel the channel on which to read the message from
  1948. * \param [in,out] message a pointer to a amqp_message_t object. Caller should
  1949. * call amqp_message_destroy() when it is done using the
  1950. * fields in the message object. The caller is responsible for
  1951. * allocating/destroying the amqp_message_t object itself.
  1952. * \param [in] flags pass in 0. Currently unused.
  1953. * \returns a amqp_rpc_reply_t object. ret.reply_type == AMQP_RESPONSE_NORMAL on
  1954. * success.
  1955. *
  1956. * \since v0.4.0
  1957. */
  1958. AMQP_EXPORT
  1959. amqp_rpc_reply_t AMQP_CALL amqp_read_message(amqp_connection_state_t state,
  1960. amqp_channel_t channel,
  1961. amqp_message_t *message,
  1962. int flags);
  1963. /**
  1964. * Frees memory associated with a amqp_message_t allocated in amqp_read_message
  1965. *
  1966. * \param [in] message
  1967. *
  1968. * \since v0.4.0
  1969. */
  1970. AMQP_EXPORT
  1971. void AMQP_CALL amqp_destroy_message(amqp_message_t *message);
  1972. /**
  1973. * Envelope object
  1974. *
  1975. * \since v0.4.0
  1976. */
  1977. typedef struct amqp_envelope_t_ {
  1978. amqp_channel_t channel; /**< channel message was delivered on */
  1979. amqp_bytes_t consumer_tag; /**< the consumer tag the message was delivered to
  1980. */
  1981. uint64_t delivery_tag; /**< the messages delivery tag */
  1982. amqp_boolean_t redelivered; /**< flag indicating whether this message is being
  1983. redelivered */
  1984. amqp_bytes_t exchange; /**< exchange this message was published to */
  1985. amqp_bytes_t routing_key; /**< the routing key this message was published with
  1986. */
  1987. amqp_message_t message; /**< the message */
  1988. } amqp_envelope_t;
  1989. /**
  1990. * Wait for and consume a message
  1991. *
  1992. * Waits for a basic.deliver method on any channel, upon receipt of
  1993. * basic.deliver it reads that message, and returns. If any other method is
  1994. * received before basic.deliver, this function will return an amqp_rpc_reply_t
  1995. * with ret.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION, and
  1996. * ret.library_error == AMQP_STATUS_UNEXPECTED_STATE. The caller should then
  1997. * call amqp_simple_wait_frame() to read this frame and take appropriate action.
  1998. *
  1999. * This function should be used after starting a consumer with the
  2000. * amqp_basic_consume() function
  2001. *
  2002. * \param [in,out] state the connection object
  2003. * \param [in,out] envelope a pointer to a amqp_envelope_t object. Caller
  2004. * should call #amqp_destroy_envelope() when it is done using
  2005. * the fields in the envelope object. The caller is responsible
  2006. * for allocating/destroying the amqp_envelope_t object itself.
  2007. * \param [in] timeout a timeout to wait for a message delivery. Passing in
  2008. * NULL will result in blocking behavior.
  2009. * \param [in] flags pass in 0. Currently unused.
  2010. * \returns a amqp_rpc_reply_t object. ret.reply_type == AMQP_RESPONSE_NORMAL
  2011. * on success. If ret.reply_type == AMQP_RESPONSE_LIBRARY_EXCEPTION,
  2012. * and ret.library_error == AMQP_STATUS_UNEXPECTED_STATE, a frame other
  2013. * than AMQP_BASIC_DELIVER_METHOD was received, the caller should call
  2014. * amqp_simple_wait_frame() to read this frame and take appropriate
  2015. * action.
  2016. *
  2017. * \since v0.4.0
  2018. */
  2019. AMQP_EXPORT
  2020. amqp_rpc_reply_t AMQP_CALL amqp_consume_message(amqp_connection_state_t state,
  2021. amqp_envelope_t *envelope,
  2022. const struct timeval *timeout,
  2023. int flags);
  2024. /**
  2025. * Frees memory associated with a amqp_envelope_t allocated in
  2026. * amqp_consume_message()
  2027. *
  2028. * \param [in] envelope
  2029. *
  2030. * \since v0.4.0
  2031. */
  2032. AMQP_EXPORT
  2033. void AMQP_CALL amqp_destroy_envelope(amqp_envelope_t *envelope);
  2034. /**
  2035. * Parameters used to connect to the RabbitMQ broker
  2036. *
  2037. * \since v0.2
  2038. */
  2039. struct amqp_connection_info {
  2040. char *user; /**< the username to authenticate with the broker, default on most
  2041. broker is 'guest' */
  2042. char *password; /**< the password to authenticate with the broker, default on
  2043. most brokers is 'guest' */
  2044. char *host; /**< the hostname of the broker */
  2045. char *vhost; /**< the virtual host on the broker to connect to, a good default
  2046. is "/" */
  2047. int port; /**< the port that the broker is listening on, default on most
  2048. brokers is 5672 */
  2049. amqp_boolean_t ssl;
  2050. };
  2051. /**
  2052. * Initialze an amqp_connection_info to default values
  2053. *
  2054. * The default values are:
  2055. * - user: "guest"
  2056. * - password: "guest"
  2057. * - host: "localhost"
  2058. * - vhost: "/"
  2059. * - port: 5672
  2060. *
  2061. * \param [out] parsed the connection info to set defaults on
  2062. *
  2063. * \since v0.2
  2064. */
  2065. AMQP_EXPORT
  2066. void AMQP_CALL
  2067. amqp_default_connection_info(struct amqp_connection_info *parsed);
  2068. /**
  2069. * Parse a connection URL
  2070. *
  2071. * An amqp connection url takes the form:
  2072. *
  2073. * amqp://[$USERNAME[:$PASSWORD]\@]$HOST[:$PORT]/[$VHOST]
  2074. *
  2075. * Examples:
  2076. * amqp://guest:guest\@localhost:5672//
  2077. * amqp://guest:guest\@localhost/myvhost
  2078. *
  2079. * Any missing parts of the URL will be set to the defaults specified in
  2080. * amqp_default_connection_info. For amqps: URLs the default port will be set
  2081. * to 5671 instead of 5672 for non-SSL URLs.
  2082. *
  2083. * \note This function modifies url parameter.
  2084. *
  2085. * \param [in] url URI to parse, note that this parameter is modified by the
  2086. * function.
  2087. * \param [out] parsed the connection info gleaned from the URI. The char*
  2088. * members will point to parts of the url input parameter.
  2089. * Memory management will depend on how the url is allocated.
  2090. * \returns AMQP_STATUS_OK on success, AMQP_STATUS_BAD_URL on failure
  2091. *
  2092. * \since v0.2
  2093. */
  2094. AMQP_EXPORT
  2095. int AMQP_CALL amqp_parse_url(char *url, struct amqp_connection_info *parsed);
  2096. /* socket API */
  2097. /**
  2098. * Open a socket connection.
  2099. *
  2100. * This function opens a socket connection returned from amqp_tcp_socket_new()
  2101. * or amqp_ssl_socket_new(). This function should be called after setting
  2102. * socket options and prior to assigning the socket to an AMQP connection with
  2103. * amqp_set_socket().
  2104. *
  2105. * \param [in,out] self A socket object.
  2106. * \param [in] host Connect to this host.
  2107. * \param [in] port Connect on this remote port.
  2108. *
  2109. * \return AMQP_STATUS_OK on success, an amqp_status_enum on failure
  2110. *
  2111. * \since v0.4.0
  2112. */
  2113. AMQP_EXPORT
  2114. int AMQP_CALL amqp_socket_open(amqp_socket_t *self, const char *host, int port);
  2115. /**
  2116. * Open a socket connection.
  2117. *
  2118. * This function opens a socket connection returned from amqp_tcp_socket_new()
  2119. * or amqp_ssl_socket_new(). This function should be called after setting
  2120. * socket options and prior to assigning the socket to an AMQP connection with
  2121. * amqp_set_socket().
  2122. *
  2123. * \param [in,out] self A socket object.
  2124. * \param [in] host Connect to this host.
  2125. * \param [in] port Connect on this remote port.
  2126. * \param [in] timeout Max allowed time to spent on opening. If NULL - run in
  2127. * blocking mode
  2128. *
  2129. * \return AMQP_STATUS_OK on success, an amqp_status_enum on failure.
  2130. *
  2131. * \since v0.4.0
  2132. */
  2133. AMQP_EXPORT
  2134. int AMQP_CALL amqp_socket_open_noblock(amqp_socket_t *self, const char *host,
  2135. int port, const struct timeval *timeout);
  2136. /**
  2137. * Get the socket descriptor in use by a socket object.
  2138. *
  2139. * Retrieve the underlying socket descriptor. This function can be used to
  2140. * perform low-level socket operations that aren't supported by the socket
  2141. * interface. Use with caution!
  2142. *
  2143. * \param [in,out] self A socket object.
  2144. *
  2145. * \return The underlying socket descriptor, or -1 if there is no socket
  2146. * descriptor associated with
  2147. *
  2148. * \since v0.4.0
  2149. */
  2150. AMQP_EXPORT
  2151. int AMQP_CALL amqp_socket_get_sockfd(amqp_socket_t *self);
  2152. /**
  2153. * Get the socket object associated with a amqp_connection_state_t
  2154. *
  2155. * \param [in] state the connection object to get the socket from
  2156. * \return a pointer to the socket object, or NULL if one has not been assigned
  2157. *
  2158. * \since v0.4.0
  2159. */
  2160. AMQP_EXPORT
  2161. amqp_socket_t *AMQP_CALL amqp_get_socket(amqp_connection_state_t state);
  2162. /**
  2163. * Get the broker properties table
  2164. *
  2165. * \param [in] state the connection object
  2166. * \return a pointer to an amqp_table_t containing the properties advertised
  2167. * by the broker on connection. The connection object owns the table, it
  2168. * should not be modified.
  2169. *
  2170. * \since v0.5.0
  2171. */
  2172. AMQP_EXPORT
  2173. amqp_table_t *AMQP_CALL
  2174. amqp_get_server_properties(amqp_connection_state_t state);
  2175. /**
  2176. * Get the client properties table
  2177. *
  2178. * Get the properties that were passed to the broker on connection.
  2179. *
  2180. * \param [in] state the connection object
  2181. * \return a pointer to an amqp_table_t containing the properties advertised
  2182. * by the client on connection. The connection object owns the table, it
  2183. * should not be modified.
  2184. *
  2185. * \since v0.7.0
  2186. */
  2187. AMQP_EXPORT
  2188. amqp_table_t *AMQP_CALL
  2189. amqp_get_client_properties(amqp_connection_state_t state);
  2190. /**
  2191. * Get the login handshake timeout.
  2192. *
  2193. * amqp_login and amqp_login_with_properties perform the login handshake with
  2194. * the broker. This function returns the timeout associated with completing
  2195. * this operation from the client side. This value can be set by using the
  2196. * amqp_set_handshake_timeout.
  2197. *
  2198. * Note that the RabbitMQ broker has configurable timeout for completing the
  2199. * login handshake, the default is 10 seconds. rabbitmq-c has a default of 12
  2200. * seconds.
  2201. *
  2202. * \param [in] state the connection object
  2203. * \return a struct timeval representing the current login timeout for the state
  2204. * object. A NULL value represents an infinite timeout. The memory returned is
  2205. * owned by the connection object.
  2206. *
  2207. * \since v0.9.0
  2208. */
  2209. AMQP_EXPORT
  2210. struct timeval *AMQP_CALL
  2211. amqp_get_handshake_timeout(amqp_connection_state_t state);
  2212. /**
  2213. * Set the login handshake timeout.
  2214. *
  2215. * amqp_login and amqp_login_with_properties perform the login handshake with
  2216. * the broker. This function sets the timeout associated with completing this
  2217. * operation from the client side.
  2218. *
  2219. * The timeout must be set before amqp_login or amqp_login_with_properties is
  2220. * called to change from the default timeout.
  2221. *
  2222. * Note that the RabbitMQ broker has a configurable timeout for completing the
  2223. * login handshake, the default is 10 seconds. rabbitmq-c has a default of 12
  2224. * seconds.
  2225. *
  2226. * \param [in] state the connection object
  2227. * \param [in] timeout a struct timeval* representing new login timeout for the
  2228. * state object. NULL represents an infinite timeout. The value of timeout is
  2229. * copied internally, the caller is responsible for ownership of the passed in
  2230. * pointer, it does not need to remain valid after this function is called.
  2231. * \return AMQP_STATUS_OK on success.
  2232. *
  2233. * \since v0.9.0
  2234. */
  2235. AMQP_EXPORT
  2236. int AMQP_CALL amqp_set_handshake_timeout(amqp_connection_state_t state,
  2237. const struct timeval *timeout);
  2238. /**
  2239. * Get the RPC timeout
  2240. *
  2241. * Gets the timeout for any RPC-style AMQP command (e.g., amqp_queue_declare).
  2242. * This timeout may be changed at any time by calling \amqp_set_rpc_timeout
  2243. * function with a new timeout. The timeout applies individually to each RPC
  2244. * that is made.
  2245. *
  2246. * The default value is NULL, or an infinite timeout.
  2247. *
  2248. * When an RPC times out, the function will return an error AMQP_STATUS_TIMEOUT,
  2249. * and the connection will be closed.
  2250. *
  2251. *\warning RPC-timeouts are an advanced feature intended to be used to detect
  2252. * dead connections quickly when the rabbitmq-c implementation of heartbeats
  2253. * does not work. Do not use RPC timeouts unless you understand the implications
  2254. * of doing so.
  2255. *
  2256. * \param [in] state the connection object
  2257. * \return a struct timeval representing the current RPC timeout for the state
  2258. * object. A NULL value represents an infinite timeout. The memory returned is
  2259. * owned by the connection object.
  2260. *
  2261. * \since v0.9.0
  2262. */
  2263. AMQP_EXPORT
  2264. struct timeval *AMQP_CALL amqp_get_rpc_timeout(amqp_connection_state_t state);
  2265. /**
  2266. * Set the RPC timeout
  2267. *
  2268. * Sets the timeout for any RPC-style AMQP command (e.g., amqp_queue_declare).
  2269. * This timeout may be changed at any time by calling this function with a new
  2270. * timeout. The timeout applies individually to each RPC that is made.
  2271. *
  2272. * The default value is NULL, or an infinite timeout.
  2273. *
  2274. * When an RPC times out, the function will return an error AMQP_STATUS_TIMEOUT,
  2275. * and the connection will be closed.
  2276. *
  2277. *\warning RPC-timeouts are an advanced feature intended to be used to detect
  2278. * dead connections quickly when the rabbitmq-c implementation of heartbeats
  2279. * does not work. Do not use RPC timeouts unless you understand the implications
  2280. * of doing so.
  2281. *
  2282. * \param [in] state the connection object
  2283. * \param [in] timeout a struct timeval* representing new RPC timeout for the
  2284. * state object. NULL represents an infinite timeout. The value of timeout is
  2285. * copied internally, the caller is responsible for ownership of the passed
  2286. * pointer, it does not need to remain valid after this function is called.
  2287. * \return AMQP_STATUS_SUCCESS on success.
  2288. *
  2289. * \since v0.9.0
  2290. */
  2291. AMQP_EXPORT
  2292. int AMQP_CALL amqp_set_rpc_timeout(amqp_connection_state_t state,
  2293. const struct timeval *timeout);
  2294. AMQP_END_DECLS
  2295. #endif /* RABBITMQ_C_RABBITMQ_C_H */