amqp.h 94 KB

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