diff --git a/.hgignore b/.hgignore deleted file mode 100644 index 99d8fa6bd..000000000 --- a/.hgignore +++ /dev/null @@ -1,39 +0,0 @@ -^scratch$ - -^autom4te\.cache$ -^aclocal\.m4$ -^config\.(guess|log|status|sub|h\.in~?)$ -^configure$ -^depcomp$ -^install-sh$ -^ltmain.sh$ -^missing$ - -(^|/)\.libs$ -(^|/)\.deps$ -\.(o|lo|la)$ -^config\.h$ -^stamp-h1$ -^libtool$ - -^librabbitmq/amqp_framing\.[ch]$ - -^(|librabbitmq/|tests/|examples/|tools/|tools/doc/)Makefile(\.in)?$ -^tests/test_tables$ -^tests/test_parse_url$ -^examples/amqp_sendstring$ -^examples/amqp_exchange_declare$ -^examples/amqp_listen$ -^examples/amqp_producer$ -^examples/amqp_consumer$ -^examples/amqp_unbind$ -^examples/amqp_bind$ -^examples/amqp_listenq$ - -^tools/amqp-publish$ -^tools/amqp-get$ -^tools/amqp-consume$ -^tools/amqp-declare-queue$ -^tools/amqp-delete-queue$ -^tools/.*\.[17]$ -^tools/doc/man-date.ent$ diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index bd0070cfc..000000000 --- a/AUTHORS +++ /dev/null @@ -1,2 +0,0 @@ -Tony Garnock-Jones -The RabbitMQ team diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 76014314e..000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,74 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project(rabbitmq-c "C") - -#find python -find_package(PythonInterp REQUIRED) - -#check for json or simplejson -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import json" - RESULT_VARIABLE CHECK_PYTHON_JSON_FAILED -) - -if (CHECK_PYTHON_JSON_FAILED) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import simplejson" - RESULT_VARIABLE CHECK_PYTHON_SIMPLEJSON_FAILED - ) - - if (CHECK_PYTHON_SIMPLEJSON_FAILED) - message(FATAL_ERROR "could not find a python that can 'import simplejson") - endif (CHECK_PYTHON_SIMPLEJSON_FAILED) -endif (CHECK_PYTHON_JSON_FAILED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) -include(TestCInline) - -option(FETCH_CODEGEN_FROM_GIT "Fetch codegen directly from the git repository" OFF) - -set(CODEGEN_GIT_TAG rabbitmq_v2_5_1 CACHE STRING "Git tag in rabbitmq-codegen to fetch with FETCH_CODEGEN_FROM_GIT") -if (FETCH_CODEGEN_FROM_GIT) - include(ExternalProject) - ExternalProject_Add( - amqp_codegen - GIT_REPOSITORY https://github.com/rabbitmq/rabbitmq-codegen.git - GIT_TAG ${CODEGEN_GIT_TAG} - CONFIGURE_COMMAND "" - UPDATE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "") - - ExternalProject_Get_Property(amqp_codegen SOURCE_DIR) - set(AMQP_CODEGEN_DIR ${SOURCE_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) - SET(AMQP_CODEGEN_TARGET amqp_codegen) - message(STATUS "Using amqp_codegen.py in ${AMQP_CODEGEN_DIR}") -else (FETCH_CODEGEN_FROM_GIT) - find_path(RABBITMQ_CODEGEN_DIR - amqp_codegen.py - PATHS ${CMAKE_SOURCE_DIR}/rabbitmq-codegen - ${CMAKE_SOURCE_DIR}/../rabbitmq-codegen - DOC "Path to directory containing amqp_codegen.py (rabbitmq-codegen)" - NO_DEFAULT_PATH - ) - - if (RABBITMQ_CODEGEN_DIR STREQUAL "RABBITMQ_CODEGEN_DIR-NOTFOUND") - message(SEND_ERROR "Cannot find rabbitmq-codegen, set RABBITMQ_CODEGEN_DIR to a rabbitmq-codegen checkout, or set FETCH_CODEGEN_FROM_GIT to download it from git automatically") - else () - message(STATUS "Using amqp_codegen.py in ${RABBITMQ_CODEGEN_DIR}") - endif() - - set(AMQP_CODEGEN_DIR ${RABBITMQ_CODEGEN_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) -endif (FETCH_CODEGEN_FROM_GIT) - -mark_as_advanced(AMQP_CODEGEN_DIR) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) - -find_package(POPT) - -add_subdirectory(librabbitmq) -add_subdirectory(examples) - -if (POPT_FOUND) - add_subdirectory(tools) -endif (POPT_FOUND) - diff --git a/COPYING b/COPYING deleted file mode 100644 index f5997d4dc..000000000 --- a/COPYING +++ /dev/null @@ -1 +0,0 @@ -See LICENSE-MIT. diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index e69de29bb..000000000 diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 8b82ade08..000000000 --- a/INSTALL +++ /dev/null @@ -1,291 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007, 2008 Free Software Foundation, Inc. - - This file is free documentation; the Free Software Foundation gives -unlimited permission to copy, distribute and modify it. - -Basic Installation -================== - - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for -instructions specific to this package. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package. - - 4. Type `make install' to install the programs and any data files and - documentation. - - 5. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 6. Often, you can also type `make uninstall' to remove the installed - files again. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - With a non-GNU `make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before -reconfiguring for another architecture. - - On MacOS X 10.5 and later systems, you can create libraries and -executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like -this: - - ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CPP="gcc -E" CXXCPP="g++ -E" - - This is not guaranteed to produce working output in all cases, you -may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. - -Installation Names -================== - - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Particular systems -================== - - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in -order to use an ANSI C compiler: - - ./configure CC="cc -Ae" - -and if that doesn't work, install pre-built binaries of GCC for HP-UX. - - On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try - - ./configure CC="cc" - -and if that doesn't work, try - - ./configure CC="cc -nodtk" - -Specifying the System Type -========================== - - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf bug. Until the bug is fixed you can use this workaround: - - CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash - -`configure' Invocation -====================== - - `configure' recognizes the following options to control how it -operates. - -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. - -`--help=short' -`--help=recursive' - Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--prefix=DIR' - Use DIR as the installation prefix. *Note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. - -`--no-create' -`-n' - Run the configure checks, but stop before creating any output - files. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - diff --git a/LICENSE-MIT b/LICENSE-MIT deleted file mode 100644 index 486e6e049..000000000 --- a/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. -All Rights Reserved. - -Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 -VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, -modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index a990faab2..000000000 --- a/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -if TOOLS -TOOLS_SUBDIR=tools -else -TOOLS_SUBDIR= -endif - -SUBDIRS=librabbitmq tests examples $(TOOLS_SUBDIR) - -squeakyclean: maintainer-clean - rm -f Makefile.in librabbitmq/Makefile.in tests/Makefile.in examples/Makefile.in tools/Makefile.in - rm -f aclocal.m4 - rm -f config.guess config.h.in* config.sub configure - rm -f depcomp install-sh ltmain.sh missing - rm -rf codegen - -codegen: - mkdir -p $@ - cp -r "$(top_srcdir)/$(AMQP_CODEGEN_DIR)"/* $@ - $(MAKE) -C $@ clean - -EXTRA_DIST=codegen debian LICENSE-MIT diff --git a/NEWS b/NEWS deleted file mode 100644 index e69de29bb..000000000 diff --git a/README b/README deleted file mode 100644 index cdec67336..000000000 --- a/README +++ /dev/null @@ -1,137 +0,0 @@ -# RabbitMQ C AMQP client library - -## Introduction - -This is a C-language AMQP client library for use with AMQP servers -speaking protocol versions 0-9-1. - - - - - - - - -Announcements regarding the library are periodically made on the -RabbitMQ mailing list and on the RabbitMQ blog. - - - - - - -## Retrieving the code - -In addition to the source code for this library, you will require a -copy of `rabbitmq-codegen`. Here is a short `sh` script for retrieving -the necessary pieces: - - hg clone http://hg.rabbitmq.com/rabbitmq-codegen/ - hg clone http://hg.rabbitmq.com/rabbitmq-c/ - -You will also need a recent python with the simplejson module -installed, and the GNU autotools (autoconf, automake, libtool etc) -or as an alternative CMake - -## Building the code - -# Using autoconf - -Once you have all the prerequisites, change to the `rabbitmq-c` -directory and run - - autoreconf -i - -to run the GNU autotools and generate the configure script, followed -by - - ./configure - make - -to build the `librabbitmq` library and the example programs. - -# Using cmake - -You will need CMake: http://cmake.org/ - -You will need a working python install in your path. - -If you would like the build system to fetch the rabbitmq-codegen -automatically you will need to have a working git install in your -path. Otherwise you will need to checkout the rabbitmq-codegen as -stated above. - -Create a binary directory in a sibling directory from the directory -you cloned the rabbitmq-c repository - - mkdir bin-rabbitmq-c - -Run CMake in the binary directory - - cmake /path/to/source/directory - -Build it: - -* On linux: `make` -* On win32: `nmake` or `msbuild`, or open it in visual studio and - build from there - -Things you can pass to cmake to change the build: - -* `-DRABBITMQ_CODEGEN_DIR=/path/to/rabbitmq-codegen/checkout` - if you - have your codegen directory in a different place [Default is - sibiling directory to source] -* `-DFETCH_CODEGEN_FROM_GIT=ON` - if you want cmake to fetch the - rabbitmq-codegen from https://github.com/rabbitmq/rabbitmq-codegen - at build time. If this option is selected `-DRABBITMQ_CODEGEN_DIR` - will be ignored [Default is off] -* `-DCODEGEN_GIT_TAG=rabbitmq_v2_5_1` - specifies the tag to check out - if using the `-DFETCH_CODEGEN_FROM_GIT` option above. [Default is - `rabbitmq_v2_5_1`] -* `-DBUILD_TOOLS=OFF` build the programs in the tools directory - [Default is ON if the POPT library can be found] - -Other interesting flags to pass to CMake (see cmake docs for more info) - -* `-DCMAKE_BUILD_TYPE` - specify the type of build (Debug or Release) -* `-DCMAKE_INSTALL_PREFIX` - specify where the install target puts files - -## Running the examples - -Arrange for a RabbitMQ or other AMQP server to be running on -`localhost` at TCP port number 5672. - -In one terminal, run - - ./examples/amqp_listen localhost 5672 amq.direct test - -In another terminal, - - ./examples/amqp_sendstring localhost 5672 amq.direct test "hello world" - -You should see output similar to the following in the listener's -terminal window: - - Result 1 - Frame type 1, channel 1 - Method AMQP_BASIC_DELIVER_METHOD - Delivery 1, exchange amq.direct routingkey test - Content-type: text/plain - ---- - 00000000: 68 65 6C 6C 6F 20 77 6F : 72 6C 64 hello world - 0000000B: - -## Writing applications using `librabbitmq` - -Please see the `examples` directory for short examples of the use of -the `librabbitmq` library. - -### Threading - -You cannot share a socket, an `amqp_connection_state_t`, or a channel -between threads using `librabbitmq`. The `librabbitmq` library is -built with event-driven, single-threaded applications in mind, and -does not yet cater to any of the requirements of `pthread`ed -applications. - -Your applications instead should open an AMQP connection (and an -associated socket, of course) per thread. If your program needs to -access an AMQP connection or any of its channels from more than one -thread, it is entirely responsible for designing and implementing an -appropriate locking scheme. It will generally be much simpler to have -a connection exclusive to each thread that needs AMQP service. diff --git a/README.md b/README.md deleted file mode 120000 index 100b93820..000000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -README \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..55a1b2b57 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Update your bookmarks! +====================== + +The official rabbitmq-c source has been moved to: + +https://github.com/alanxz/rabbitmq-c diff --git a/README.windows b/README.windows deleted file mode 100644 index 2774f19a1..000000000 --- a/README.windows +++ /dev/null @@ -1,124 +0,0 @@ -# Using rabbitmq-c on Windows - -There are three approaches to building rabbitmq-c under Windows: - -- Build using the MinGW/MSYS (MinGW/MSYS is a port of the GNU - toolchain and utilities to Windows, including the gcc compiler). - The results of building in this way are native Windows DLLs and - EXEs, and can be used without having MinGW installed. The drawback - to this approach is that you cannot safely call the resulting - librabbitmq DLL from code compiled with Microsoft's C compiler. The - advantage is that the whole of rabbitmq-c can be built under - Windows, including the tools. - -- Build using Microsoft's C compiler. You will still need to install - MinGW/MSYS in order to run the rabbitmq-c build scripts, but - Microsoft's compiler is used to compile the code. The resulting - librabbitmq DLL can be used from code compiled with Microsoft's C - compiler (i.e. code developed in Visual Studio). The downside to - this approach is that the rabbitmq-c tools cannot be built, due to - dependencies on other libraries. - -- Build using CMake, which will cover building with MSVC or MinGW - See the README file for details on how to build with cmake. - - -## Common steps - -With either of the approaches, the initial steps are the same: You -should download and install MinGW/MSYS and Python. - -Installing installing the relevant parts of MinGW/MSYS can be fairly -time consuming - there are dozens of files to be downloaded and -unpacked. To make it easier, we provide a bash script that automates -this process, in `rabbitmq-c/etc/install-mingw.sh`. You can run this -script under cygwin or Linux (obviously if you use Linux you'll need -to transfer the resulting files over to the Windows machine). - -Note that some MinGW packages are .tar.lzma files, so it requires a -system with the xz compression utility and a tar that supports the -J -option. Recent cygwin and Linux distros should be fine here. - -Run the install-mingw.sh script specifying the destination directory, -e.g. - - $ etc/install-mingw.sh mingw - -This will download all the required MinGW/MSYS packages, and unpack -them into the `mingw` directory. - -The other prerequisite for the rabbitmq-c build is Python. The -Windows installer from python.org for the latest 2.x version of Python -will do fine. - -You will also need to copy the source code for rabbitmq-c and -rabbitmq-codegen somewhere under your `mingw` directory. - -Then to start the MSYS bash shell, open a `cmd` window, and ensure -that both the MinGW bin directory and the python install directory are -in the path, e.g. - - C:\>set PATH=%PATH%;C:\mingw\bin;C:\Python27 - -Then start bash, and run the following mount command (substituting the -Windows path of your MinGW install if it isn't `C:\mingw`): - - C:\>bash - bash-3.1$ mount 'C:\mingw' /mingw - -Finally, go to wherever you copied the rabbitmq-c source. - - bash-3.1$ cd /rabbitmq-c - - -## Building rabbitmq-c with Microsoft's C compiler - -The Microsoft C/C++ compiler is part of MS Visual Studio, including -the gratis Visual Studio Express. Visual Studio 2005 and higher are -known to work. - -Start by following the steps in the previous section. The GNU build -tools have limited support for Microsoft toolchain, but the -install-mingw.sh script will install versions of the packages that are -known to be suitable. In particular, only libtool version 2.2.7a is -known to work; later versions have been reported to introduce -problems. - -Once you are at the bash prompt, build rabbitmq-c by running the -script in `rabbitmq-c/etc/build-ms.sh`: - - bash-3.1$ etc/build-ms.sh - -You should end up with a directory `build` containing the librabbitmq -DLL, the corresponding .lib file, and header files. These are -sufficient to create applications using librabbitmq within Visual -Studio. - -build-ms.sh produces 32-bit binaries by default. If you have an -appropriate version of Visual Studio (e.g. VS2010), you can build -64-bit binaries with: - - bash-3.1$ etc/build-ms.sh --enable-64-bit - - -## Building rabbitmq-c with gcc - -There is no script to build rabbitmq-c with gcc, but it is as -documented in the README file: - - bash-3.1$ autoreconf -i && ./configure && make - -You can run the resulting tool EXEs without needing the rest of MinGW. To do -this, copy the following files into a single directory: - -- rabbitmq-c/tools/.libs/*.exe - -- rabbitmq-c/librabbitmq/.libs/librabbitmq-0.dll - -- /bin/libpopt-0.dll - -- /bin/libiconv-2.dll - -- /bin/libintl-8.dll - - diff --git a/THANKS b/THANKS deleted file mode 100644 index 1f378eadf..000000000 --- a/THANKS +++ /dev/null @@ -1,8 +0,0 @@ -Thank-you to the following people for their contributions to the -codebase: - - - Scott Brooks / Epic Advertising - - - Frank Gönninger - - - Daniel Schauenberg diff --git a/TODO b/TODO deleted file mode 100644 index 179d297aa..000000000 --- a/TODO +++ /dev/null @@ -1,9 +0,0 @@ -Deal with version-mismatch-header received from the server - -Cope with unknown frame types better. Currently it gets horribly -confused about frame lengths. - -Make client brutal by default, killing the program on any amqp -error. Only if the user disables this behaviour will the user get to -deal with error conditions themselves. Make use of amqp_rpc_reply -consistent (i.e. universal), and rename it something like amqp_errno. diff --git a/TestCInline.cmake b/TestCInline.cmake deleted file mode 100644 index 4fdd4c5bb..000000000 --- a/TestCInline.cmake +++ /dev/null @@ -1,28 +0,0 @@ -#Inspired from http://www.cmake.org/Wiki/CMakeTestInline - -IF(NOT DEFINED C_INLINE_DETECTED) - - SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */ -static inline int static_foo() {return 0\;} -int main(int argc, char *argv[]){return 0\;} -") - - FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c ${INLINE_TEST_SRC}) - - FOREACH(KEYWORD "inline" "__inline__" "__inline") - IF(NOT DEFINED C_INLINE) - TRY_COMPILE(C_HAS_${KEYWORD} - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c - COMPILE_DEFINITIONS "-Dinline=${KEYWORD}" - ) - IF(C_HAS_${KEYWORD}) - SET(C_INLINE ${KEYWORD}) - ENDIF(C_HAS_${KEYWORD}) - ENDIF(NOT DEFINED C_INLINE) - ENDFOREACH(KEYWORD) - - SET(C_INLINE_DETECTED True CACHE BOOL INTERNAL) - -ENDIF(NOT DEFINED C_INLINE_DETECTED) - diff --git a/cmake/FindPOPT.cmake b/cmake/FindPOPT.cmake deleted file mode 100644 index e0af6789e..000000000 --- a/cmake/FindPOPT.cmake +++ /dev/null @@ -1,18 +0,0 @@ -INCLUDE(LibFindMacros) - -# Find the include directories -FIND_PATH(POPT_INCLUDE_DIR - NAMES popt.h - HINTS ${POPT_PREFIX}/include - ) - -FIND_LIBRARY(POPT_LIBRARY - NAMES popt - HINTS ${POPT_PREFIX}/lib - ) - -SET(POPT_PROCESS_INCLUDES POPT_INCLUDE_DIR) -SET(POPT_PROCESS_LIBS POPT_LIBRARY) - -LIBFIND_PROCESS(POPT) - diff --git a/cmake/LibFindMacros.cmake b/cmake/LibFindMacros.cmake deleted file mode 100644 index 69975c51b..000000000 --- a/cmake/LibFindMacros.cmake +++ /dev/null @@ -1,99 +0,0 @@ -# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments -# used for the current package. For this to work, the first parameter must be the -# prefix of the current package, then the prefix of the new package etc, which are -# passed to find_package. -macro (libfind_package PREFIX) - set (LIBFIND_PACKAGE_ARGS ${ARGN}) - if (${PREFIX}_FIND_QUIETLY) - set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) - endif (${PREFIX}_FIND_QUIETLY) - if (${PREFIX}_FIND_REQUIRED) - set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) - endif (${PREFIX}_FIND_REQUIRED) - find_package(${LIBFIND_PACKAGE_ARGS}) -endmacro (libfind_package) - -# CMake developers made the UsePkgConfig system deprecated in the same release (2.6) -# where they added pkg_check_modules. Consequently I need to support both in my scripts -# to avoid those deprecated warnings. Here's a helper that does just that. -# Works identically to pkg_check_modules, except that no checks are needed prior to use. -macro (libfind_pkg_check_modules PREFIX PKGNAME) - if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) - include(UsePkgConfig) - pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) - else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) - find_package(PkgConfig) - if (PKG_CONFIG_FOUND) - pkg_check_modules(${PREFIX} ${PKGNAME}) - endif (PKG_CONFIG_FOUND) - endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) -endmacro (libfind_pkg_check_modules) - -# Do the final processing once the paths have been detected. -# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain -# all the variables, each of which contain one include directory. -# Ditto for ${PREFIX}_PROCESS_LIBS and library files. -# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. -# Also handles errors in case library detection was required, etc. -macro (libfind_process PREFIX) - # Skip processing if already processed during this run - if (NOT ${PREFIX}_FOUND) - # Start with the assumption that the library was found - set (${PREFIX}_FOUND TRUE) - - # Process all includes and set _FOUND to false if any are missing - foreach (i ${${PREFIX}_PROCESS_INCLUDES}) - if (${i}) - set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) - mark_as_advanced(${i}) - else (${i}) - set (${PREFIX}_FOUND FALSE) - endif (${i}) - endforeach (i) - - # Process all libraries and set _FOUND to false if any are missing - foreach (i ${${PREFIX}_PROCESS_LIBS}) - if (${i}) - set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) - mark_as_advanced(${i}) - else (${i}) - set (${PREFIX}_FOUND FALSE) - endif (${i}) - endforeach (i) - - # Print message and/or exit on fatal error - if (${PREFIX}_FOUND) - if (NOT ${PREFIX}_FIND_QUIETLY) - message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") - endif (NOT ${PREFIX}_FIND_QUIETLY) - else (${PREFIX}_FOUND) - if (${PREFIX}_FIND_REQUIRED) - foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) - message("${i}=${${i}}") - endforeach (i) - message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") - endif (${PREFIX}_FIND_REQUIRED) - endif (${PREFIX}_FOUND) - endif (NOT ${PREFIX}_FOUND) -endmacro (libfind_process) - -macro(libfind_library PREFIX basename) - set(TMP "") - if(MSVC80) - set(TMP -vc80) - endif(MSVC80) - if(MSVC90) - set(TMP -vc90) - endif(MSVC90) - set(${PREFIX}_LIBNAMES ${basename}${TMP}) - if(${ARGC} GREATER 2) - set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) - string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) - set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) - endif(${ARGC} GREATER 2) - find_library(${PREFIX}_LIBRARY - NAMES ${${PREFIX}_LIBNAMES} - PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} - ) -endmacro(libfind_library) - diff --git a/configure.ac b/configure.ac deleted file mode 100644 index e6aac3225..000000000 --- a/configure.ac +++ /dev/null @@ -1,166 +0,0 @@ -AC_INIT([librabbitmq],[0.0.1],[support@rabbitmq.com]) -AC_CONFIG_SRCDIR(librabbitmq/codegen.py) -AM_INIT_AUTOMAKE - -AC_CONFIG_HEADER([config.h]) - -dnl Program checks -AC_GNU_SOURCE -AC_PROG_CC - -dnl Library checks -AC_LIBTOOL_WIN32_DLL -AM_PROG_LIBTOOL - -dnl Header-file checks -AC_HEADER_STDC - -if test "x$GCC" = "xyes"; then - dnl Only use -Wall if we have gcc - if ! echo "$CFLAGS" | grep "\-Wall" 2> /dev/null ; then - CFLAGS="$CFLAGS -Wall" - fi -fi - -dnl Detect the kind of host we're building for -AC_CANONICAL_HOST -windows=no -case "${host}" in -*-*-mingw*) - windows=yes - ;; -esac -AM_CONDITIONAL(WINDOWS, test "x$windows" = xyes) -AS_IF([test "x$windows" = xyes], - [AC_DEFINE([WINDOWS], [1], [Define to 1 if on Windows.])] -) - -AM_CONDITIONAL(GCC, test "x$GCC" = xyes) - -# Detect how to declare inline functions. Because we will sometimes -# use "-ansi -pedantic" with gcc, we need to make sure the result will -# work in that context. -orig_cflags="$CFLAGS" -AS_IF([test "x$GCC" = "xyes"], [CFLAGS="$CFLAGS -ansi -pedantic"]) -AC_C_INLINE -CFLAGS="$orig_cflags" - -AC_C_BIGENDIAN - -dnl Decide which API abstraction layer to use -PLATFORM_DIR=unix -if test "x$windows" = xyes ; then - PLATFORM_DIR=windows -fi -AC_SUBST(PLATFORM_DIR) - -dnl Enable -m64 if we were asked to do so -AC_ARG_ENABLE(64-bit, -[ --enable-64-bit produce 64-bit library], -[CFLAGS="$CFLAGS -m64"; LDFLAGS="$LDFLAGS -m64"], -) - -AC_MSG_CHECKING(location of AMQP codegen directory) -for d in ../rabbitmq-codegen codegen ; do - AMQP_CODEGEN_DIR="$d" - test -d "$srcdir/$AMQP_CODEGEN_DIR" && break -done -AMQP_SPEC_JSON_PATH="$AMQP_CODEGEN_DIR/amqp-rabbitmq-0.9.1.json" - -if test -f "$srcdir/$AMQP_SPEC_JSON_PATH" -then - AC_MSG_RESULT($AMQP_CODEGEN_DIR) -else - AC_MSG_ERROR(could not find AMQP spec file at "'$AMQP_SPEC_JSON_PATH'") -fi - -AC_MSG_CHECKING(finding a python with simplejson installed) -found_python=no -checkPython() { - if test "$found_python" = "yes" - then - return - fi - PYTHON=$1 - if $PYTHON -c 'import json' 2>/dev/null \ - || $PYTHON -c 'import simplejson' 2>/dev/null - then - found_python=yes - AC_MSG_RESULT($PYTHON) - fi -} -checkPython python -checkPython python2.6 -checkPython python2.5 -if test "$found_python" = "no" -then - AC_MSG_ERROR(could not find a python that can 'import simplejson') -fi - -AC_SUBST(AMQP_CODEGEN_DIR) -AC_SUBST(AMQP_SPEC_JSON_PATH) -AC_SUBST(PYTHON) - -dnl Decide which extra win32 libs we need, and handle other special -dnl cases when building with the Microsoft compiler -EXTRA_LIBS= -USE_MISINTTYPES= -AS_IF([test "x$windows" = xyes], - [ - AS_IF([test "x$GCC" = xyes], - [EXTRA_LIBS="-lws2_32 $EXTRA_LIBS"], - [ - EXTRA_LIBS="ws2_32.lib $EXTRA_LIBS" - USE_MSINTTYPES=yes - ]) - ]) - -AC_SUBST(EXTRA_LIBS) -AM_CONDITIONAL(USE_MSINTTYPES, test "x$USE_MSINTTYPES" != "x") - -dnl Check for libpopt, which we need to build the tools -AC_ARG_WITH([popt], - [AS_HELP_STRING([--with-popt], [use the popt library. Needed for tools.])], - [], - [with_popt=check]) - -LIBPOPT= -AS_IF([test "x$with_popt" != xno], - [AC_CHECK_LIB([popt], [poptGetContext], - [AC_SUBST([LIBPOPT], ["-lpopt"]) - AC_DEFINE([HAVE_LIBPOPT], [1], [Define if you have libpopt]) - ], - [if test "x$with_popt" != xcheck; then - AC_MSG_FAILURE([--with-popt was given, but test for libpopt failed]) - fi - ])]) - -AS_IF([test "x$LIBPOPT" != "x"], - [AC_CHECK_HEADER([popt.h], [], - [AC_MSG_FAILURE([You have libpopt, but could not find the popt.h header])]) - ]) - -AM_CONDITIONAL(TOOLS, test "x$LIBPOPT" != "x") - -AC_ARG_WITH([xmlto], - [AS_HELP_STRING([--with-xmlto], [use the xmlto toolchain. Needed for tools man pages.])], - [], - [with_xmlto=check]) - -XMLTO= -AS_IF([test "x$with_xmlto" != xno], - [AC_CHECK_PROG([XMLTO], [xmlto], [xmlto]) - if test "x$with_xmlto" != xcheck; then - AC_MSG_FAILURE([--with-xmlto was given, but xmlto not found]) - fi]) - -AM_CONDITIONAL(TOOLS_DOC, test "x$XMLTO" != "x") - -AC_OUTPUT( -Makefile -librabbitmq/Makefile -tests/Makefile -examples/Makefile -tools/Makefile -tools/doc/Makefile -) diff --git a/debian/amqp-tools.docs b/debian/amqp-tools.docs deleted file mode 100644 index e2cf5a1eb..000000000 --- a/debian/amqp-tools.docs +++ /dev/null @@ -1 +0,0 @@ -LICENSE-MIT diff --git a/debian/amqp-tools.install b/debian/amqp-tools.install deleted file mode 100644 index 03e10525a..000000000 --- a/debian/amqp-tools.install +++ /dev/null @@ -1,3 +0,0 @@ -debian/tmp/usr/bin/* usr/bin -debian/tmp/usr/share/man/man1/* usr/share/man/man1 -debian/tmp/usr/share/man/man7/* usr/share/man/man7 diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 7f2de4558..000000000 --- a/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -librabbitmq (1.0-1) unstable; urgency=low - - * Initial release - - -- Tony Garnock-Jones Tue, 14 Jul 2009 04:42:37 +0100 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff82d..000000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index fd6971356..000000000 --- a/debian/control +++ /dev/null @@ -1,29 +0,0 @@ -Source: librabbitmq -Section: libs -Priority: extra -Maintainer: Tony Garnock-Jones -Build-Depends: debhelper (>= 7), autoconf, automake, libtool, python (>= 2.5), python-simplejson, libpopt-dev, xmlto -Standards-Version: 3.8.1 -Homepage: http://www.rabbitmq.com/ -Vcs-Browser: http://hg.rabbitmq.com/rabbitmq-c - -Package: librabbitmq -Architecture: any -Section: libs -Priority: extra -Depends: -Description: An AMQP client library written in C - -Package: librabbitmq-dev -Architecture: any -Section: libdevel -Priority: extra -Depends: librabbitmq (= ${binary:Version}), libc-dev -Description: developer's libraries and docs for librabbitmq - -Package: amqp-tools -Architecture: any -Section: net -Priority: extra -Depends: librabbitmq (= ${binary:Version}), ${shlibs:Depends} -Description: Command-line utilities for interacting with AMQP servers diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index c3be4043b..000000000 --- a/debian/copyright +++ /dev/null @@ -1,17 +0,0 @@ -This package was debianized by Tony Garnock-Jones - on Tue, 14 Jul 2009 04:42:37 +0100. - -Upstream Author: The RabbitMQ team at VMware, Inc. - -Copyright: Portions created by VMware are Copyright (c) 2007-2012 -VMware, Inc. All Rights Reserved. Portions created by Tony -Garnock-Jones are Copyright (c) 2009-2010 VMware, Inc. and Tony -Garnock-Jones. All Rights Reserved. - -License: This package, librabbitmq, the RabbitMQ C client, is licensed -under the MIT. For the license, please see LICENSE-MIT. Please see -also the license block near the top of each source file in the -package. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. diff --git a/debian/librabbitmq-dev.docs b/debian/librabbitmq-dev.docs deleted file mode 100644 index e2cf5a1eb..000000000 --- a/debian/librabbitmq-dev.docs +++ /dev/null @@ -1 +0,0 @@ -LICENSE-MIT diff --git a/debian/librabbitmq-dev.install b/debian/librabbitmq-dev.install deleted file mode 100644 index b4f0bfda0..000000000 --- a/debian/librabbitmq-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -debian/tmp/usr/include/*.h usr/include -debian/tmp/usr/lib/*.a usr/lib -debian/tmp/usr/lib/*.la usr/lib -debian/tmp/usr/lib/*.so usr/lib diff --git a/debian/librabbitmq.docs b/debian/librabbitmq.docs deleted file mode 100644 index e2cf5a1eb..000000000 --- a/debian/librabbitmq.docs +++ /dev/null @@ -1 +0,0 @@ -LICENSE-MIT diff --git a/debian/librabbitmq.install b/debian/librabbitmq.install deleted file mode 100644 index 84bc66315..000000000 --- a/debian/librabbitmq.install +++ /dev/null @@ -1 +0,0 @@ -debian/tmp/usr/lib/*.so.* usr/lib diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 10327f220..000000000 --- a/debian/rules +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/make -f - -build: build-stamp -build-stamp: - dh build - touch build-stamp - -clean: - dh clean - rm -f build-stamp - rm -f install-stamp - -install: build install-stamp -install-stamp: - dh install - touch install-stamp - -binary-arch: install - dh binary-arch - -binary-indep: install - dh binary-indep - -binary: binary-arch binary-indep diff --git a/etc/build-ms.sh b/etc/build-ms.sh deleted file mode 100755 index 8567eac39..000000000 --- a/etc/build-ms.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -# Build rabbitmq-c using Microsoft's C compiler - -set -e - -vs64= -sdk64= - -while [ $# -gt 0 ] ; do - case $1 in - --enable-64-bit) - vs64=/amd64 - sdk64=/x64 - ;; - *) - echo "Usage: build-ms.sh [ --enable-64-bit ]" 1>&2 - exit 1 - esac - shift -done - -# Locate the necessary lib and include directories - -drive=$(echo "$SYSTEMDRIVE" | sed 's|^\([A-Za-z]\):$|/\1|') - -for vsvers in 10.0 9.0 8 ; do - vsdir="$drive/Program Files/Microsoft Visual Studio $vsvers" - [ -x "$vsdir/VC/bin$vs64/cl.exe" ] && break - - vsdir="$drive/Program Files (x86)/Microsoft Visual Studio $vsvers" - [ -x "$vsdir/VC/bin$vs64/cl.exe" ] && break - - vsdir= -done - -if [ -z "$vsdir" ] ; then - echo "Couldn't find a suitable Visual Studio installation" - exit 1 -fi - -echo "Using Visual Studio install at $vsdir" - -for sdkpath in "Microsoft SDKs/Windows/"{v7.0A,v6.0A} "Microsoft Visual Studio 8/VC/PlatformSDK" ; do - sdkdir="$drive/Program Files/$sdkpath" - [ -d "$sdkdir/lib$sdk64" -a -d "$sdkdir/include" ] && break - - sdkdir="$drive/Program Files (x86)/$sdkpath" - [ -d "$sdkdir/lib$sdk64" -a -d "$sdkdir/include" ] && break - - sdkdir= -done - -if [ -z "$sdkdir" ] ; then - echo "Couldn't find suitable Windows SDK installation" - exit 1 -fi - -echo "Using Windows SDK install at $sdkdir" - -PATH="$PATH:$vsdir/VC/bin$vs64:$vsdir/Common7/IDE" -LIB="$vsdir/VC/lib$vs64:$sdkdir/lib$sdk64" -INCLUDE="$vsdir/VC/include:$sdkdir/include" -export PATH LIB INCLUDE - -# Do the build -set -x -autoreconf -i -./configure CC=cl.exe LD=link.exe CFLAGS='-nologo' -sed -i -e 's/^fix_srcfile_path=.*$/fix_srcfile_path=""/;s/^deplibs_check_method=.*$/deplibs_check_method=pass_all/;/^archive_cmds=/s/-link -dll/& -implib:\\$libname.\\$libext/' libtool -make - -# Copy the results of the build into one place, as "make install" -# isn't too useful here. -mkdir -p build/lib build/include build/bin -cp -a librabbitmq/.libs/*.dll examples/.libs/*.exe build/bin -cp -a msinttypes/*.h librabbitmq/amqp.h librabbitmq/amqp_framing.h build/include -cp -a librabbitmq/*.exp librabbitmq/*.lib build/lib diff --git a/etc/install-mingw.sh b/etc/install-mingw.sh deleted file mode 100755 index 289315f32..000000000 --- a/etc/install-mingw.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -if [ $# -ne 1 ] ; then - echo "usage: install-mingw.sh " 1>&2 - exit 1 -fi - -unpack_dir=$1 - -if [ -e "$unpack_dir" ] ; then - echo "Destination directory already exists; please delete it if you are sure" 1>&2 - exit 1 -fi - -set -e - -download_dir=/tmp/install-mingw.$$ -mkdir -p $download_dir $unpack_dir - -while read f ; do - wget -P $download_dir -N http://switch.dl.sourceforge.net/project/mingw/$f -done <&2 - exit 1 - ;; - esac -done - -rm -rf $download_dir diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 8b58e8b73..000000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -include_directories(${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR}) - -if (WIN32) - set(PLATFORM_DIR windows) -else (WIN32) - set(PLATFORM_DIR unix) -endif (WIN32) - -set(COMMON_SRCS - utils.h - utils.c - ${PLATFORM_DIR}/platform_utils.c - ) - -add_executable(amqp_sendstring amqp_sendstring.c ${COMMON_SRCS}) -target_link_libraries(amqp_sendstring rabbitmq) - -add_executable(amqp_exchange_declare amqp_exchange_declare.c ${COMMON_SRCS}) -target_link_libraries(amqp_exchange_declare rabbitmq) - -add_executable(amqp_listen amqp_listen.c ${COMMON_SRCS}) -target_link_libraries(amqp_listen rabbitmq) - -add_executable(amqp_producer amqp_producer.c ${COMMON_SRCS}) -target_link_libraries(amqp_producer rabbitmq) - -add_executable(amqp_consumer amqp_consumer.c ${COMMON_SRCS}) -target_link_libraries(amqp_consumer rabbitmq) - -add_executable(amqp_unbind amqp_unbind.c ${COMMON_SRCS}) -target_link_libraries(amqp_unbind rabbitmq) - -add_executable(amqp_bind amqp_bind.c ${COMMON_SRCS}) -target_link_libraries(amqp_bind rabbitmq) - -add_executable(amqp_listenq amqp_listenq.c ${COMMON_SRCS}) -target_link_libraries(amqp_listenq rabbitmq) diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index bde66bd36..000000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -noinst_PROGRAMS = amqp_sendstring amqp_exchange_declare amqp_listen amqp_producer amqp_consumer amqp_unbind amqp_bind amqp_listenq - -# The -I to srcdir's librabbitmq is for the main amqp header -# files. The -I to builddir's librabbitmq is less obvious; it's for -# VPATH-based builds: the amqp_framing.h gets generated into the -# *build* directory, not the source directory. -AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(top_builddir)/librabbitmq - -if GCC -# Because we want to build under Microsoft's C compiler (for which -# there is apparently no demand for C99 support), it's a good idea -# to have gcc tell us when we stray from the old standard. -AM_CFLAGS += -ansi -pedantic -endif - -if USE_MSINTTYPES -AM_CFLAGS += -I$(top_srcdir)/msinttypes -endif - -AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la - -noinst_HEADERS = utils.h - -COMMON_SOURCES = utils.c $(PLATFORM_DIR)/platform_utils.c - -amqp_sendstring_SOURCES = amqp_sendstring.c $(COMMON_SOURCES) -amqp_exchange_declare_SOURCES = amqp_exchange_declare.c $(COMMON_SOURCES) -amqp_listen_SOURCES = amqp_listen.c $(COMMON_SOURCES) -amqp_producer_SOURCES = amqp_producer.c $(COMMON_SOURCES) -amqp_consumer_SOURCES = amqp_consumer.c $(COMMON_SOURCES) -amqp_unbind_SOURCES = amqp_unbind.c $(COMMON_SOURCES) -amqp_bind_SOURCES = amqp_bind.c $(COMMON_SOURCES) -amqp_listenq_SOURCES = amqp_listenq.c $(COMMON_SOURCES) diff --git a/examples/amqp_bind.c b/examples/amqp_bind.c deleted file mode 100644 index b689617bc..000000000 --- a/examples/amqp_bind.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - char const *queue; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_bind host port exchange bindingkey queue\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - queue = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_queue_bind(conn, 1, - amqp_cstring_bytes(queue), - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_consumer.c b/examples/amqp_consumer.c deleted file mode 100644 index 4fb4a8fc6..000000000 --- a/examples/amqp_consumer.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void run(amqp_connection_state_t conn) -{ - uint64_t start_time = now_microseconds(); - int received = 0; - int previous_received = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - amqp_frame_t frame; - int result; - size_t body_received; - size_t body_target; - - uint64_t now; - - while (1) { - now = now_microseconds(); - if (now > next_summary_time) { - int countOverInterval = received - previous_received; - double intervalRate = countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Received %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, received, countOverInterval, (int) intervalRate); - - previous_received = received; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - return; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - } - - received++; - } -} - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - - int sockfd; - amqp_connection_state_t conn; - - amqp_bytes_t queuename; - - if (argc < 3) { - fprintf(stderr, "Usage: amqp_consumer host port\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = "amq.direct"; /* argv[3]; */ - bindingkey = "test queue"; /* argv[4]; */ - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - run(conn); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_exchange_declare.c b/examples/amqp_exchange_declare.c deleted file mode 100644 index 19dc1f988..000000000 --- a/examples/amqp_exchange_declare.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *exchangetype; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_exchange_declare host port exchange exchangetype\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - exchangetype = argv[4]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_exchange_declare(conn, 1, amqp_cstring_bytes(exchange), amqp_cstring_bytes(exchangetype), - 0, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring exchange"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_listen.c b/examples/amqp_listen.c deleted file mode 100644 index ea4497302..000000000 --- a/examples/amqp_listen.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - - int sockfd; - amqp_connection_state_t conn; - - amqp_bytes_t queuename; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_listen host port exchange bindingkey\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, 1, amqp_empty_bytes, 0, 0, 0, 1, - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Declaring queue"); - queuename = amqp_bytes_malloc_dup(r->queue); - if (queuename.bytes == NULL) { - fprintf(stderr, "Out of memory while copying queue name"); - return 1; - } - } - - amqp_queue_bind(conn, 1, queuename, amqp_cstring_bytes(exchange), amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Binding queue"); - - amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - amqp_frame_t frame; - int result; - - amqp_basic_deliver_t *d; - amqp_basic_properties_t *p; - size_t body_target; - size_t body_received; - - while (1) { - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - printf("Result %d\n", result); - if (result < 0) - break; - - printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - printf("Method %s\n", amqp_method_name(frame.payload.method.id)); - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - d = (amqp_basic_deliver_t *) frame.payload.method.decoded; - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned) d->delivery_tag, - (int) d->exchange.len, (char *) d->exchange.bytes, - (int) d->routing_key.len, (char *) d->routing_key.bytes); - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - p = (amqp_basic_properties_t *) frame.payload.properties.decoded; - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int) p->content_type.len, (char *) p->content_type.bytes); - } - printf("----\n"); - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - - amqp_dump(frame.payload.body_fragment.bytes, - frame.payload.body_fragment.len); - } - - if (body_received != body_target) { - /* Can only happen when amqp_simple_wait_frame returns <= 0 */ - /* We break here to close the connection */ - break; - } - } - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_listenq.c b/examples/amqp_listenq.c deleted file mode 100644 index f05008793..000000000 --- a/examples/amqp_listenq.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *queuename; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 4) { - fprintf(stderr, "Usage: amqp_listenq host port queuename\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - queuename = argv[3]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_basic_consume(conn, 1, amqp_cstring_bytes(queuename), amqp_empty_bytes, 0, 0, 0, amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); - - { - amqp_frame_t frame; - int result; - - amqp_basic_deliver_t *d; - amqp_basic_properties_t *p; - size_t body_target; - size_t body_received; - - while (1) { - amqp_maybe_release_buffers(conn); - result = amqp_simple_wait_frame(conn, &frame); - printf("Result %d\n", result); - if (result < 0) - break; - - printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); - if (frame.frame_type != AMQP_FRAME_METHOD) - continue; - - printf("Method %s\n", amqp_method_name(frame.payload.method.id)); - if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - d = (amqp_basic_deliver_t *) frame.payload.method.decoded; - printf("Delivery %u, exchange %.*s routingkey %.*s\n", - (unsigned) d->delivery_tag, - (int) d->exchange.len, (char *) d->exchange.bytes, - (int) d->routing_key.len, (char *) d->routing_key.bytes); - - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_HEADER) { - fprintf(stderr, "Expected header!"); - abort(); - } - p = (amqp_basic_properties_t *) frame.payload.properties.decoded; - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - printf("Content-type: %.*s\n", - (int) p->content_type.len, (char *) p->content_type.bytes); - } - printf("----\n"); - - body_target = frame.payload.properties.body_size; - body_received = 0; - - while (body_received < body_target) { - result = amqp_simple_wait_frame(conn, &frame); - if (result < 0) - break; - - if (frame.frame_type != AMQP_FRAME_BODY) { - fprintf(stderr, "Expected body!"); - abort(); - } - - body_received += frame.payload.body_fragment.len; - assert(body_received <= body_target); - - amqp_dump(frame.payload.body_fragment.bytes, - frame.payload.body_fragment.len); - } - - if (body_received != body_target) { - /* Can only happen when amqp_simple_wait_frame returns <= 0 */ - /* We break here to close the connection */ - break; - } - - amqp_basic_ack(conn, 1, d->delivery_tag, 0); - } - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - - return 0; -} diff --git a/examples/amqp_producer.c b/examples/amqp_producer.c deleted file mode 100644 index c149a7203..000000000 --- a/examples/amqp_producer.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -#define SUMMARY_EVERY_US 1000000 - -static void send_batch(amqp_connection_state_t conn, - char const *queue_name, - int rate_limit, - int message_count) -{ - uint64_t start_time = now_microseconds(); - int i; - int sent = 0; - int previous_sent = 0; - uint64_t previous_report_time = start_time; - uint64_t next_summary_time = start_time + SUMMARY_EVERY_US; - - char message[256]; - amqp_bytes_t message_bytes; - - for (i = 0; i < sizeof(message); i++) { - message[i] = i & 0xff; - } - - message_bytes.len = sizeof(message); - message_bytes.bytes = message; - - for (i = 0; i < message_count; i++) { - uint64_t now = now_microseconds(); - - die_on_error(amqp_basic_publish(conn, - 1, - amqp_cstring_bytes("amq.direct"), - amqp_cstring_bytes(queue_name), - 0, - 0, - NULL, - message_bytes), - "Publishing"); - sent++; - if (now > next_summary_time) { - int countOverInterval = sent - previous_sent; - double intervalRate = countOverInterval / ((now - previous_report_time) / 1000000.0); - printf("%d ms: Sent %d - %d since last report (%d Hz)\n", - (int)(now - start_time) / 1000, sent, countOverInterval, (int) intervalRate); - - previous_sent = sent; - previous_report_time = now; - next_summary_time += SUMMARY_EVERY_US; - } - - while (((i * 1000000.0) / (now - start_time)) > rate_limit) { - microsleep(2000); - now = now_microseconds(); - } - } - - { - uint64_t stop_time = now_microseconds(); - int total_delta = stop_time - start_time; - - printf("PRODUCER - Message count: %d\n", message_count); - printf("Total time, milliseconds: %d\n", total_delta / 1000); - printf("Overall messages-per-second: %g\n", (message_count / (total_delta / 1000000.0))); - } -} - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - int rate_limit; - int message_count; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 5) { - fprintf(stderr, "Usage: amqp_producer host port rate_limit message_count\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - rate_limit = atoi(argv[3]); - message_count = atoi(argv[4]); - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - send_batch(conn, "test queue", rate_limit, message_count); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_sendstring.c b/examples/amqp_sendstring.c deleted file mode 100644 index ea30d95c9..000000000 --- a/examples/amqp_sendstring.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *routingkey; - char const *messagebody; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_sendstring host port exchange routingkey messagebody\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - routingkey = argv[4]; - messagebody = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - { - amqp_basic_properties_t props; - props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG; - props.content_type = amqp_cstring_bytes("text/plain"); - props.delivery_mode = 2; /* persistent delivery mode */ - die_on_error(amqp_basic_publish(conn, - 1, - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(routingkey), - 0, - 0, - &props, - amqp_cstring_bytes(messagebody)), - "Publishing"); - } - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/amqp_unbind.c b/examples/amqp_unbind.c deleted file mode 100644 index c26031c29..000000000 --- a/examples/amqp_unbind.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -int main(int argc, char const * const *argv) { - char const *hostname; - int port; - char const *exchange; - char const *bindingkey; - char const *queue; - - int sockfd; - amqp_connection_state_t conn; - - if (argc < 6) { - fprintf(stderr, "Usage: amqp_unbind host port exchange bindingkey queue\n"); - return 1; - } - - hostname = argv[1]; - port = atoi(argv[2]); - exchange = argv[3]; - bindingkey = argv[4]; - queue = argv[5]; - - conn = amqp_new_connection(); - - die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); - amqp_set_sockfd(conn, sockfd); - die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), - "Logging in"); - amqp_channel_open(conn, 1); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); - - amqp_queue_unbind(conn, 1, - amqp_cstring_bytes(queue), - amqp_cstring_bytes(exchange), - amqp_cstring_bytes(bindingkey), - amqp_empty_table); - die_on_amqp_error(amqp_get_rpc_reply(conn), "Unbinding"); - - die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); - die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); - die_on_error(amqp_destroy_connection(conn), "Ending connection"); - return 0; -} diff --git a/examples/unix/platform_utils.c b/examples/unix/platform_utils.c deleted file mode 100644 index 859344818..000000000 --- a/examples/unix/platform_utils.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -/* For usleep */ -#define _BSD_SOURCE - -#include - -#include -#include - -uint64_t now_microseconds(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec; -} - -void microsleep(int usec) -{ - usleep(usec); -} diff --git a/examples/utils.c b/examples/utils.c deleted file mode 100644 index 5adbc2ce3..000000000 --- a/examples/utils.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include "utils.h" - -void die_on_error(int x, char const *context) { - if (x < 0) { - char *errstr = amqp_error_string(-x); - fprintf(stderr, "%s: %s\n", context, errstr); - free(errstr); - exit(1); - } -} - -void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) { - switch (x.reply_type) { - case AMQP_RESPONSE_NORMAL: - return; - - case AMQP_RESPONSE_NONE: - fprintf(stderr, "%s: missing RPC reply type!\n", context); - break; - - case AMQP_RESPONSE_LIBRARY_EXCEPTION: - fprintf(stderr, "%s: %s\n", context, amqp_error_string(x.library_error)); - break; - - case AMQP_RESPONSE_SERVER_EXCEPTION: - switch (x.reply.id) { - case AMQP_CONNECTION_CLOSE_METHOD: { - amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded; - fprintf(stderr, "%s: server connection error %d, message: %.*s\n", - context, - m->reply_code, - (int) m->reply_text.len, (char *) m->reply_text.bytes); - break; - } - case AMQP_CHANNEL_CLOSE_METHOD: { - amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded; - fprintf(stderr, "%s: server channel error %d, message: %.*s\n", - context, - m->reply_code, - (int) m->reply_text.len, (char *) m->reply_text.bytes); - break; - } - default: - fprintf(stderr, "%s: unknown server error, method id 0x%08X\n", context, x.reply.id); - break; - } - break; - } - - exit(1); -} - -static void dump_row(long count, int numinrow, int *chs) { - int i; - - printf("%08lX:", count - numinrow); - - if (numinrow > 0) { - for (i = 0; i < numinrow; i++) { - if (i == 8) - printf(" :"); - printf(" %02X", chs[i]); - } - for (i = numinrow; i < 16; i++) { - if (i == 8) - printf(" :"); - printf(" "); - } - printf(" "); - for (i = 0; i < numinrow; i++) { - if (isprint(chs[i])) - printf("%c", chs[i]); - else - printf("."); - } - } - printf("\n"); -} - -static int rows_eq(int *a, int *b) { - int i; - - for (i=0; i<16; i++) - if (a[i] != b[i]) - return 0; - - return 1; -} - -void amqp_dump(void const *buffer, size_t len) { - unsigned char *buf = (unsigned char *) buffer; - long count = 0; - int numinrow = 0; - int chs[16]; - int oldchs[16]; - int showed_dots = 0; - int i; - - for (i = 0; i < len; i++) { - int ch = buf[i]; - - if (numinrow == 16) { - int i; - - if (rows_eq(oldchs, chs)) { - if (!showed_dots) { - showed_dots = 1; - printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n"); - } - } else { - showed_dots = 0; - dump_row(count, numinrow, chs); - } - - for (i=0; i<16; i++) - oldchs[i] = chs[i]; - - numinrow = 0; - } - - count++; - chs[numinrow++] = ch; - } - - dump_row(count, numinrow, chs); - - if (numinrow != 0) - printf("%08lX:\n", count); -} diff --git a/examples/utils.h b/examples/utils.h deleted file mode 100644 index 61a0270ca..000000000 --- a/examples/utils.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef librabbitmq_examples_utils_h -#define librabbitmq_examples_utils_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -extern void die_on_error(int x, char const *context); -extern void die_on_amqp_error(amqp_rpc_reply_t x, char const *context); - -extern void amqp_dump(void const *buffer, size_t len); - -extern uint64_t now_microseconds(void); -extern void microsleep(int usec); - -#endif diff --git a/examples/windows/platform_utils.c b/examples/windows/platform_utils.c deleted file mode 100644 index ee972384a..000000000 --- a/examples/windows/platform_utils.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include - -#include - -uint64_t now_microseconds(void) -{ - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - return (((uint64_t)ft.dwHighDateTime << 32) | (uint64_t)ft.dwLowDateTime) - / 10; -} - -void microsleep(int usec) -{ - Sleep(usec / 1000); -} diff --git a/librabbitmq/CMakeLists.txt b/librabbitmq/CMakeLists.txt deleted file mode 100644 index 80632edda..000000000 --- a/librabbitmq/CMakeLists.txt +++ /dev/null @@ -1,82 +0,0 @@ -project(librabbitmq "C") - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -# Stuff dealing with code generation -set(AMQP_CODEGEN_PY "${CMAKE_CURRENT_BINARY_DIR}/amqp_codegen.py") -set(CODEGEN_PY "${CMAKE_CURRENT_BINARY_DIR}/codegen.py") -set(AMQP_SPEC_JSON_PATH "${AMQP_CODEGEN_DIR}/amqp-rabbitmq-0.9.1.json") - -#generate amqp_framing.h/amqp_framing.c -add_custom_command( - OUTPUT ${CODEGEN_PY} - COMMAND ${CMAKE_COMMAND} ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/codegen.py ${CODEGEN_PY} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/codegen.py - VERBATIM) - -add_custom_command( - OUTPUT ${AMQP_CODEGEN_PY} - COMMAND ${CMAKE_COMMAND} ARGS -E copy ${AMQP_CODEGEN_DIR}/amqp_codegen.py ${AMQP_CODEGEN_PY} - DEPENDS ${AMQP_CODEGEN_DIR}/amqp_codegen.py ${AMQP_CODEGEN_TARGET} - VERBATIM) - -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h - COMMAND ${PYTHON_EXECUTABLE} ARGS ${CODEGEN_PY} header ${AMQP_SPEC_JSON_PATH} ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h - DEPENDS ${AMQP_SPEC_JSON_PATH} ${CODEGEN_PY} ${AMQP_CODEGEN_PY} - VERBATIM) - -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.c - COMMAND ${PYTHON_EXECUTABLE} ARGS ${CODEGEN_PY} body ${AMQP_SPEC_JSON_PATH} ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.c - DEPENDS ${AMQP_SPEC_JSON_PATH} ${CODEGEN_PY} ${AMQP_CODEGEN_PY} - VERBATIM) - - -SET(CONFIG_CONTENTS "#define VERSION \"0.0.1\" -#ifndef __cplusplus -# define inline ${C_INLINE} -#endif // __cplusplus -") - -#prepare config.h -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h" ${CONFIG_CONTENTS}) - -if(WIN32) - set(SOCKET_IMPL "windows") -else(WIN32) - set(SOCKET_IMPL "unix") -endif(WIN32) - -if(MSVC) - set(MSINTTYPES_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../msinttypes") -endif(MSVC) - -include_directories(${SOCKET_IMPL} ${MSINTTYPES_INCLUDE}) -add_definitions(-DBUILDING_LIBRABBITMQ) - -set(RABBITMQ_SOURCES - ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h - ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.c - amqp_api.c amqp.h - amqp_connection.c amqp_mem.c amqp_private.h amqp_socket.c amqp_table.c - amqp_url.c - ${SOCKET_IMPL}/socket.h ${SOCKET_IMPL}/socket.c -) - -add_library(rabbitmq SHARED ${RABBITMQ_SOURCES}) - -if(WIN32) - target_link_libraries(rabbitmq ws2_32) -endif(WIN32) - -install(TARGETS rabbitmq - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - PUBLIC_HEADER DESTINATION include) - -install(FILES amqp.h ${CMAKE_CURRENT_BINARY_DIR}/amqp_framing.h - DESTINATION include) - - diff --git a/librabbitmq/Makefile.am b/librabbitmq/Makefile.am deleted file mode 100644 index f5908c3d7..000000000 --- a/librabbitmq/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -lib_LTLIBRARIES = librabbitmq.la - -AM_CFLAGS = -I$(srcdir)/$(PLATFORM_DIR) -DBUILDING_LIBRABBITMQ - -if GCC -# Because we want to build under Microsoft's C compiler (for which -# there is apparently no demand for C99 support), it's a good idea -# to have gcc tell us when we stray from the old standard. -AM_CFLAGS += -ansi -pedantic -endif - -if USE_MSINTTYPES -AM_CFLAGS += -I$(top_srcdir)/msinttypes -endif - -librabbitmq_la_SOURCES = amqp_mem.c amqp_table.c amqp_connection.c amqp_socket.c amqp_api.c amqp_url.c $(PLATFORM_DIR)/socket.c -librabbitmq_la_LDFLAGS = -no-undefined -librabbitmq_la_LIBADD = $(EXTRA_LIBS) -nodist_librabbitmq_la_SOURCES = amqp_framing.c -include_HEADERS = amqp_framing.h amqp.h -noinst_HEADERS = amqp_private.h $(PLATFORM_DIR)/socket.h -BUILT_SOURCES = amqp_framing.h amqp_framing.c -CLEANFILES = amqp_framing.h amqp_framing.c -EXTRA_DIST = \ - codegen.py \ - unix/socket.c unix/socket.h \ - windows/socket.c windows/socket.h - -CODEGEN_PY=$(srcdir)/codegen.py - -amqp_framing.h: $(top_srcdir)/$(AMQP_SPEC_JSON_PATH) $(CODEGEN_PY) - PYTHONPATH=$(top_srcdir)/$(AMQP_CODEGEN_DIR) $(PYTHON) $(CODEGEN_PY) header $< $@ - -amqp_framing.c: $(top_srcdir)/$(AMQP_SPEC_JSON_PATH) $(CODEGEN_PY) - PYTHONPATH=$(top_srcdir)/$(AMQP_CODEGEN_DIR) $(PYTHON) $(CODEGEN_PY) body $< $@ diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h deleted file mode 100644 index e4e97eea7..000000000 --- a/librabbitmq/amqp.h +++ /dev/null @@ -1,410 +0,0 @@ -#ifndef librabbitmq_amqp_h -#define librabbitmq_amqp_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef _WIN32 -#ifdef BUILDING_LIBRABBITMQ -#define RABBITMQ_EXPORT extern __declspec(dllexport) -#else -#define RABBITMQ_EXPORT extern __declspec(dllimport) -#endif -#else -#define RABBITMQ_EXPORT extern -#endif - -typedef int amqp_boolean_t; -typedef uint32_t amqp_method_number_t; -typedef uint32_t amqp_flags_t; -typedef uint16_t amqp_channel_t; - -typedef struct amqp_bytes_t_ { - size_t len; - void *bytes; -} amqp_bytes_t; - -typedef struct amqp_decimal_t_ { - uint8_t decimals; - uint32_t value; -} amqp_decimal_t; - -typedef struct amqp_table_t_ { - int num_entries; - struct amqp_table_entry_t_ *entries; -} amqp_table_t; - -typedef struct amqp_array_t_ { - int num_entries; - struct amqp_field_value_t_ *entries; -} amqp_array_t; - -/* - 0-9 0-9-1 Qpid/Rabbit Type Remarks ---------------------------------------------------------------------------- - t t Boolean - b b Signed 8-bit - B Unsigned 8-bit - U s Signed 16-bit (A1) - u Unsigned 16-bit - I I I Signed 32-bit - i Unsigned 32-bit - L l Signed 64-bit (B) - l Unsigned 64-bit - f f 32-bit float - d d 64-bit float - D D D Decimal - s Short string (A2) - S S S Long string - A Nested Array - T T T Timestamp (u64) - F F F Nested Table - V V V Void - x Byte array - -Remarks: - - A1, A2: Notice how the types **CONFLICT** here. In Qpid and Rabbit, - 's' means a signed 16-bit integer; in 0-9-1, it means a - short string. - - B: Notice how the signednesses **CONFLICT** here. In Qpid and Rabbit, - 'l' means a signed 64-bit integer; in 0-9-1, it means an unsigned - 64-bit integer. - -I'm going with the Qpid/Rabbit types, where there's a conflict, and -the 0-9-1 types otherwise. 0-8 is a subset of 0-9, which is a subset -of the other two, so this will work for both 0-8 and 0-9-1 branches of -the code. -*/ - -typedef struct amqp_field_value_t_ { - uint8_t kind; - union { - amqp_boolean_t boolean; - int8_t i8; - uint8_t u8; - int16_t i16; - uint16_t u16; - int32_t i32; - uint32_t u32; - int64_t i64; - uint64_t u64; - float f32; - double f64; - amqp_decimal_t decimal; - amqp_bytes_t bytes; - amqp_table_t table; - amqp_array_t array; - } value; -} amqp_field_value_t; - -typedef struct amqp_table_entry_t_ { - amqp_bytes_t key; - amqp_field_value_t value; -} amqp_table_entry_t; - -typedef enum { - AMQP_FIELD_KIND_BOOLEAN = 't', - AMQP_FIELD_KIND_I8 = 'b', - AMQP_FIELD_KIND_U8 = 'B', - AMQP_FIELD_KIND_I16 = 's', - AMQP_FIELD_KIND_U16 = 'u', - AMQP_FIELD_KIND_I32 = 'I', - AMQP_FIELD_KIND_U32 = 'i', - AMQP_FIELD_KIND_I64 = 'l', - AMQP_FIELD_KIND_U64 = 'L', - AMQP_FIELD_KIND_F32 = 'f', - AMQP_FIELD_KIND_F64 = 'd', - AMQP_FIELD_KIND_DECIMAL = 'D', - AMQP_FIELD_KIND_UTF8 = 'S', - AMQP_FIELD_KIND_ARRAY = 'A', - AMQP_FIELD_KIND_TIMESTAMP = 'T', - AMQP_FIELD_KIND_TABLE = 'F', - AMQP_FIELD_KIND_VOID = 'V', - AMQP_FIELD_KIND_BYTES = 'x' -} amqp_field_value_kind_t; - -typedef struct amqp_pool_blocklist_t_ { - int num_blocks; - void **blocklist; -} amqp_pool_blocklist_t; - -typedef struct amqp_pool_t_ { - size_t pagesize; - - amqp_pool_blocklist_t pages; - amqp_pool_blocklist_t large_blocks; - - int next_page; - char *alloc_block; - size_t alloc_used; -} amqp_pool_t; - -typedef struct amqp_method_t_ { - amqp_method_number_t id; - void *decoded; -} amqp_method_t; - -typedef struct amqp_frame_t_ { - uint8_t frame_type; /* 0 means no event */ - amqp_channel_t channel; - union { - amqp_method_t method; - struct { - uint16_t class_id; - uint64_t body_size; - void *decoded; - amqp_bytes_t raw; - } properties; - amqp_bytes_t body_fragment; - struct { - uint8_t transport_high; - uint8_t transport_low; - uint8_t protocol_version_major; - uint8_t protocol_version_minor; - } protocol_header; - } payload; -} amqp_frame_t; - -typedef enum amqp_response_type_enum_ { - AMQP_RESPONSE_NONE = 0, - AMQP_RESPONSE_NORMAL, - AMQP_RESPONSE_LIBRARY_EXCEPTION, - AMQP_RESPONSE_SERVER_EXCEPTION -} amqp_response_type_enum; - -typedef struct amqp_rpc_reply_t_ { - amqp_response_type_enum reply_type; - amqp_method_t reply; - int library_error; /* if AMQP_RESPONSE_LIBRARY_EXCEPTION, then 0 here means socket EOF */ -} amqp_rpc_reply_t; - -typedef enum amqp_sasl_method_enum_ { - AMQP_SASL_METHOD_PLAIN = 0 -} amqp_sasl_method_enum; - -/* Opaque struct. */ -typedef struct amqp_connection_state_t_ *amqp_connection_state_t; - -RABBITMQ_EXPORT char const *amqp_version(void); - -/* Exported empty data structures */ -RABBITMQ_EXPORT const amqp_bytes_t amqp_empty_bytes; -RABBITMQ_EXPORT const amqp_table_t amqp_empty_table; -RABBITMQ_EXPORT const amqp_array_t amqp_empty_array; - -/* Compatibility macros for the above, to avoid the need to update - code written against earlier versions of librabbitmq. */ -#define AMQP_EMPTY_BYTES amqp_empty_bytes -#define AMQP_EMPTY_TABLE amqp_empty_table -#define AMQP_EMPTY_ARRAY amqp_empty_array - -RABBITMQ_EXPORT void init_amqp_pool(amqp_pool_t *pool, size_t pagesize); -RABBITMQ_EXPORT void recycle_amqp_pool(amqp_pool_t *pool); -RABBITMQ_EXPORT void empty_amqp_pool(amqp_pool_t *pool); - -RABBITMQ_EXPORT void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount); -RABBITMQ_EXPORT void amqp_pool_alloc_bytes(amqp_pool_t *pool, - size_t amount, amqp_bytes_t *output); - -RABBITMQ_EXPORT amqp_bytes_t amqp_cstring_bytes(char const *cstr); -RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc_dup(amqp_bytes_t src); -RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc(size_t amount); -RABBITMQ_EXPORT void amqp_bytes_free(amqp_bytes_t bytes); - -RABBITMQ_EXPORT amqp_connection_state_t amqp_new_connection(void); -RABBITMQ_EXPORT int amqp_get_sockfd(amqp_connection_state_t state); -RABBITMQ_EXPORT void amqp_set_sockfd(amqp_connection_state_t state, - int sockfd); -RABBITMQ_EXPORT int amqp_tune_connection(amqp_connection_state_t state, - int channel_max, - int frame_max, - int heartbeat); -RABBITMQ_EXPORT int amqp_get_channel_max(amqp_connection_state_t state); -RABBITMQ_EXPORT int amqp_destroy_connection(amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_handle_input(amqp_connection_state_t state, - amqp_bytes_t received_data, - amqp_frame_t *decoded_frame); - -RABBITMQ_EXPORT amqp_boolean_t amqp_release_buffers_ok( - amqp_connection_state_t state); - -RABBITMQ_EXPORT void amqp_release_buffers(amqp_connection_state_t state); - -RABBITMQ_EXPORT void amqp_maybe_release_buffers(amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_send_frame(amqp_connection_state_t state, - amqp_frame_t const *frame); - -RABBITMQ_EXPORT int amqp_table_entry_cmp(void const *entry1, - void const *entry2); - -RABBITMQ_EXPORT int amqp_open_socket(char const *hostname, - int portnumber); - -RABBITMQ_EXPORT int amqp_send_header(amqp_connection_state_t state); - -RABBITMQ_EXPORT amqp_boolean_t amqp_frames_enqueued( - amqp_connection_state_t state); - -RABBITMQ_EXPORT int amqp_simple_wait_frame(amqp_connection_state_t state, - amqp_frame_t *decoded_frame); - -RABBITMQ_EXPORT int amqp_simple_wait_method(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t expected_method, - amqp_method_t *output); - -RABBITMQ_EXPORT int amqp_send_method(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t id, - void *decoded); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t *expected_reply_ids, - void *decoded_request_method); - -RABBITMQ_EXPORT void *amqp_simple_rpc_decoded(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t reply_id, - void *decoded_request_method); - -/* - * The API methods corresponding to most synchronous AMQP methods - * return a pointer to the decoded method result. Upon error, they - * return NULL, and we need some way of discovering what, if anything, - * went wrong. amqp_get_rpc_reply() returns the most recent - * amqp_rpc_reply_t instance corresponding to such an API operation - * for the given connection. - * - * Only use it for operations that do not themselves return - * amqp_rpc_reply_t; operations that do return amqp_rpc_reply_t - * generally do NOT update this per-connection-global amqp_rpc_reply_t - * instance. - */ -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_get_rpc_reply( - amqp_connection_state_t state); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, - char const *vhost, - int channel_max, - int frame_max, - int heartbeat, - amqp_sasl_method_enum sasl_method, ...); - -struct amqp_basic_properties_t_; -RABBITMQ_EXPORT int amqp_basic_publish(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t exchange, - amqp_bytes_t routing_key, - amqp_boolean_t mandatory, - amqp_boolean_t immediate, - struct amqp_basic_properties_t_ const *properties, - amqp_bytes_t body); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_channel_close( - amqp_connection_state_t state, - amqp_channel_t channel, - int code); -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_connection_close( - amqp_connection_state_t state, - int code); - -RABBITMQ_EXPORT int amqp_basic_ack(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t multiple); - -RABBITMQ_EXPORT amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t queue, - amqp_boolean_t no_ack); - -RABBITMQ_EXPORT int amqp_basic_reject(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t requeue); - -/* - * Can be used to see if there is data still in the buffer, if so - * calling amqp_simple_wait_frame will not immediately enter a - * blocking read. - * - * Possibly amqp_frames_enqueued should be used for this? - */ -RABBITMQ_EXPORT amqp_boolean_t amqp_data_in_buffer( - amqp_connection_state_t state); - -/* - * Get the error string for the given error code. - * - * The returned string resides on the heap; the caller is responsible - * for freeing it. - */ -RABBITMQ_EXPORT char *amqp_error_string(int err); - -RABBITMQ_EXPORT int amqp_decode_table(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_table_t *output, - size_t *offset); - -RABBITMQ_EXPORT int amqp_encode_table(amqp_bytes_t encoded, - amqp_table_t *input, - size_t *offset); - -struct amqp_connection_info { - char *user; - char *password; - char *host; - char *vhost; - int port; -}; - -RABBITMQ_EXPORT void amqp_default_connection_info( - struct amqp_connection_info *parsed); -RABBITMQ_EXPORT int amqp_parse_url(char *url, - struct amqp_connection_info *parsed); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c deleted file mode 100644 index 465940b28..000000000 --- a/librabbitmq/amqp_api.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" - -#include - -static const char *client_error_strings[ERROR_MAX] = { - "could not allocate memory", /* ERROR_NO_MEMORY */ - "received bad AMQP data", /* ERROR_BAD_AQMP_DATA */ - "unknown AMQP class id", /* ERROR_UNKOWN_CLASS */ - "unknown AMQP method id", /* ERROR_UNKOWN_METHOD */ - "unknown host", /* ERROR_GETHOSTBYNAME_FAILED */ - "incompatible AMQP version", /* ERROR_INCOMPATIBLE_AMQP_VERSION */ - "connection closed unexpectedly", /* ERROR_CONNECTION_CLOSED */ - "could not parse AMQP URL", /* ERROR_BAD_AMQP_URL */ -}; - -char *amqp_error_string(int err) -{ - const char *str; - int category = (err & ERROR_CATEGORY_MASK); - err = (err & ~ERROR_CATEGORY_MASK); - - switch (category) { - case ERROR_CATEGORY_CLIENT: - if (err < 1 || err > ERROR_MAX) - str = "(undefined librabbitmq error)"; - else - str = client_error_strings[err - 1]; - break; - - case ERROR_CATEGORY_OS: - return amqp_os_error_string(err); - - default: - str = "(undefined error category)"; - } - - return strdup(str); -} - -void amqp_abort(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fputc('\n', stderr); - abort(); -} - -const amqp_bytes_t amqp_empty_bytes = { 0, NULL }; -const amqp_table_t amqp_empty_table = { 0, NULL }; -const amqp_array_t amqp_empty_array = { 0, NULL }; - -#define RPC_REPLY(replytype) \ - (state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL \ - ? (replytype *) state->most_recent_api_result.reply.decoded \ - : NULL) - -int amqp_basic_publish(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t exchange, - amqp_bytes_t routing_key, - amqp_boolean_t mandatory, - amqp_boolean_t immediate, - amqp_basic_properties_t const *properties, - amqp_bytes_t body) -{ - amqp_frame_t f; - size_t body_offset; - size_t usable_body_payload_size = state->frame_max - (HEADER_SIZE + FOOTER_SIZE); - int res; - - amqp_basic_publish_t m; - amqp_basic_properties_t default_properties; - - m.exchange = exchange; - m.routing_key = routing_key; - m.mandatory = mandatory; - m.immediate = immediate; - - res = amqp_send_method(state, channel, AMQP_BASIC_PUBLISH_METHOD, &m); - if (res < 0) - return res; - - if (properties == NULL) { - memset(&default_properties, 0, sizeof(default_properties)); - properties = &default_properties; - } - - f.frame_type = AMQP_FRAME_HEADER; - f.channel = channel; - f.payload.properties.class_id = AMQP_BASIC_CLASS; - f.payload.properties.body_size = body.len; - f.payload.properties.decoded = (void *) properties; - - res = amqp_send_frame(state, &f); - if (res < 0) - return res; - - body_offset = 0; - while (1) { - int remaining = body.len - body_offset; - assert(remaining >= 0); - - if (remaining == 0) - break; - - f.frame_type = AMQP_FRAME_BODY; - f.channel = channel; - f.payload.body_fragment.bytes = amqp_offset(body.bytes, body_offset); - if (remaining >= usable_body_payload_size) { - f.payload.body_fragment.len = usable_body_payload_size; - } else { - f.payload.body_fragment.len = remaining; - } - - body_offset += f.payload.body_fragment.len; - res = amqp_send_frame(state, &f); - if (res < 0) - return res; - } - - return 0; -} - -amqp_rpc_reply_t amqp_channel_close(amqp_connection_state_t state, - amqp_channel_t channel, - int code) -{ - char codestr[13]; - amqp_method_number_t replies[2] = { AMQP_CHANNEL_CLOSE_OK_METHOD, 0}; - amqp_channel_close_t req; - - req.reply_code = code; - req.reply_text.bytes = codestr; - req.reply_text.len = sprintf(codestr, "%d", code); - req.class_id = 0; - req.method_id = 0; - - return amqp_simple_rpc(state, channel, AMQP_CHANNEL_CLOSE_METHOD, - replies, &req); -} - -amqp_rpc_reply_t amqp_connection_close(amqp_connection_state_t state, - int code) -{ - char codestr[13]; - amqp_method_number_t replies[2] = { AMQP_CONNECTION_CLOSE_OK_METHOD, 0}; - amqp_channel_close_t req; - - req.reply_code = code; - req.reply_text.bytes = codestr; - req.reply_text.len = sprintf(codestr, "%d", code); - req.class_id = 0; - req.method_id = 0; - - return amqp_simple_rpc(state, 0, AMQP_CONNECTION_CLOSE_METHOD, - replies, &req); -} - -int amqp_basic_ack(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t multiple) -{ - amqp_basic_ack_t m; - m.delivery_tag = delivery_tag; - m.multiple = multiple; - return amqp_send_method(state, channel, AMQP_BASIC_ACK_METHOD, &m); -} - -amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t queue, - amqp_boolean_t no_ack) -{ - amqp_method_number_t replies[] = { AMQP_BASIC_GET_OK_METHOD, - AMQP_BASIC_GET_EMPTY_METHOD, - 0 }; - amqp_basic_get_t req; - req.ticket = 0; - req.queue = queue; - req.no_ack = no_ack; - - state->most_recent_api_result = amqp_simple_rpc(state, channel, - AMQP_BASIC_GET_METHOD, - replies, &req); - return state->most_recent_api_result; -} - -int amqp_basic_reject(amqp_connection_state_t state, - amqp_channel_t channel, - uint64_t delivery_tag, - amqp_boolean_t requeue) -{ - amqp_basic_reject_t req; - req.delivery_tag = delivery_tag; - req.requeue = requeue; - return amqp_send_method(state, channel, AMQP_BASIC_REJECT_METHOD, &req); -} diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c deleted file mode 100644 index 294910ec9..000000000 --- a/librabbitmq/amqp_connection.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" - -#define INITIAL_FRAME_POOL_PAGE_SIZE 65536 -#define INITIAL_DECODING_POOL_PAGE_SIZE 131072 -#define INITIAL_INBOUND_SOCK_BUFFER_SIZE 131072 - -#define ENFORCE_STATE(statevec, statenum) \ - { \ - amqp_connection_state_t _check_state = (statevec); \ - int _wanted_state = (statenum); \ - if (_check_state->state != _wanted_state) \ - amqp_abort("Programming error: invalid AMQP connection state: expected %d, got %d", \ - _wanted_state, \ - _check_state->state); \ - } - -amqp_connection_state_t amqp_new_connection(void) { - amqp_connection_state_t state = - (amqp_connection_state_t) calloc(1, sizeof(struct amqp_connection_state_t_)); - - if (state == NULL) - return NULL; - - init_amqp_pool(&state->frame_pool, INITIAL_FRAME_POOL_PAGE_SIZE); - init_amqp_pool(&state->decoding_pool, INITIAL_DECODING_POOL_PAGE_SIZE); - - if (amqp_tune_connection(state, 0, INITIAL_FRAME_POOL_PAGE_SIZE, 0) != 0) - goto out_nomem; - - state->inbound_buffer.bytes = amqp_pool_alloc(&state->frame_pool, state->inbound_buffer.len); - if (state->inbound_buffer.bytes == NULL) - goto out_nomem; - - state->state = CONNECTION_STATE_INITIAL; - /* the server protocol version response is 8 bytes, which conveniently - is also the minimum frame size */ - state->target_size = 8; - - state->sockfd = -1; - state->sock_inbound_buffer.len = INITIAL_INBOUND_SOCK_BUFFER_SIZE; - state->sock_inbound_buffer.bytes = malloc(INITIAL_INBOUND_SOCK_BUFFER_SIZE); - if (state->sock_inbound_buffer.bytes == NULL) - goto out_nomem; - - return state; - - out_nomem: - free(state->sock_inbound_buffer.bytes); - empty_amqp_pool(&state->frame_pool); - empty_amqp_pool(&state->decoding_pool); - free(state); - return NULL; -} - -int amqp_get_sockfd(amqp_connection_state_t state) { - return state->sockfd; -} - -void amqp_set_sockfd(amqp_connection_state_t state, - int sockfd) -{ - state->sockfd = sockfd; -} - -int amqp_tune_connection(amqp_connection_state_t state, - int channel_max, - int frame_max, - int heartbeat) -{ - void *newbuf; - - ENFORCE_STATE(state, CONNECTION_STATE_IDLE); - - state->channel_max = channel_max; - state->frame_max = frame_max; - state->heartbeat = heartbeat; - - empty_amqp_pool(&state->frame_pool); - init_amqp_pool(&state->frame_pool, frame_max); - - state->inbound_buffer.len = frame_max; - state->outbound_buffer.len = frame_max; - newbuf = realloc(state->outbound_buffer.bytes, frame_max); - if (newbuf == NULL) { - amqp_destroy_connection(state); - return -ERROR_NO_MEMORY; - } - state->outbound_buffer.bytes = newbuf; - - return 0; -} - -int amqp_get_channel_max(amqp_connection_state_t state) { - return state->channel_max; -} - -int amqp_destroy_connection(amqp_connection_state_t state) { - int s = state->sockfd; - - empty_amqp_pool(&state->frame_pool); - empty_amqp_pool(&state->decoding_pool); - free(state->outbound_buffer.bytes); - free(state->sock_inbound_buffer.bytes); - free(state); - - if (s >= 0 && amqp_socket_close(s) < 0) - return -amqp_socket_error(); - else - return 0; -} - -static void return_to_idle(amqp_connection_state_t state) { - state->inbound_buffer.bytes = NULL; - state->inbound_offset = 0; - state->target_size = HEADER_SIZE; - state->state = CONNECTION_STATE_IDLE; -} - -static size_t consume_data(amqp_connection_state_t state, - amqp_bytes_t *received_data) -{ - /* how much data is available and will fit? */ - size_t bytes_consumed = state->target_size - state->inbound_offset; - if (received_data->len < bytes_consumed) - bytes_consumed = received_data->len; - - memcpy(amqp_offset(state->inbound_buffer.bytes, state->inbound_offset), - received_data->bytes, bytes_consumed); - state->inbound_offset += bytes_consumed; - received_data->bytes = amqp_offset(received_data->bytes, bytes_consumed); - received_data->len -= bytes_consumed; - - return bytes_consumed; -} - -int amqp_handle_input(amqp_connection_state_t state, - amqp_bytes_t received_data, - amqp_frame_t *decoded_frame) -{ - size_t bytes_consumed; - void *raw_frame; - - /* Returning frame_type of zero indicates either insufficient input, - or a complete, ignored frame was read. */ - decoded_frame->frame_type = 0; - - if (received_data.len == 0) - return 0; - - if (state->state == CONNECTION_STATE_IDLE) { - state->inbound_buffer.bytes = amqp_pool_alloc(&state->frame_pool, - state->inbound_buffer.len); - if (state->inbound_buffer.bytes == NULL) - /* state->inbound_buffer.len is always nonzero, because it - corresponds to frame_max, which is not permitted to be less - than AMQP_FRAME_MIN_SIZE (currently 4096 bytes). */ - return -ERROR_NO_MEMORY; - - state->state = CONNECTION_STATE_HEADER; - } - - bytes_consumed = consume_data(state, &received_data); - - /* do we have target_size data yet? if not, return with the - expectation that more will arrive */ - if (state->inbound_offset < state->target_size) - return bytes_consumed; - - raw_frame = state->inbound_buffer.bytes; - - switch (state->state) { - case CONNECTION_STATE_INITIAL: - /* check for a protocol header from the server */ - if (memcmp(raw_frame, "AMQP", 4) == 0) { - decoded_frame->frame_type = AMQP_PSEUDOFRAME_PROTOCOL_HEADER; - decoded_frame->channel = 0; - - decoded_frame->payload.protocol_header.transport_high - = amqp_d8(raw_frame, 4); - decoded_frame->payload.protocol_header.transport_low - = amqp_d8(raw_frame, 5); - decoded_frame->payload.protocol_header.protocol_version_major - = amqp_d8(raw_frame, 6); - decoded_frame->payload.protocol_header.protocol_version_minor - = amqp_d8(raw_frame, 7); - - return_to_idle(state); - return bytes_consumed; - } - - /* it's not a protocol header; fall through to process it as a - regular frame header */ - - case CONNECTION_STATE_HEADER: - /* frame length is 3 bytes in */ - state->target_size - = amqp_d32(raw_frame, 3) + HEADER_SIZE + FOOTER_SIZE; - state->state = CONNECTION_STATE_BODY; - - bytes_consumed += consume_data(state, &received_data); - - /* do we have target_size data yet? if not, return with the - expectation that more will arrive */ - if (state->inbound_offset < state->target_size) - return bytes_consumed; - - /* fall through to process body */ - - case CONNECTION_STATE_BODY: { - amqp_bytes_t encoded; - int res; - - /* Check frame end marker (footer) */ - if (amqp_d8(raw_frame, state->target_size - 1) != AMQP_FRAME_END) - return -ERROR_BAD_AMQP_DATA; - - decoded_frame->frame_type = amqp_d8(raw_frame, 0); - decoded_frame->channel = amqp_d16(raw_frame, 1); - - switch (decoded_frame->frame_type) { - case AMQP_FRAME_METHOD: - decoded_frame->payload.method.id = amqp_d32(raw_frame, HEADER_SIZE); - encoded.bytes = amqp_offset(raw_frame, HEADER_SIZE + 4); - encoded.len = state->target_size - HEADER_SIZE - 4 - FOOTER_SIZE; - - res = amqp_decode_method(decoded_frame->payload.method.id, - &state->decoding_pool, encoded, - &decoded_frame->payload.method.decoded); - if (res < 0) - return res; - - break; - - case AMQP_FRAME_HEADER: - decoded_frame->payload.properties.class_id - = amqp_d16(raw_frame, HEADER_SIZE); - /* unused 2-byte weight field goes here */ - decoded_frame->payload.properties.body_size - = amqp_d64(raw_frame, HEADER_SIZE + 4); - encoded.bytes = amqp_offset(raw_frame, HEADER_SIZE + 12); - encoded.len = state->target_size - HEADER_SIZE - 12 - FOOTER_SIZE; - decoded_frame->payload.properties.raw = encoded; - - res = amqp_decode_properties(decoded_frame->payload.properties.class_id, - &state->decoding_pool, encoded, - &decoded_frame->payload.properties.decoded); - if (res < 0) - return res; - - break; - - case AMQP_FRAME_BODY: - decoded_frame->payload.body_fragment.len - = state->target_size - HEADER_SIZE - FOOTER_SIZE; - decoded_frame->payload.body_fragment.bytes - = amqp_offset(raw_frame, HEADER_SIZE); - break; - - case AMQP_FRAME_HEARTBEAT: - break; - - default: - /* Ignore the frame */ - decoded_frame->frame_type = 0; - break; - } - - return_to_idle(state); - return bytes_consumed; - } - - default: - amqp_abort("Internal error: invalid amqp_connection_state_t->state %d", state->state); - return bytes_consumed; - } -} - -amqp_boolean_t amqp_release_buffers_ok(amqp_connection_state_t state) { - return (state->state == CONNECTION_STATE_IDLE) && (state->first_queued_frame == NULL); -} - -void amqp_release_buffers(amqp_connection_state_t state) { - ENFORCE_STATE(state, CONNECTION_STATE_IDLE); - - if (state->first_queued_frame) - amqp_abort("Programming error: attempt to amqp_release_buffers while waiting events enqueued"); - - recycle_amqp_pool(&state->frame_pool); - recycle_amqp_pool(&state->decoding_pool); -} - -void amqp_maybe_release_buffers(amqp_connection_state_t state) { - if (amqp_release_buffers_ok(state)) { - amqp_release_buffers(state); - } -} - -int amqp_send_frame(amqp_connection_state_t state, - const amqp_frame_t *frame) -{ - void *out_frame = state->outbound_buffer.bytes; - int res; - - amqp_e8(out_frame, 0, frame->frame_type); - amqp_e16(out_frame, 1, frame->channel); - - if (frame->frame_type == AMQP_FRAME_BODY) { - /* For a body frame, rather than copying data around, we use - writev to compose the frame */ - struct iovec iov[3]; - uint8_t frame_end_byte = AMQP_FRAME_END; - const amqp_bytes_t *body = &frame->payload.body_fragment; - - amqp_e32(out_frame, 3, body->len); - - iov[0].iov_base = out_frame; - iov[0].iov_len = HEADER_SIZE; - iov[1].iov_base = body->bytes; - iov[1].iov_len = body->len; - iov[2].iov_base = &frame_end_byte; - iov[2].iov_len = FOOTER_SIZE; - - res = amqp_socket_writev(state->sockfd, iov, 3); - } - else { - size_t out_frame_len; - amqp_bytes_t encoded; - - switch (frame->frame_type) { - case AMQP_FRAME_METHOD: - amqp_e32(out_frame, HEADER_SIZE, frame->payload.method.id); - - encoded.bytes = amqp_offset(out_frame, HEADER_SIZE + 4); - encoded.len = state->outbound_buffer.len - HEADER_SIZE - 4 - FOOTER_SIZE; - - res = amqp_encode_method(frame->payload.method.id, - frame->payload.method.decoded, encoded); - if (res < 0) - return res; - - out_frame_len = res + 4; - break; - - case AMQP_FRAME_HEADER: - amqp_e16(out_frame, HEADER_SIZE, frame->payload.properties.class_id); - amqp_e16(out_frame, HEADER_SIZE+2, 0); /* "weight" */ - amqp_e64(out_frame, HEADER_SIZE+4, frame->payload.properties.body_size); - - encoded.bytes = amqp_offset(out_frame, HEADER_SIZE + 12); - encoded.len = state->outbound_buffer.len - HEADER_SIZE - 12 - FOOTER_SIZE; - - res = amqp_encode_properties(frame->payload.properties.class_id, - frame->payload.properties.decoded, encoded); - if (res < 0) - return res; - - out_frame_len = res + 12; - break; - - case AMQP_FRAME_HEARTBEAT: - out_frame_len = 0; - break; - - default: - abort(); - } - - amqp_e32(out_frame, 3, out_frame_len); - amqp_e8(out_frame, out_frame_len + HEADER_SIZE, AMQP_FRAME_END); - res = send(state->sockfd, out_frame, - out_frame_len + HEADER_SIZE + FOOTER_SIZE, 0); - } - - if (res < 0) - return -amqp_socket_error(); - else - return 0; -} diff --git a/librabbitmq/amqp_mem.c b/librabbitmq/amqp_mem.c deleted file mode 100644 index 429d42378..000000000 --- a/librabbitmq/amqp_mem.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include -#include -#include - -#include "amqp.h" -#include "config.h" - -char const *amqp_version(void) { - return VERSION; /* defined in config.h */ -} - -void init_amqp_pool(amqp_pool_t *pool, size_t pagesize) { - pool->pagesize = pagesize ? pagesize : 4096; - - pool->pages.num_blocks = 0; - pool->pages.blocklist = NULL; - - pool->large_blocks.num_blocks = 0; - pool->large_blocks.blocklist = NULL; - - pool->next_page = 0; - pool->alloc_block = NULL; - pool->alloc_used = 0; -} - -static void empty_blocklist(amqp_pool_blocklist_t *x) { - int i; - - for (i = 0; i < x->num_blocks; i++) { - free(x->blocklist[i]); - } - if (x->blocklist != NULL) { - free(x->blocklist); - } - x->num_blocks = 0; - x->blocklist = NULL; -} - -void recycle_amqp_pool(amqp_pool_t *pool) { - empty_blocklist(&pool->large_blocks); - pool->next_page = 0; - pool->alloc_block = NULL; - pool->alloc_used = 0; -} - -void empty_amqp_pool(amqp_pool_t *pool) { - recycle_amqp_pool(pool); - empty_blocklist(&pool->pages); -} - -/* Returns 1 on success, 0 on failure */ -static int record_pool_block(amqp_pool_blocklist_t *x, void *block) { - size_t blocklistlength = sizeof(void *) * (x->num_blocks + 1); - - if (x->blocklist == NULL) { - x->blocklist = malloc(blocklistlength); - if (x->blocklist == NULL) - return 0; - } else { - void *newbl = realloc(x->blocklist, blocklistlength); - if (newbl == NULL) - return 0; - x->blocklist = newbl; - } - - x->blocklist[x->num_blocks] = block; - x->num_blocks++; - return 1; -} - -void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount) { - if (amount == 0) { - return NULL; - } - - amount = (amount + 7) & (~7); /* round up to nearest 8-byte boundary */ - - if (amount > pool->pagesize) { - void *result = calloc(1, amount); - if (result == NULL) { - return NULL; - } - if (!record_pool_block(&pool->large_blocks, result)) - return NULL; - return result; - } - - if (pool->alloc_block != NULL) { - assert(pool->alloc_used <= pool->pagesize); - - if (pool->alloc_used + amount <= pool->pagesize) { - void *result = pool->alloc_block + pool->alloc_used; - pool->alloc_used += amount; - return result; - } - } - - if (pool->next_page >= pool->pages.num_blocks) { - pool->alloc_block = calloc(1, pool->pagesize); - if (pool->alloc_block == NULL) { - return NULL; - } - if (!record_pool_block(&pool->pages, pool->alloc_block)) - return NULL; - pool->next_page = pool->pages.num_blocks; - } else { - pool->alloc_block = pool->pages.blocklist[pool->next_page]; - pool->next_page++; - } - - pool->alloc_used = amount; - - return pool->alloc_block; -} - -void amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output) { - output->len = amount; - output->bytes = amqp_pool_alloc(pool, amount); -} - -amqp_bytes_t amqp_cstring_bytes(char const *cstr) { - amqp_bytes_t result; - result.len = strlen(cstr); - result.bytes = (void *) cstr; - return result; -} - -amqp_bytes_t amqp_bytes_malloc_dup(amqp_bytes_t src) { - amqp_bytes_t result; - result.len = src.len; - result.bytes = malloc(src.len); - if (result.bytes != NULL) { - memcpy(result.bytes, src.bytes, src.len); - } - return result; -} - -amqp_bytes_t amqp_bytes_malloc(size_t amount) { - amqp_bytes_t result; - result.len = amount; - result.bytes = malloc(amount); /* will return NULL if it fails */ - return result; -} - -void amqp_bytes_free(amqp_bytes_t bytes) { - free(bytes.bytes); -} diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h deleted file mode 100644 index 7cfb65cd0..000000000 --- a/librabbitmq/amqp_private.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef librabbitmq_amqp_private_h -#define librabbitmq_amqp_private_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -/* Error numbering: Because of differences in error numbering on - * different platforms, we want to keep error numbers opaque for - * client code. Internally, we encode the category of an error - * (i.e. where its number comes from) in the top bits of the number - * (assuming that an int has at least 32 bits). - */ -#define ERROR_CATEGORY_MASK (1 << 29) - -#define ERROR_CATEGORY_CLIENT (0 << 29) /* librabbitmq error codes */ -#define ERROR_CATEGORY_OS (1 << 29) /* OS-specific error codes */ - -/* librabbitmq error codes */ -#define ERROR_NO_MEMORY 1 -#define ERROR_BAD_AMQP_DATA 2 -#define ERROR_UNKNOWN_CLASS 3 -#define ERROR_UNKNOWN_METHOD 4 -#define ERROR_GETHOSTBYNAME_FAILED 5 -#define ERROR_INCOMPATIBLE_AMQP_VERSION 6 -#define ERROR_CONNECTION_CLOSED 7 -#define ERROR_BAD_AMQP_URL 8 -#define ERROR_MAX 8 - -extern char *amqp_os_error_string(int err); - -#include "socket.h" - -/* - * Connection states: XXX FIX THIS - * - * - CONNECTION_STATE_INITIAL: The initial state, when we cannot be - * sure if the next thing we will get is the first AMQP frame, or a - * protocol header from the server. - * - * - CONNECTION_STATE_IDLE: The normal state between - * frames. Connections may only be reconfigured, and the - * connection's pools recycled, when in this state. Whenever we're - * in this state, the inbound_buffer's bytes pointer must be NULL; - * any other state, and it must point to a block of memory allocated - * from the frame_pool. - * - * - CONNECTION_STATE_HEADER: Some bytes of an incoming frame have - * been seen, but not a complete frame header's worth. - * - * - CONNECTION_STATE_BODY: A complete frame header has been seen, but - * the frame is not yet complete. When it is completed, it will be - * returned, and the connection will return to IDLE state. - * - */ -typedef enum amqp_connection_state_enum_ { - CONNECTION_STATE_IDLE = 0, - CONNECTION_STATE_INITIAL, - CONNECTION_STATE_HEADER, - CONNECTION_STATE_BODY -} amqp_connection_state_enum; - -/* 7 bytes up front, then payload, then 1 byte footer */ -#define HEADER_SIZE 7 -#define FOOTER_SIZE 1 - -#define AMQP_PSEUDOFRAME_PROTOCOL_HEADER 'A' - -typedef struct amqp_link_t_ { - struct amqp_link_t_ *next; - void *data; -} amqp_link_t; - -struct amqp_connection_state_t_ { - amqp_pool_t frame_pool; - amqp_pool_t decoding_pool; - - amqp_connection_state_enum state; - - int channel_max; - int frame_max; - int heartbeat; - amqp_bytes_t inbound_buffer; - - size_t inbound_offset; - size_t target_size; - - amqp_bytes_t outbound_buffer; - - int sockfd; - amqp_bytes_t sock_inbound_buffer; - size_t sock_inbound_offset; - size_t sock_inbound_limit; - - amqp_link_t *first_queued_frame; - amqp_link_t *last_queued_frame; - - amqp_rpc_reply_t most_recent_api_result; -}; - -static inline void *amqp_offset(void *data, size_t offset) -{ - return (char *)data + offset; -} - -/* This macro defines the encoding and decoding functions associated with a - simple type. */ - -#define DECLARE_CODEC_BASE_TYPE(bits, htonx, ntohx) \ - \ -static inline void amqp_e##bits(void *data, size_t offset, \ - uint##bits##_t val) \ -{ \ - /* The AMQP data might be unaligned. So we encode and then copy the \ - result into place. */ \ - uint##bits##_t res = htonx(val); \ - memcpy(amqp_offset(data, offset), &res, bits/8); \ -} \ - \ -static inline uint##bits##_t amqp_d##bits(void *data, size_t offset) \ -{ \ - /* The AMQP data might be unaligned. So we copy the source value \ - into a variable and then decode it. */ \ - uint##bits##_t val; \ - memcpy(&val, amqp_offset(data, offset), bits/8); \ - return ntohx(val); \ -} \ - \ -static inline int amqp_encode_##bits(amqp_bytes_t encoded, size_t *offset, \ - uint##bits##_t input) \ - \ -{ \ - size_t o = *offset; \ - if ((*offset = o + bits / 8) <= encoded.len) { \ - amqp_e##bits(encoded.bytes, o, input); \ - return 1; \ - } \ - else { \ - return 0; \ - } \ -} \ - \ -static inline int amqp_decode_##bits(amqp_bytes_t encoded, size_t *offset, \ - uint##bits##_t *output) \ - \ -{ \ - size_t o = *offset; \ - if ((*offset = o + bits / 8) <= encoded.len) { \ - *output = amqp_d##bits(encoded.bytes, o); \ - return 1; \ - } \ - else { \ - return 0; \ - } \ -} - -#ifndef WORDS_BIGENDIAN - -#define DECLARE_XTOXLL(func) \ -static inline uint64_t func##ll(uint64_t val) \ -{ \ - union { \ - uint64_t whole; \ - uint32_t halves[2]; \ - } u; \ - uint32_t t; \ - u.whole = val; \ - t = u.halves[0]; \ - u.halves[0] = func##l(u.halves[1]); \ - u.halves[1] = func##l(t); \ - return u.whole; \ -} - -#else - -#define DECLARE_XTOXLL(func) \ -static inline uint64_t func##ll(uint64_t val) \ -{ \ - union { \ - uint64_t whole; \ - uint32_t halves[2]; \ - } u; \ - u.whole = val; \ - u.halves[0] = func##l(u.halves[0]); \ - u.halves[1] = func##l(u.halves[1]); \ - return u.whole; \ -} - -#endif - -DECLARE_XTOXLL(hton) -DECLARE_XTOXLL(ntoh) - -DECLARE_CODEC_BASE_TYPE(8, (uint8_t), (uint8_t)) -DECLARE_CODEC_BASE_TYPE(16, htons, ntohs) -DECLARE_CODEC_BASE_TYPE(32, htonl, ntohl) -DECLARE_CODEC_BASE_TYPE(64, htonll, ntohll) - -static inline int amqp_encode_bytes(amqp_bytes_t encoded, size_t *offset, - amqp_bytes_t input) -{ - size_t o = *offset; - if ((*offset = o + input.len) <= encoded.len) { - memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len); - return 1; - } - else { - return 0; - } -} - -static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset, - amqp_bytes_t *output, size_t len) -{ - size_t o = *offset; - if ((*offset = o + len) <= encoded.len) { - output->bytes = amqp_offset(encoded.bytes, o); - output->len = len; - return 1; - } - else { - return 0; - } -} - -extern void amqp_abort(const char *fmt, ...); - -#endif diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c deleted file mode 100644 index d7c523ea7..000000000 --- a/librabbitmq/amqp_socket.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" - - -int amqp_open_socket(char const *hostname, - int portnumber) -{ - int sockfd, res; - struct sockaddr_in addr; - struct hostent *he; - int one = 1; /* used as a buffer by setsockopt below */ - - res = amqp_socket_init(); - if (res) - return res; - - he = gethostbyname(hostname); - if (he == NULL) - return -ERROR_GETHOSTBYNAME_FAILED; - - addr.sin_family = AF_INET; - addr.sin_port = htons(portnumber); - addr.sin_addr.s_addr = * (uint32_t *) he->h_addr_list[0]; - - sockfd = socket(PF_INET, SOCK_STREAM, 0); - if (sockfd == -1) - return -amqp_socket_error(); - - if (amqp_socket_setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &one, - sizeof(one)) < 0 - || connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) - { - res = -amqp_socket_error(); - amqp_socket_close(sockfd); - return res; - } - - return sockfd; -} - -int amqp_send_header(amqp_connection_state_t state) { - static const uint8_t header[8] = { 'A', 'M', 'Q', 'P', 0, - AMQP_PROTOCOL_VERSION_MAJOR, - AMQP_PROTOCOL_VERSION_MINOR, - AMQP_PROTOCOL_VERSION_REVISION }; - return send(state->sockfd, (void *)header, 8, 0); -} - -static amqp_bytes_t sasl_method_name(amqp_sasl_method_enum method) { - amqp_bytes_t res; - - switch (method) { - case AMQP_SASL_METHOD_PLAIN: - res.bytes = "PLAIN"; - res.len = 5; - break; - - default: - amqp_abort("Invalid SASL method: %d", (int) method); - } - - return res; -} - -static amqp_bytes_t sasl_response(amqp_pool_t *pool, - amqp_sasl_method_enum method, - va_list args) -{ - amqp_bytes_t response; - - switch (method) { - case AMQP_SASL_METHOD_PLAIN: { - char *username = va_arg(args, char *); - size_t username_len = strlen(username); - char *password = va_arg(args, char *); - size_t password_len = strlen(password); - char *response_buf; - - amqp_pool_alloc_bytes(pool, strlen(username) + strlen(password) + 2, &response); - if (response.bytes == NULL) - /* We never request a zero-length block, because of the +2 - above, so a NULL here really is ENOMEM. */ - return response; - - response_buf = response.bytes; - response_buf[0] = 0; - memcpy(response_buf + 1, username, username_len); - response_buf[username_len + 1] = 0; - memcpy(response_buf + username_len + 2, password, password_len); - break; - } - default: - amqp_abort("Invalid SASL method: %d", (int) method); - } - - return response; -} - -amqp_boolean_t amqp_frames_enqueued(amqp_connection_state_t state) { - return (state->first_queued_frame != NULL); -} - -/* - * Check to see if we have data in our buffer. If this returns 1, we - * will avoid an immediate blocking read in amqp_simple_wait_frame. - */ -amqp_boolean_t amqp_data_in_buffer(amqp_connection_state_t state) { - return (state->sock_inbound_offset < state->sock_inbound_limit); -} - -static int wait_frame_inner(amqp_connection_state_t state, - amqp_frame_t *decoded_frame) -{ - while (1) { - int res; - - while (amqp_data_in_buffer(state)) { - amqp_bytes_t buffer; - buffer.len = state->sock_inbound_limit - state->sock_inbound_offset; - buffer.bytes = ((char *) state->sock_inbound_buffer.bytes) + state->sock_inbound_offset; - - res = amqp_handle_input(state, buffer, decoded_frame); - if (res < 0) - return res; - - state->sock_inbound_offset += res; - - if (decoded_frame->frame_type != 0) - /* Complete frame was read. Return it. */ - return 0; - - /* Incomplete or ignored frame. Keep processing input. */ - assert(res != 0); - } - - res = recv(state->sockfd, state->sock_inbound_buffer.bytes, - state->sock_inbound_buffer.len, 0); - if (res <= 0) { - if (res == 0) - return -ERROR_CONNECTION_CLOSED; - else - return -amqp_socket_error(); - } - - state->sock_inbound_limit = res; - state->sock_inbound_offset = 0; - } -} - -int amqp_simple_wait_frame(amqp_connection_state_t state, - amqp_frame_t *decoded_frame) -{ - if (state->first_queued_frame != NULL) { - amqp_frame_t *f = (amqp_frame_t *) state->first_queued_frame->data; - state->first_queued_frame = state->first_queued_frame->next; - if (state->first_queued_frame == NULL) { - state->last_queued_frame = NULL; - } - *decoded_frame = *f; - return 0; - } else { - return wait_frame_inner(state, decoded_frame); - } -} - -int amqp_simple_wait_method(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t expected_method, - amqp_method_t *output) -{ - amqp_frame_t frame; - int res = amqp_simple_wait_frame(state, &frame); - if (res < 0) - return res; - - if (frame.channel != expected_channel) - amqp_abort("Expected 0x%08X method frame on channel %d, got frame on channel %d", - expected_method, - expected_channel, - frame.channel); - if (frame.frame_type != AMQP_FRAME_METHOD) - amqp_abort("Expected 0x%08X method frame on channel %d, got frame type %d", - expected_method, - expected_channel, - frame.frame_type); - if (frame.payload.method.id != expected_method) - amqp_abort("Expected method ID 0x%08X on channel %d, got ID 0x%08X", - expected_method, - expected_channel, - frame.payload.method.id); - *output = frame.payload.method; - return 0; -} - -int amqp_send_method(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t id, - void *decoded) -{ - amqp_frame_t frame; - - frame.frame_type = AMQP_FRAME_METHOD; - frame.channel = channel; - frame.payload.method.id = id; - frame.payload.method.decoded = decoded; - return amqp_send_frame(state, &frame); -} - -static int amqp_id_in_reply_list( amqp_method_number_t expected, amqp_method_number_t *list ) -{ - while ( *list != 0 ) { - if ( *list == expected ) return 1; - list++; - } - return 0; -} - -amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t *expected_reply_ids, - void *decoded_request_method) -{ - int status; - amqp_rpc_reply_t result; - - memset(&result, 0, sizeof(result)); - - status = amqp_send_method(state, channel, request_id, decoded_request_method); - if (status < 0) { - result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - result.library_error = -status; - return result; - } - - { - amqp_frame_t frame; - - retry: - status = wait_frame_inner(state, &frame); - if (status < 0) { - result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - result.library_error = -status; - return result; - } - - /* - * We store the frame for later processing unless it's something - * that directly affects us here, namely a method frame that is - * either - * - on the channel we want, and of the expected type, or - * - on the channel we want, and a channel.close frame, or - * - on channel zero, and a connection.close frame. - */ - if (!( (frame.frame_type == AMQP_FRAME_METHOD) && - ( ((frame.channel == channel) && - ((amqp_id_in_reply_list(frame.payload.method.id, expected_reply_ids)) || - (frame.payload.method.id == AMQP_CHANNEL_CLOSE_METHOD))) - || - ((frame.channel == 0) && - (frame.payload.method.id == AMQP_CONNECTION_CLOSE_METHOD)) ) )) - { - amqp_frame_t *frame_copy = amqp_pool_alloc(&state->decoding_pool, sizeof(amqp_frame_t)); - amqp_link_t *link = amqp_pool_alloc(&state->decoding_pool, sizeof(amqp_link_t)); - - if (frame_copy == NULL || link == NULL) { - result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - result.library_error = ERROR_NO_MEMORY; - return result; - } - - *frame_copy = frame; - - link->next = NULL; - link->data = frame_copy; - - if (state->last_queued_frame == NULL) { - state->first_queued_frame = link; - } else { - state->last_queued_frame->next = link; - } - state->last_queued_frame = link; - - goto retry; - } - - result.reply_type = (amqp_id_in_reply_list(frame.payload.method.id, expected_reply_ids)) - ? AMQP_RESPONSE_NORMAL - : AMQP_RESPONSE_SERVER_EXCEPTION; - - result.reply = frame.payload.method; - return result; - } -} - -void *amqp_simple_rpc_decoded(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_method_number_t request_id, - amqp_method_number_t reply_id, - void *decoded_request_method) -{ - amqp_method_number_t replies[2]; - - replies[0] = reply_id; - replies[1] = 0; - - state->most_recent_api_result = amqp_simple_rpc(state, channel, - request_id, replies, - decoded_request_method); - if (state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL) - return state->most_recent_api_result.reply.decoded; - else - return NULL; -} - -amqp_rpc_reply_t amqp_get_rpc_reply(amqp_connection_state_t state) -{ - return state->most_recent_api_result; -} - - -static int amqp_login_inner(amqp_connection_state_t state, - int channel_max, - int frame_max, - int heartbeat, - amqp_sasl_method_enum sasl_method, - va_list vl) -{ - int res; - amqp_method_t method; - uint32_t server_frame_max; - uint16_t server_channel_max; - uint16_t server_heartbeat; - - amqp_send_header(state); - - res = amqp_simple_wait_method(state, 0, AMQP_CONNECTION_START_METHOD, - &method); - if (res < 0) - return res; - - { - amqp_connection_start_t *s = (amqp_connection_start_t *) method.decoded; - if ((s->version_major != AMQP_PROTOCOL_VERSION_MAJOR) || - (s->version_minor != AMQP_PROTOCOL_VERSION_MINOR)) { - return -ERROR_INCOMPATIBLE_AMQP_VERSION; - } - - /* TODO: check that our chosen SASL mechanism is in the list of - acceptable mechanisms. Or even let the application choose from - the list! */ - } - - { - amqp_table_entry_t properties[2]; - amqp_connection_start_ok_t s; - amqp_bytes_t response_bytes = sasl_response(&state->decoding_pool, - sasl_method, vl); - - if (response_bytes.bytes == NULL) - return -ERROR_NO_MEMORY; - - properties[0].key = amqp_cstring_bytes("product"); - properties[0].value.kind = AMQP_FIELD_KIND_UTF8; - properties[0].value.value.bytes - = amqp_cstring_bytes("rabbitmq-c"); - - properties[1].key = amqp_cstring_bytes("information"); - properties[1].value.kind = AMQP_FIELD_KIND_UTF8; - properties[1].value.value.bytes - = amqp_cstring_bytes("See http://hg.rabbitmq.com/rabbitmq-c/"); - - s.client_properties.num_entries = 2; - s.client_properties.entries = properties; - s.mechanism = sasl_method_name(sasl_method); - s.response = response_bytes; - s.locale.bytes = "en_US"; - s.locale.len = 5; - - res = amqp_send_method(state, 0, AMQP_CONNECTION_START_OK_METHOD, &s); - if (res < 0) - return res; - } - - amqp_release_buffers(state); - - res = amqp_simple_wait_method(state, 0, AMQP_CONNECTION_TUNE_METHOD, - &method); - if (res < 0) - return res; - - { - amqp_connection_tune_t *s = (amqp_connection_tune_t *) method.decoded; - server_channel_max = s->channel_max; - server_frame_max = s->frame_max; - server_heartbeat = s->heartbeat; - } - - if (server_channel_max != 0 && server_channel_max < channel_max) - channel_max = server_channel_max; - - if (server_frame_max != 0 && server_frame_max < frame_max) - frame_max = server_frame_max; - - if (server_heartbeat != 0 && server_heartbeat < heartbeat) - heartbeat = server_heartbeat; - - res = amqp_tune_connection(state, channel_max, frame_max, heartbeat); - if (res < 0) - return res; - - { - amqp_connection_tune_ok_t s; - s.frame_max = frame_max; - s.channel_max = channel_max; - s.heartbeat = heartbeat; - - res = amqp_send_method(state, 0, AMQP_CONNECTION_TUNE_OK_METHOD, &s); - if (res < 0) - return res; - } - - amqp_release_buffers(state); - - return 0; -} - -amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, - char const *vhost, - int channel_max, - int frame_max, - int heartbeat, - amqp_sasl_method_enum sasl_method, - ...) -{ - va_list vl; - amqp_rpc_reply_t result; - int status; - - va_start(vl, sasl_method); - - status = amqp_login_inner(state, channel_max, frame_max, heartbeat, sasl_method, vl); - if (status < 0) { - result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - result.reply.id = 0; - result.reply.decoded = NULL; - result.library_error = -status; - return result; - } - - { - amqp_method_number_t replies[] = { AMQP_CONNECTION_OPEN_OK_METHOD, 0 }; - amqp_connection_open_t s; - s.virtual_host = amqp_cstring_bytes(vhost); - s.capabilities.len = 0; - s.capabilities.bytes = NULL; - s.insist = 1; - - result = amqp_simple_rpc(state, - 0, - AMQP_CONNECTION_OPEN_METHOD, - (amqp_method_number_t *) &replies, - &s); - if (result.reply_type != AMQP_RESPONSE_NORMAL) - return result; - } - amqp_maybe_release_buffers(state); - - va_end(vl); - - result.reply_type = AMQP_RESPONSE_NORMAL; - result.reply.id = 0; - result.reply.decoded = NULL; - result.library_error = 0; - return result; -} diff --git a/librabbitmq/amqp_table.c b/librabbitmq/amqp_table.c deleted file mode 100644 index 3f78a5b48..000000000 --- a/librabbitmq/amqp_table.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_private.h" - -#include - -#define INITIAL_ARRAY_SIZE 16 -#define INITIAL_TABLE_SIZE 16 - -static int amqp_decode_field_value(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_field_value_t *entry, - size_t *offset); - -static int amqp_encode_field_value(amqp_bytes_t encoded, - amqp_field_value_t *entry, - size_t *offset); - -/*---------------------------------------------------------------------------*/ - -static int amqp_decode_array(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_array_t *output, - size_t *offset) -{ - uint32_t arraysize; - int num_entries = 0; - int allocated_entries = INITIAL_ARRAY_SIZE; - amqp_field_value_t *entries; - size_t limit; - int res; - - if (!amqp_decode_32(encoded, offset, &arraysize)) - return -ERROR_BAD_AMQP_DATA; - - entries = malloc(allocated_entries * sizeof(amqp_field_value_t)); - if (entries == NULL) - return -ERROR_NO_MEMORY; - - limit = *offset + arraysize; - while (*offset < limit) { - if (num_entries >= allocated_entries) { - void *newentries; - allocated_entries = allocated_entries * 2; - newentries = realloc(entries, allocated_entries * sizeof(amqp_field_value_t)); - res = -ERROR_NO_MEMORY; - if (newentries == NULL) - goto out; - - entries = newentries; - } - - res = amqp_decode_field_value(encoded, pool, &entries[num_entries], - offset); - if (res < 0) - goto out; - - num_entries++; - } - - output->num_entries = num_entries; - output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_field_value_t)); - res = -ERROR_NO_MEMORY; - /* NULL is legitimate if we requested a zero-length block. */ - if (output->entries == NULL && num_entries > 0) - goto out; - - memcpy(output->entries, entries, num_entries * sizeof(amqp_field_value_t)); - res = 0; - - out: - free(entries); - return res; -} - -int amqp_decode_table(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_table_t *output, - size_t *offset) -{ - uint32_t tablesize; - int num_entries = 0; - amqp_table_entry_t *entries; - int allocated_entries = INITIAL_TABLE_SIZE; - size_t limit; - int res; - - if (!amqp_decode_32(encoded, offset, &tablesize)) - return -ERROR_BAD_AMQP_DATA; - - entries = malloc(allocated_entries * sizeof(amqp_table_entry_t)); - if (entries == NULL) - return -ERROR_NO_MEMORY; - - limit = *offset + tablesize; - while (*offset < limit) { - uint8_t keylen; - - res = -ERROR_BAD_AMQP_DATA; - if (!amqp_decode_8(encoded, offset, &keylen)) - goto out; - - if (num_entries >= allocated_entries) { - void *newentries; - allocated_entries = allocated_entries * 2; - newentries = realloc(entries, allocated_entries * sizeof(amqp_table_entry_t)); - res = -ERROR_NO_MEMORY; - if (newentries == NULL) - goto out; - - entries = newentries; - } - - res = -ERROR_BAD_AMQP_DATA; - if (!amqp_decode_bytes(encoded, offset, &entries[num_entries].key, keylen)) - goto out; - - res = amqp_decode_field_value(encoded, pool, &entries[num_entries].value, - offset); - if (res < 0) - goto out; - - num_entries++; - } - - output->num_entries = num_entries; - output->entries = amqp_pool_alloc(pool, num_entries * sizeof(amqp_table_entry_t)); - res = -ERROR_NO_MEMORY; - /* NULL is legitimate if we requested a zero-length block. */ - if (output->entries == NULL && num_entries > 0) - goto out; - - memcpy(output->entries, entries, num_entries * sizeof(amqp_table_entry_t)); - res = 0; - - out: - free(entries); - return res; -} - -static int amqp_decode_field_value(amqp_bytes_t encoded, - amqp_pool_t *pool, - amqp_field_value_t *entry, - size_t *offset) -{ - int res = -ERROR_BAD_AMQP_DATA; - - if (!amqp_decode_8(encoded, offset, &entry->kind)) - goto out; - -#define TRIVIAL_FIELD_DECODER(bits) if (!amqp_decode_##bits(encoded, offset, &entry->value.u##bits)) goto out; break -#define SIMPLE_FIELD_DECODER(bits, dest, how) { uint##bits##_t val; if (!amqp_decode_##bits(encoded, offset, &val)) goto out; entry->value.dest = how; } break - - switch (entry->kind) { - case AMQP_FIELD_KIND_BOOLEAN: - SIMPLE_FIELD_DECODER(8, boolean, val ? 1 : 0); - - case AMQP_FIELD_KIND_I8: - SIMPLE_FIELD_DECODER(8, i8, (int8_t)val); - case AMQP_FIELD_KIND_U8: - TRIVIAL_FIELD_DECODER(8); - - case AMQP_FIELD_KIND_I16: - SIMPLE_FIELD_DECODER(16, i16, (int16_t)val); - case AMQP_FIELD_KIND_U16: - TRIVIAL_FIELD_DECODER(16); - - case AMQP_FIELD_KIND_I32: - SIMPLE_FIELD_DECODER(32, i32, (int32_t)val); - case AMQP_FIELD_KIND_U32: - TRIVIAL_FIELD_DECODER(32); - - case AMQP_FIELD_KIND_I64: - SIMPLE_FIELD_DECODER(64, i64, (int64_t)val); - case AMQP_FIELD_KIND_U64: - TRIVIAL_FIELD_DECODER(64); - - case AMQP_FIELD_KIND_F32: - TRIVIAL_FIELD_DECODER(32); - /* and by punning, f32 magically gets the right value...! */ - - case AMQP_FIELD_KIND_F64: - TRIVIAL_FIELD_DECODER(64); - /* and by punning, f64 magically gets the right value...! */ - - case AMQP_FIELD_KIND_DECIMAL: - if (!amqp_decode_8(encoded, offset, &entry->value.decimal.decimals) - || !amqp_decode_32(encoded, offset, &entry->value.decimal.value)) - goto out; - break; - - case AMQP_FIELD_KIND_UTF8: - /* AMQP_FIELD_KIND_UTF8 and AMQP_FIELD_KIND_BYTES have the - same implementation, but different interpretations. */ - /* fall through */ - case AMQP_FIELD_KIND_BYTES: { - uint32_t len; - if (!amqp_decode_32(encoded, offset, &len) - || !amqp_decode_bytes(encoded, offset, &entry->value.bytes, len)) - goto out; - break; - } - - case AMQP_FIELD_KIND_ARRAY: - res = amqp_decode_array(encoded, pool, &(entry->value.array), offset); - goto out; - - case AMQP_FIELD_KIND_TIMESTAMP: - TRIVIAL_FIELD_DECODER(64); - - case AMQP_FIELD_KIND_TABLE: - res = amqp_decode_table(encoded, pool, &(entry->value.table), offset); - goto out; - - case AMQP_FIELD_KIND_VOID: - break; - - default: - goto out; - } - - res = 0; - - out: - return res; -} - -/*---------------------------------------------------------------------------*/ - -static int amqp_encode_array(amqp_bytes_t encoded, - amqp_array_t *input, - size_t *offset) -{ - size_t start = *offset; - int i, res; - - *offset += 4; /* size of the array gets filled in later on */ - - for (i = 0; i < input->num_entries; i++) { - res = amqp_encode_field_value(encoded, &input->entries[i], offset); - if (res < 0) - goto out; - } - - if (amqp_encode_32(encoded, &start, *offset - start - 4)) - res = 0; - else - res = -ERROR_BAD_AMQP_DATA; - - out: - return res; -} - -int amqp_encode_table(amqp_bytes_t encoded, - amqp_table_t *input, - size_t *offset) -{ - size_t start = *offset; - int i, res; - - *offset += 4; /* size of the table gets filled in later on */ - - for (i = 0; i < input->num_entries; i++) { - res = amqp_encode_8(encoded, offset, input->entries[i].key.len); - if (res < 0) - goto out; - - res = amqp_encode_bytes(encoded, offset, input->entries[i].key); - if (res < 0) - goto out; - - res = amqp_encode_field_value(encoded, &input->entries[i].value, offset); - if (res < 0) - goto out; - } - - if (amqp_encode_32(encoded, &start, *offset - start - 4)) - res = 0; - else - res = -ERROR_BAD_AMQP_DATA; - - out: - return res; -} - -static int amqp_encode_field_value(amqp_bytes_t encoded, - amqp_field_value_t *entry, - size_t *offset) -{ - int res = -ERROR_BAD_AMQP_DATA; - - if (!amqp_encode_8(encoded, offset, entry->kind)) - goto out; - -#define FIELD_ENCODER(bits, val) if (!amqp_encode_##bits(encoded, offset, val)) goto out; break - - switch (entry->kind) { - case AMQP_FIELD_KIND_BOOLEAN: - FIELD_ENCODER(8, entry->value.boolean ? 1 : 0); - - case AMQP_FIELD_KIND_I8: - FIELD_ENCODER(8, entry->value.i8); - case AMQP_FIELD_KIND_U8: - FIELD_ENCODER(8, entry->value.u8); - - case AMQP_FIELD_KIND_I16: - FIELD_ENCODER(16, entry->value.i16); - case AMQP_FIELD_KIND_U16: - FIELD_ENCODER(16, entry->value.u16); - - case AMQP_FIELD_KIND_I32: - FIELD_ENCODER(32, entry->value.i32); - case AMQP_FIELD_KIND_U32: - FIELD_ENCODER(32, entry->value.u32); - - case AMQP_FIELD_KIND_I64: - FIELD_ENCODER(64, entry->value.i64); - case AMQP_FIELD_KIND_U64: - FIELD_ENCODER(64, entry->value.u64); - - case AMQP_FIELD_KIND_F32: - /* by punning, u32 magically gets the right value...! */ - FIELD_ENCODER(32, entry->value.u32); - - case AMQP_FIELD_KIND_F64: - /* by punning, u64 magically gets the right value...! */ - FIELD_ENCODER(64, entry->value.u64); - - case AMQP_FIELD_KIND_DECIMAL: - if (!amqp_encode_8(encoded, offset, entry->value.decimal.decimals) - || !amqp_encode_32(encoded, offset, entry->value.decimal.value)) - goto out; - break; - - case AMQP_FIELD_KIND_UTF8: - /* AMQP_FIELD_KIND_UTF8 and AMQP_FIELD_KIND_BYTES have the - same implementation, but different interpretations. */ - /* fall through */ - case AMQP_FIELD_KIND_BYTES: - if (!amqp_encode_32(encoded, offset, entry->value.bytes.len) - || !amqp_encode_bytes(encoded, offset, entry->value.bytes)) - goto out; - break; - - case AMQP_FIELD_KIND_ARRAY: - res = amqp_encode_array(encoded, &entry->value.array, offset); - goto out; - - case AMQP_FIELD_KIND_TIMESTAMP: - FIELD_ENCODER(64, entry->value.u64); - - case AMQP_FIELD_KIND_TABLE: - res = amqp_encode_table(encoded, &entry->value.table, offset); - goto out; - - case AMQP_FIELD_KIND_VOID: - break; - - default: - abort(); - } - - res = 0; - - out: - return res; -} - -/*---------------------------------------------------------------------------*/ - -int amqp_table_entry_cmp(void const *entry1, void const *entry2) { - amqp_table_entry_t const *p1 = (amqp_table_entry_t const *) entry1; - amqp_table_entry_t const *p2 = (amqp_table_entry_t const *) entry2; - - int d; - int minlen; - - minlen = p1->key.len; - if (p2->key.len < minlen) minlen = p2->key.len; - - d = memcmp(p1->key.bytes, p2->key.bytes, minlen); - if (d != 0) { - return d; - } - - return p1->key.len - p2->key.len; -} diff --git a/librabbitmq/amqp_url.c b/librabbitmq/amqp_url.c deleted file mode 100644 index 476d5dcab..000000000 --- a/librabbitmq/amqp_url.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" - -void amqp_default_connection_info(struct amqp_connection_info *ci) -{ - /* Apply defaults */ - ci->user = "guest"; - ci->password = "guest"; - ci->host = "localhost"; - ci->port = 5672; - ci->vhost = "/"; -} - -/* Scan for the next delimiter, handling percent-encodings on the way. */ -static char find_delim(char **pp, int colon_and_at_sign_are_delims) -{ - char *from = *pp; - char *to = from; - - for (;;) { - char ch = *from++; - - switch (ch) { - case ':': - case '@': - if (!colon_and_at_sign_are_delims) { - *to++ = ch; - break; - } - - /* fall through */ - case 0: - case '/': - case '?': - case '#': - case '[': - case ']': - *to = 0; - *pp = from; - return ch; - - case '%': { - unsigned int val; - int chars; - int res = sscanf(from, "%2x%n", &val, &chars); - - if (res == EOF || res < 1 || chars != 2) - /* Return a surprising delimiter to - force an error. */ - return '%'; - - *to++ = val; - from += 2; - break; - } - - default: - *to++ = ch; - break; - } - } -} - -/* Parse an AMQP URL into its component parts. */ -int amqp_parse_url(char *url, struct amqp_connection_info *parsed) -{ - int res = -ERROR_BAD_AMQP_URL; - char delim; - char *start; - char *host; - char *port = NULL; - - /* check the prefix */ - if (strncmp(url, "amqp://", 7)) - goto out; - - host = start = url += 7; - delim = find_delim(&url, 1); - - if (delim == ':') { - /* The colon could be introducing the port or the - password part of the userinfo. We don't know yet, - so stash the preceding component. */ - port = start = url; - delim = find_delim(&url, 1); - } - - if (delim == '@') { - /* What might have been the host and port were in fact - the username and password */ - parsed->user = host; - if (port) - parsed->password = port; - - port = NULL; - host = start = url; - delim = find_delim(&url, 1); - } - - if (delim == '[') { - /* IPv6 address. The bracket should be the first - character in the host. */ - if (host != start || *host != 0) - goto out; - - start = url; - delim = find_delim(&url, 0); - - if (delim != ']') - goto out; - - parsed->host = start; - start = url; - delim = find_delim(&url, 1); - - /* Closing bracket should be the last character in the - host. */ - if (*start != 0) - goto out; - } - else { - /* If we haven't seen the host yet, this is it. */ - if (*host != 0) - parsed->host = host; - } - - if (delim == ':') { - port = start = url; - delim = find_delim(&url, 1); - } - - if (port) { - char *end; - long portnum = strtol(port, &end, 10); - - if (port == end || *end != 0 || portnum < 0 || portnum > 65535) - goto out; - - parsed->port = portnum; - } - - if (delim == '/') { - start = url; - delim = find_delim(&url, 1); - - if (delim != 0) - goto out; - - parsed->vhost = start; - res = 0; - } - else if (delim == 0) { - res = 0; - } - - /* Any other delimiter is bad, and we will return - ERROR_BAD_AMQP_URL. */ - - out: - return res; -} diff --git a/librabbitmq/codegen.py b/librabbitmq/codegen.py deleted file mode 100644 index b29c68d27..000000000 --- a/librabbitmq/codegen.py +++ /dev/null @@ -1,642 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MIT -# -# Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. -# All Rights Reserved. -# -# Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 -# VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, copy, -# modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# ***** END LICENSE BLOCK ***** - -from __future__ import nested_scopes - -from amqp_codegen import * -import string -import re - - -class Emitter(object): - """An object the trivially emits generated code lines. - - This largely exists to be wrapped by more sophisticated emitter - classes. - """ - - def __init__(self, prefix): - self.prefix = prefix - - def emit(self, line): - """Emit a line of generated code.""" - print self.prefix + line - - -class BitDecoder(object): - """An emitter object that keeps track of the state involved in - decoding the AMQP bit type.""" - - def __init__(self, emitter): - self.emitter = emitter - self.bit = 0 - - def emit(self, line): - self.bit = 0 - self.emitter.emit(line) - - def decode_bit(self, lvalue): - """Generate code to decode a value of the AMQP bit type into - the given lvalue.""" - if self.bit == 0: - self.emitter.emit("if (!amqp_decode_8(encoded, &offset, &bit_buffer)) return -ERROR_BAD_AMQP_DATA;") - - self.emitter.emit("%s = (bit_buffer & (1 << %d)) ? 1 : 0;" - % (lvalue, self.bit)) - self.bit += 1 - if self.bit == 8: - self.bit = 0 - - -class BitEncoder(object): - """An emitter object that keeps track of the state involved in - encoding the AMQP bit type.""" - - def __init__(self, emitter): - self.emitter = emitter - self.bit = 0 - - def flush(self): - """Flush the state associated with AMQP bit types.""" - if self.bit: - self.emitter.emit("if (!amqp_encode_8(encoded, &offset, bit_buffer)) return -ERROR_BAD_AMQP_DATA;") - self.bit = 0 - - def emit(self, line): - self.flush() - self.emitter.emit(line) - - def encode_bit(self, value): - """Generate code to encode a value of the AMQP bit type from - the given value.""" - if self.bit == 0: - self.emitter.emit("bit_buffer = 0;") - - self.emitter.emit("if (%s) bit_buffer |= (1 << %d);" - % (value, self.bit)) - self.bit += 1 - if self.bit == 8: - self.flush() - - -class SimpleType(object): - """A AMQP type that corresponds to a simple scalar C value of a - certain width.""" - - def __init__(self, bits): - self.bits = bits - self.ctype = "uint%d_t" % (bits,) - - def decode(self, emitter, lvalue): - emitter.emit("if (!amqp_decode_%d(encoded, &offset, &%s)) return -ERROR_BAD_AMQP_DATA;" % (self.bits, lvalue)) - - def encode(self, emitter, value): - emitter.emit("if (!amqp_encode_%d(encoded, &offset, %s)) return -ERROR_BAD_AMQP_DATA;" % (self.bits, value)) - - def literal(self, value): - return value - -class StrType(object): - """The AMQP shortstr or longstr types.""" - - def __init__(self, lenbits): - self.lenbits = lenbits - self.ctype = "amqp_bytes_t" - - def decode(self, emitter, lvalue): - emitter.emit("{") - emitter.emit(" uint%d_t len;" % (self.lenbits,)) - emitter.emit(" if (!amqp_decode_%d(encoded, &offset, &len)" % (self.lenbits,)) - emitter.emit(" || !amqp_decode_bytes(encoded, &offset, &%s, len))" % (lvalue,)) - emitter.emit(" return -ERROR_BAD_AMQP_DATA;") - emitter.emit("}") - - def encode(self, emitter, value): - emitter.emit("if (!amqp_encode_%d(encoded, &offset, %s.len)" % (self.lenbits, value)) - emitter.emit(" || !amqp_encode_bytes(encoded, &offset, %s))" % (value,)) - emitter.emit(" return -ERROR_BAD_AMQP_DATA;") - - def literal(self, value): - if value != '': - raise NotImplementedError() - - return "amqp_empty_bytes" - -class BitType(object): - """The AMQP bit type.""" - - def __init__(self): - self.ctype = "amqp_boolean_t" - - def decode(self, emitter, lvalue): - emitter.decode_bit(lvalue) - - def encode(self, emitter, value): - emitter.encode_bit(value) - - def literal(self, value): - return {True: 1, False: 0}[value] - -class TableType(object): - """The AMQP table type.""" - - def __init__(self): - self.ctype = "amqp_table_t" - - def decode(self, emitter, lvalue): - emitter.emit("{") - emitter.emit(" int res = amqp_decode_table(encoded, pool, &(%s), &offset);" % (lvalue,)) - emitter.emit(" if (res < 0) return res;") - emitter.emit("}") - - def encode(self, emitter, value): - emitter.emit("{") - emitter.emit(" int res = amqp_encode_table(encoded, &(%s), &offset);" % (value,)) - emitter.emit(" if (res < 0) return res;") - emitter.emit("}") - - def literal(self, value): - raise NotImplementedError() - -types = { - 'octet': SimpleType(8), - 'short': SimpleType(16), - 'long': SimpleType(32), - 'longlong': SimpleType(64), - 'shortstr': StrType(8), - 'longstr': StrType(32), - 'bit': BitType(), - 'table': TableType(), - 'timestamp': SimpleType(64), -} - -def typeFor(spec, f): - """Get a representation of the AMQP type of a field.""" - return types[spec.resolveDomain(f.domain)] - -def c_ize(s): - s = s.replace('-', '_') - s = s.replace(' ', '_') - return s - -# When generating API functions corresponding to synchronous methods, -# we need some information that isn't in the protocol def: Some -# methods should not be exposed, indicated here by a False value. -# Some methods should be exposed but certain fields should not be -# exposed as parameters. -apiMethodInfo = { - "amqp_connection_start": False, # application code should not use this - "amqp_connection_secure": False, # application code should not use this - "amqp_connection_tune": False, # application code should not use this - "amqp_connection_open": False, # application code should not use this - "amqp_connection_close": False, # needs special handling - "amqp_channel_open": ["out_of_band"], - "amqp_channel_close": False, # needs special handling - "amqp_access_request": False, # huh? - "amqp_exchange_declare": ["auto_delete", "internal"], - "amqp_basic_get": False, # get-ok has content -} - -# When generating API functions corresponding to synchronous methods, -# some fields should be suppressed everywhere. This dict names those -# fields, and the fixed values to use for them. -apiMethodsSuppressArgs = {"ticket": 0, "nowait": False} - -AmqpMethod.defName = lambda m: cConstantName(c_ize(m.klass.name) + '_' + c_ize(m.name) + "_method") -AmqpMethod.fullName = lambda m: "amqp_%s_%s" % (c_ize(m.klass.name), c_ize(m.name)) -AmqpMethod.structName = lambda m: m.fullName() + "_t" - -AmqpClass.structName = lambda c: "amqp_" + c_ize(c.name) + "_properties_t" - -def methodApiPrototype(m): - fn = m.fullName() - info = apiMethodInfo.get(fn, []) - - args = [] - for f in m.arguments: - n = c_ize(f.name) - if n in apiMethodsSuppressArgs or n in info: - continue - - args.append(", ") - args.append(typeFor(m.klass.spec, f).ctype) - args.append(" ") - args.append(n) - - return "%s_ok_t *%s(amqp_connection_state_t state, amqp_channel_t channel%s)" % (fn, fn, ''.join(args)) - -AmqpMethod.apiPrototype = methodApiPrototype - -def cConstantName(s): - return 'AMQP_' + '_'.join(re.split('[- ]', s.upper())) - -def cFlagName(c, f): - return cConstantName(c.name + '_' + f.name) + '_FLAG' - -def genErl(spec): - def fieldTempList(fields): - return '[' + ', '.join(['F' + str(f.index) for f in fields]) + ']' - - def fieldMapList(fields): - return ', '.join([c_ize(f.name) + " = F" + str(f.index) for f in fields]) - - def genLookupMethodName(m): - print ' case %s: return "%s";' % (m.defName(), m.defName()) - - def genDecodeMethodFields(m): - print " case %s: {" % (m.defName(),) - if m.arguments: - print " %s *m = (%s *) amqp_pool_alloc(pool, sizeof(%s));" % \ - (m.structName(), m.structName(), m.structName()) - print " if (m == NULL) { return -ERROR_NO_MEMORY; }" - else: - print " %s *m = NULL; /* no fields */" % (m.structName(),) - - emitter = BitDecoder(Emitter(" ")) - for f in m.arguments: - typeFor(spec, f).decode(emitter, "m->"+c_ize(f.name)) - - print " *decoded = m;" - print " return 0;" - print " }" - - def genDecodeProperties(c): - print " case %d: {" % (c.index,) - print " %s *p = (%s *) amqp_pool_alloc(pool, sizeof(%s));" % \ - (c.structName(), c.structName(), c.structName()) - print " if (p == NULL) { return -ERROR_NO_MEMORY; }" - print " p->_flags = flags;" - - emitter = Emitter(" ") - for f in c.fields: - emitter.emit("if (flags & %s) {" % (cFlagName(c, f),)) - typeFor(spec, f).decode(emitter, "p->"+c_ize(f.name)) - emitter.emit("}") - - print " *decoded = p;" - print " return 0;" - print " }" - - def genEncodeMethodFields(m): - print " case %s: {" % (m.defName(),) - if m.arguments: - print " %s *m = (%s *) decoded;" % (m.structName(), m.structName()) - - emitter = BitEncoder(Emitter(" ")) - for f in m.arguments: - typeFor(spec, f).encode(emitter, "m->"+c_ize(f.name)) - emitter.flush() - - print " return offset;" - print " }" - - def genEncodeProperties(c): - print " case %d: {" % (c.index,) - if c.fields: - print " %s *p = (%s *) decoded;" % (c.structName(), c.structName()) - - emitter = Emitter(" ") - for f in c.fields: - emitter.emit(" if (flags & %s) {" % (cFlagName(c, f),)) - typeFor(spec, f).encode(emitter, "p->"+c_ize(f.name)) - emitter.emit("}") - - print " return offset;" - print " }" - - methods = spec.allMethods() - - print """/* Autogenerated code. Do not edit. - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_framing.h" -#include "amqp_private.h" -#include "socket.h" -""" - - print """ -char const *amqp_constant_name(int constantNumber) { - switch (constantNumber) {""" - for (c,v,cls) in spec.constants: - print " case %s: return \"%s\";" % (cConstantName(c), cConstantName(c)) - print """ default: return "(unknown)"; - } -}""" - - print """ -amqp_boolean_t amqp_constant_is_hard_error(int constantNumber) { - switch (constantNumber) {""" - for (c,v,cls) in spec.constants: - if cls == 'hard-error': - print " case %s: return 1;" % (cConstantName(c),) - print """ default: return 0; - } -}""" - - print """ -char const *amqp_method_name(amqp_method_number_t methodNumber) { - switch (methodNumber) {""" - for m in methods: genLookupMethodName(m) - print """ default: return NULL; - } -}""" - - print """ -amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber) { - switch (methodNumber) {""" - for m in methods: - if m.hasContent: - print ' case %s: return 1;' % (m.defName()) - print """ default: return 0; - } -}""" - - print """ -int amqp_decode_method(amqp_method_number_t methodNumber, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded) -{ - size_t offset = 0; - uint8_t bit_buffer; - - switch (methodNumber) {""" - for m in methods: genDecodeMethodFields(m) - print """ default: return -ERROR_UNKNOWN_METHOD; - } -}""" - - print """ -int amqp_decode_properties(uint16_t class_id, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded) -{ - size_t offset = 0; - - amqp_flags_t flags = 0; - int flagword_index = 0; - uint16_t partial_flags; - - do { - if (!amqp_decode_16(encoded, &offset, &partial_flags)) - return -ERROR_BAD_AMQP_DATA; - flags |= (partial_flags << (flagword_index * 16)); - flagword_index++; - } while (partial_flags & 1); - - switch (class_id) {""" - for c in spec.allClasses(): genDecodeProperties(c) - print """ default: return -ERROR_UNKNOWN_CLASS; - } -}""" - - print """ -int amqp_encode_method(amqp_method_number_t methodNumber, - void *decoded, - amqp_bytes_t encoded) -{ - size_t offset = 0; - uint8_t bit_buffer; - - switch (methodNumber) {""" - for m in methods: genEncodeMethodFields(m) - print """ default: return -ERROR_UNKNOWN_METHOD; - } -}""" - - print """ -int amqp_encode_properties(uint16_t class_id, - void *decoded, - amqp_bytes_t encoded) -{ - size_t offset = 0; - - /* Cheat, and get the flags out generically, relying on the - similarity of structure between classes */ - amqp_flags_t flags = * (amqp_flags_t *) decoded; /* cheating! */ - - { - /* We take a copy of flags to avoid destroying it, as it is used - in the autogenerated code below. */ - amqp_flags_t remaining_flags = flags; - do { - amqp_flags_t remainder = remaining_flags >> 16; - uint16_t partial_flags = remaining_flags & 0xFFFE; - if (remainder != 0) { partial_flags |= 1; } - if (!amqp_encode_16(encoded, &offset, partial_flags)) - return -ERROR_BAD_AMQP_DATA; - remaining_flags = remainder; - } while (remaining_flags != 0); - } - - switch (class_id) {""" - for c in spec.allClasses(): genEncodeProperties(c) - print """ default: return -ERROR_UNKNOWN_CLASS; - } -}""" - - for m in methods: - if not m.isSynchronous: - continue - - info = apiMethodInfo.get(m.fullName(), []) - if info is False: - continue - - print - print m.apiPrototype() - print "{" - print " %s req;" % (m.structName(),) - - for f in m.arguments: - n = c_ize(f.name) - - val = apiMethodsSuppressArgs.get(n) - if val is None and n in info: - val = f.defaultvalue - - if val is None: - val = n - else: - val = typeFor(spec, f).literal(val) - - - print " req.%s = %s;" % (n, val) - - reply = cConstantName(c_ize(m.klass.name) + '_' + c_ize(m.name) - + "_ok_method") - print """ - return amqp_simple_rpc_decoded(state, channel, %s, %s, &req); -} -""" % (m.defName(), reply) - -def genHrl(spec): - def fieldDeclList(fields): - if fields: - return ''.join([" %s %s;\n" % (typeFor(spec, f).ctype, - c_ize(f.name)) - for f in fields]) - else: - return " char dummy; /* Dummy field to avoid empty struct */\n" - - def propDeclList(fields): - return ''.join([" %s %s;\n" % (typeFor(spec, f).ctype, c_ize(f.name)) - for f in fields - if spec.resolveDomain(f.domain) != 'bit']) - - methods = spec.allMethods() - - print """/* Autogenerated code. Do not edit. */ -#ifndef librabbitmq_amqp_framing_h -#define librabbitmq_amqp_framing_h - -#ifdef __cplusplus -extern "C" { -#endif -""" - print "#define AMQP_PROTOCOL_VERSION_MAJOR %d" % (spec.major) - print "#define AMQP_PROTOCOL_VERSION_MINOR %d" % (spec.minor) - print "#define AMQP_PROTOCOL_VERSION_REVISION %d" % (spec.revision) - print "#define AMQP_PROTOCOL_PORT %d" % (spec.port) - - for (c,v,cls) in spec.constants: - print "#define %s %s" % (cConstantName(c), v) - print - - print """/* Function prototypes. */ - -extern char const *amqp_constant_name(int constantNumber); -extern amqp_boolean_t amqp_constant_is_hard_error(int constantNumber); -RABBITMQ_EXPORT char const *amqp_method_name(amqp_method_number_t methodNumber); -extern amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber); -extern int amqp_decode_method(amqp_method_number_t methodNumber, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded); -extern int amqp_decode_properties(uint16_t class_id, - amqp_pool_t *pool, - amqp_bytes_t encoded, - void **decoded); -extern int amqp_encode_method(amqp_method_number_t methodNumber, - void *decoded, - amqp_bytes_t encoded); -extern int amqp_encode_properties(uint16_t class_id, - void *decoded, - amqp_bytes_t encoded); -""" - - print "/* Method field records. */\n" - for m in methods: - methodid = m.klass.index << 16 | m.index - print "#define %s ((amqp_method_number_t) 0x%.08X) /* %d, %d; %d */" % \ - (m.defName(), - methodid, - m.klass.index, - m.index, - methodid) - print "typedef struct %s_ {\n%s} %s;\n" % \ - (m.structName(), fieldDeclList(m.arguments), m.structName()) - - print "/* Class property records. */" - for c in spec.allClasses(): - print "#define %s (0x%.04X) /* %d */" % \ - (cConstantName(c.name + "_class"), c.index, c.index) - index = 0 - for f in c.fields: - if index % 16 == 15: - index = index + 1 - shortnum = index / 16 - partialindex = 15 - (index % 16) - bitindex = shortnum * 16 + partialindex - print '#define %s (1 << %d)' % (cFlagName(c, f), bitindex) - index = index + 1 - print "typedef struct %s_ {\n amqp_flags_t _flags;\n%s} %s;\n" % \ - (c.structName(), - fieldDeclList(c.fields), - c.structName()) - - print "/* API functions for methods */\n" - - for m in methods: - if m.isSynchronous and apiMethodInfo.get(m.fullName()) is not False: - print "RABBITMQ_EXPORT %s;" % (m.apiPrototype(),) - - print """ -#ifdef __cplusplus -} -#endif - -#endif""" - -def generateErl(specPath): - genErl(AmqpSpec(specPath)) - -def generateHrl(specPath): - genHrl(AmqpSpec(specPath)) - -if __name__ == "__main__": - do_main(generateHrl, generateErl) diff --git a/librabbitmq/unix/socket.c b/librabbitmq/unix/socket.c deleted file mode 100644 index 5d339e6ff..000000000 --- a/librabbitmq/unix/socket.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "amqp.h" -#include "amqp_private.h" -#include "socket.h" - -int amqp_socket_socket(int domain, int type, int proto) -{ - int flags; - - int s = socket(domain, type, proto); - if (s < 0) - return s; - - /* Always enable CLOEXEC on the socket */ - flags = fcntl(s, F_GETFD); - if (flags == -1 - || fcntl(s, F_SETFD, (long)(flags | FD_CLOEXEC)) == -1) { - int e = errno; - close(s); - errno = e; - return -1; - } - - return s; -} - -char *amqp_os_error_string(int err) -{ - return strdup(strerror(err)); -} diff --git a/librabbitmq/unix/socket.h b/librabbitmq/unix/socket.h deleted file mode 100644 index af86ffbfc..000000000 --- a/librabbitmq/unix/socket.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef librabbitmq_unix_socket_h -#define librabbitmq_unix_socket_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static inline int amqp_socket_init(void) -{ - return 0; -} - -extern int amqp_socket_socket(int domain, int type, int proto); - -#define amqp_socket_setsockopt setsockopt -#define amqp_socket_close close -#define amqp_socket_writev writev - -static inline int amqp_socket_error() -{ - return errno | ERROR_CATEGORY_OS; -} - -#endif diff --git a/librabbitmq/windows/socket.c b/librabbitmq/windows/socket.c deleted file mode 100644 index faf6819ae..000000000 --- a/librabbitmq/windows/socket.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -/* See http://msdn.microsoft.com/en-us/library/ms737629%28VS.85%29.aspx */ -#define WIN32_LEAN_AND_MEAN - -#include "config.h" - -#include -#include -#include - -#include "amqp.h" -#include "amqp_private.h" -#include "socket.h" - -static int called_wsastartup; - -int amqp_socket_init(void) -{ - if (!called_wsastartup) { - WSADATA data; - int res = WSAStartup(0x0202, &data); - if (res) - return -res; - - called_wsastartup = 1; - } - - return 0; -} - -char *amqp_os_error_string(int err) -{ - char *msg, *copy; - - if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&msg, 0, NULL)) - return strdup("(error retrieving Windows error message)"); - - copy = strdup(msg); - LocalFree(msg); - return copy; -} diff --git a/librabbitmq/windows/socket.h b/librabbitmq/windows/socket.h deleted file mode 100644 index 0665b3aed..000000000 --- a/librabbitmq/windows/socket.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef librabbitmq_windows_socket_h -#define librabbitmq_windows_socket_h - -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include - -extern int amqp_socket_init(void); - -#define amqp_socket_socket socket -#define amqp_socket_close closesocket - -static inline int amqp_socket_setsockopt(int sock, int level, int optname, - const void *optval, size_t optlen) -{ - /* the winsock setsockopt function has its 4th argument as a - const char * */ - return setsockopt(sock, level, optname, (const char *)optval, optlen); -} - -/* same as WSABUF */ -struct iovec { - u_long iov_len; - void *iov_base; -}; - -static inline int amqp_socket_writev(int sock, struct iovec *iov, int nvecs) -{ - DWORD ret; - if (WSASend(sock, (LPWSABUF)iov, nvecs, &ret, 0, NULL, NULL) == 0) - return ret; - else - return -1; -} - -static inline int amqp_socket_error() -{ - return WSAGetLastError() | ERROR_CATEGORY_OS; -} - -#endif diff --git a/msinttypes/inttypes.h b/msinttypes/inttypes.h deleted file mode 100644 index 4b3828a21..000000000 --- a/msinttypes/inttypes.h +++ /dev/null @@ -1,305 +0,0 @@ -// ISO C9x compliant inttypes.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_INTTYPES_H_ // [ -#define _MSC_INTTYPES_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include "stdint.h" - -// 7.8 Format conversion of integer types - -typedef struct { - intmax_t quot; - intmax_t rem; -} imaxdiv_t; - -// 7.8.1 Macros for format specifiers - -#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 - -// The fprintf macros for signed integers are: -#define PRId8 "d" -#define PRIi8 "i" -#define PRIdLEAST8 "d" -#define PRIiLEAST8 "i" -#define PRIdFAST8 "d" -#define PRIiFAST8 "i" - -#define PRId16 "hd" -#define PRIi16 "hi" -#define PRIdLEAST16 "hd" -#define PRIiLEAST16 "hi" -#define PRIdFAST16 "hd" -#define PRIiFAST16 "hi" - -#define PRId32 "I32d" -#define PRIi32 "I32i" -#define PRIdLEAST32 "I32d" -#define PRIiLEAST32 "I32i" -#define PRIdFAST32 "I32d" -#define PRIiFAST32 "I32i" - -#define PRId64 "I64d" -#define PRIi64 "I64i" -#define PRIdLEAST64 "I64d" -#define PRIiLEAST64 "I64i" -#define PRIdFAST64 "I64d" -#define PRIiFAST64 "I64i" - -#define PRIdMAX "I64d" -#define PRIiMAX "I64i" - -#define PRIdPTR "Id" -#define PRIiPTR "Ii" - -// The fprintf macros for unsigned integers are: -#define PRIo8 "o" -#define PRIu8 "u" -#define PRIx8 "x" -#define PRIX8 "X" -#define PRIoLEAST8 "o" -#define PRIuLEAST8 "u" -#define PRIxLEAST8 "x" -#define PRIXLEAST8 "X" -#define PRIoFAST8 "o" -#define PRIuFAST8 "u" -#define PRIxFAST8 "x" -#define PRIXFAST8 "X" - -#define PRIo16 "ho" -#define PRIu16 "hu" -#define PRIx16 "hx" -#define PRIX16 "hX" -#define PRIoLEAST16 "ho" -#define PRIuLEAST16 "hu" -#define PRIxLEAST16 "hx" -#define PRIXLEAST16 "hX" -#define PRIoFAST16 "ho" -#define PRIuFAST16 "hu" -#define PRIxFAST16 "hx" -#define PRIXFAST16 "hX" - -#define PRIo32 "I32o" -#define PRIu32 "I32u" -#define PRIx32 "I32x" -#define PRIX32 "I32X" -#define PRIoLEAST32 "I32o" -#define PRIuLEAST32 "I32u" -#define PRIxLEAST32 "I32x" -#define PRIXLEAST32 "I32X" -#define PRIoFAST32 "I32o" -#define PRIuFAST32 "I32u" -#define PRIxFAST32 "I32x" -#define PRIXFAST32 "I32X" - -#define PRIo64 "I64o" -#define PRIu64 "I64u" -#define PRIx64 "I64x" -#define PRIX64 "I64X" -#define PRIoLEAST64 "I64o" -#define PRIuLEAST64 "I64u" -#define PRIxLEAST64 "I64x" -#define PRIXLEAST64 "I64X" -#define PRIoFAST64 "I64o" -#define PRIuFAST64 "I64u" -#define PRIxFAST64 "I64x" -#define PRIXFAST64 "I64X" - -#define PRIoMAX "I64o" -#define PRIuMAX "I64u" -#define PRIxMAX "I64x" -#define PRIXMAX "I64X" - -#define PRIoPTR "Io" -#define PRIuPTR "Iu" -#define PRIxPTR "Ix" -#define PRIXPTR "IX" - -// The fscanf macros for signed integers are: -#define SCNd8 "d" -#define SCNi8 "i" -#define SCNdLEAST8 "d" -#define SCNiLEAST8 "i" -#define SCNdFAST8 "d" -#define SCNiFAST8 "i" - -#define SCNd16 "hd" -#define SCNi16 "hi" -#define SCNdLEAST16 "hd" -#define SCNiLEAST16 "hi" -#define SCNdFAST16 "hd" -#define SCNiFAST16 "hi" - -#define SCNd32 "ld" -#define SCNi32 "li" -#define SCNdLEAST32 "ld" -#define SCNiLEAST32 "li" -#define SCNdFAST32 "ld" -#define SCNiFAST32 "li" - -#define SCNd64 "I64d" -#define SCNi64 "I64i" -#define SCNdLEAST64 "I64d" -#define SCNiLEAST64 "I64i" -#define SCNdFAST64 "I64d" -#define SCNiFAST64 "I64i" - -#define SCNdMAX "I64d" -#define SCNiMAX "I64i" - -#ifdef _WIN64 // [ -# define SCNdPTR "I64d" -# define SCNiPTR "I64i" -#else // _WIN64 ][ -# define SCNdPTR "ld" -# define SCNiPTR "li" -#endif // _WIN64 ] - -// The fscanf macros for unsigned integers are: -#define SCNo8 "o" -#define SCNu8 "u" -#define SCNx8 "x" -#define SCNX8 "X" -#define SCNoLEAST8 "o" -#define SCNuLEAST8 "u" -#define SCNxLEAST8 "x" -#define SCNXLEAST8 "X" -#define SCNoFAST8 "o" -#define SCNuFAST8 "u" -#define SCNxFAST8 "x" -#define SCNXFAST8 "X" - -#define SCNo16 "ho" -#define SCNu16 "hu" -#define SCNx16 "hx" -#define SCNX16 "hX" -#define SCNoLEAST16 "ho" -#define SCNuLEAST16 "hu" -#define SCNxLEAST16 "hx" -#define SCNXLEAST16 "hX" -#define SCNoFAST16 "ho" -#define SCNuFAST16 "hu" -#define SCNxFAST16 "hx" -#define SCNXFAST16 "hX" - -#define SCNo32 "lo" -#define SCNu32 "lu" -#define SCNx32 "lx" -#define SCNX32 "lX" -#define SCNoLEAST32 "lo" -#define SCNuLEAST32 "lu" -#define SCNxLEAST32 "lx" -#define SCNXLEAST32 "lX" -#define SCNoFAST32 "lo" -#define SCNuFAST32 "lu" -#define SCNxFAST32 "lx" -#define SCNXFAST32 "lX" - -#define SCNo64 "I64o" -#define SCNu64 "I64u" -#define SCNx64 "I64x" -#define SCNX64 "I64X" -#define SCNoLEAST64 "I64o" -#define SCNuLEAST64 "I64u" -#define SCNxLEAST64 "I64x" -#define SCNXLEAST64 "I64X" -#define SCNoFAST64 "I64o" -#define SCNuFAST64 "I64u" -#define SCNxFAST64 "I64x" -#define SCNXFAST64 "I64X" - -#define SCNoMAX "I64o" -#define SCNuMAX "I64u" -#define SCNxMAX "I64x" -#define SCNXMAX "I64X" - -#ifdef _WIN64 // [ -# define SCNoPTR "I64o" -# define SCNuPTR "I64u" -# define SCNxPTR "I64x" -# define SCNXPTR "I64X" -#else // _WIN64 ][ -# define SCNoPTR "lo" -# define SCNuPTR "lu" -# define SCNxPTR "lx" -# define SCNXPTR "lX" -#endif // _WIN64 ] - -#endif // __STDC_FORMAT_MACROS ] - -// 7.8.2 Functions for greatest-width integer types - -// 7.8.2.1 The imaxabs function -#define imaxabs _abs64 - -// 7.8.2.2 The imaxdiv function - -// This is modified version of div() function from Microsoft's div.c found -// in %MSVC.NET%\crt\src\div.c -#ifdef STATIC_IMAXDIV // [ -static -#else // STATIC_IMAXDIV ][ -_inline -#endif // STATIC_IMAXDIV ] -imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) -{ - imaxdiv_t result; - - result.quot = numer / denom; - result.rem = numer % denom; - - if (numer < 0 && result.rem > 0) { - // did division wrong; must fix up - ++result.quot; - result.rem -= denom; - } - - return result; -} - -// 7.8.2.3 The strtoimax and strtoumax functions -#define strtoimax _strtoi64 -#define strtoumax _strtoui64 - -// 7.8.2.4 The wcstoimax and wcstoumax functions -#define wcstoimax _wcstoi64 -#define wcstoumax _wcstoui64 - - -#endif // _MSC_INTTYPES_H_ ] diff --git a/msinttypes/stdint.h b/msinttypes/stdint.h deleted file mode 100644 index d02608a59..000000000 --- a/msinttypes/stdint.h +++ /dev/null @@ -1,247 +0,0 @@ -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2008 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. The name of the author may be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -// For Visual Studio 6 in C++ mode and for many Visual Studio versions when -// compiling for ARM we should wrap include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#ifdef __cplusplus -extern "C" { -#endif -# include -#ifdef __cplusplus -} -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types - -// Visual Studio 6 and Embedded Visual C++ 4 doesn't -// realize that, e.g. char has the same size as __int8 -// so we give up on __intX for them. -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef signed __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 signed int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -#define INTMAX_C INT64_C -#define UINTMAX_C UINT64_C - -#endif // __STDC_CONSTANT_MACROS ] - - -#endif // _MSC_STDINT_H_ ] diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index ac694dcd1..000000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -check_PROGRAMS = test_tables test_parse_url -TESTS = $(check_PROGRAMS) -EXTRA_DIST = test_tables.expected - -AM_CFLAGS = -I$(top_srcdir)/librabbitmq - -if GCC -# Because we want to build under Microsoft's C compiler (for which -# there is apparently no demand for C99 support), it's a good idea -# to have gcc tell us when we stray from the old standard. -AM_CFLAGS += -ansi -pedantic -endif - -if USE_MSINTTYPES -AM_CFLAGS += -I$(top_srcdir)/msinttypes -endif - -AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la diff --git a/tests/test_parse_url.c b/tests/test_parse_url.c deleted file mode 100644 index 4870e1204..000000000 --- a/tests/test_parse_url.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include - -#include - -#include - -static void match_string(const char *what, const char *expect, const char *got) -{ - if (strcmp(got, expect)) { - fprintf(stderr, "Expected %s '%s', got '%s'\n", - what, expect, got); - abort(); - } -} - -static void match_int(const char *what, int expect, int got) -{ - if (got != expect) { - fprintf(stderr, "Expected %s '%d', got '%d'\n", - what, expect, got); - abort(); - } -} - -static void parse_success(const char *url, - const char *user, - const char *password, - const char *host, - int port, - const char *vhost) -{ - char *s = strdup(url); - struct amqp_connection_info ci; - int res; - - amqp_default_connection_info(&ci); - res = amqp_parse_url(s, &ci); - if (res) { - fprintf(stderr, - "Expected to successfully parse URL, but didn't: %s (%s)\n", - url, amqp_error_string(-res)); - abort(); - } - - match_string("user", user, ci.user); - match_string("password", password, ci.password); - match_string("host", host, ci.host); - match_int("port", port, ci.port); - match_string("vhost", vhost, ci.vhost); - - free(s); -} - -static void parse_fail(const char *url) -{ - char *s = strdup(url); - struct amqp_connection_info ci; - - amqp_default_connection_info(&ci); - if (amqp_parse_url(s, &ci) >= 0) { - fprintf(stderr, - "Expected to fail parsing URL, but didn't: %s\n", - url); - abort(); - } - - free(s); -} - -int main(int argc, char **argv) -{ - /* From the spec */ - parse_success("amqp://user:pass@host:10000/vhost", "user", "pass", - "host", 10000, "vhost"); - parse_success("amqp://user%61:%61pass@ho%61st:10000/v%2fhost", - "usera", "apass", "hoast", 10000, "v/host"); - parse_success("amqp://", "guest", "guest", "localhost", 5672, "/"); - parse_success("amqp://:@/", "", "", "localhost", 5672, ""); - parse_success("amqp://user@", "user", "guest", "localhost", 5672, "/"); - parse_success("amqp://user:pass@", "user", "pass", - "localhost", 5672, "/"); - parse_success("amqp://host", "guest", "guest", "host", 5672, "/"); - parse_success("amqp://:10000", "guest", "guest", "localhost", 10000, - "/"); - parse_success("amqp:///vhost", "guest", "guest", "localhost", 5672, - "vhost"); - parse_success("amqp://host/", "guest", "guest", "host", 5672, ""); - parse_success("amqp://host/%2f", "guest", "guest", "host", 5672, "/"); - parse_success("amqp://[::1]", "guest", "guest", "::1", 5672, "/"); - - /* Various other success cases */ - parse_success("amqp://host:100", "guest", "guest", "host", 100, "/"); - parse_success("amqp://[::1]:100", "guest", "guest", "::1", 100, "/"); - - parse_success("amqp://host/blah", "guest", "guest", - "host", 5672, "blah"); - parse_success("amqp://host:100/blah", "guest", "guest", - "host", 100, "blah"); - parse_success("amqp://:100/blah", "guest", "guest", - "localhost", 100, "blah"); - parse_success("amqp://[::1]/blah", "guest", "guest", - "::1", 5672, "blah"); - parse_success("amqp://[::1]:100/blah", "guest", "guest", - "::1", 100, "blah"); - - parse_success("amqp://user:pass@host", "user", "pass", - "host", 5672, "/"); - parse_success("amqp://user:pass@host:100", "user", "pass", - "host", 100, "/"); - parse_success("amqp://user:pass@:100", "user", "pass", - "localhost", 100, "/"); - parse_success("amqp://user:pass@[::1]", "user", "pass", - "::1", 5672, "/"); - parse_success("amqp://user:pass@[::1]:100", "user", "pass", - "::1", 100, "/"); - - /* Various failure cases */ - parse_fail("http://www.rabbitmq.com"); - parse_fail("amqp://foo:bar:baz"); - parse_fail("amqp://foo[::1]"); - parse_fail("amqp://foo:[::1]"); - parse_fail("amqp://[::1]foo"); - parse_fail("amqp://foo:1000xyz"); - parse_fail("amqp://foo:1000000"); - parse_fail("amqp://foo/bar/baz"); - - parse_fail("amqp://foo%1"); - parse_fail("amqp://foo%1x"); - parse_fail("amqp://foo%xy"); - - return 0; -} diff --git a/tests/test_tables.c b/tests/test_tables.c deleted file mode 100644 index 363b9f444..000000000 --- a/tests/test_tables.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -void die(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - abort(); -} - -#define M_PI 3.14159265358979323846264338327 - -static void dump_indent(int indent, FILE *out) -{ - int i; - - for (i = 0; i < indent; i++) - fputc(' ', out); -} - -static void dump_value(int indent, amqp_field_value_t v, FILE *out) -{ - int i; - - dump_indent(indent, out); - fputc(v.kind, out); - - switch (v.kind) { - case AMQP_FIELD_KIND_BOOLEAN: - fputs(v.value.boolean ? " true\n" : " false\n", out); - break; - - case AMQP_FIELD_KIND_I8: - fprintf(out, " %"PRId8"\n", v.value.i8); - break; - - case AMQP_FIELD_KIND_U8: - fprintf(out, " %"PRIu8"\n", v.value.u8); - break; - - case AMQP_FIELD_KIND_I16: - fprintf(out, " %"PRId16"\n", v.value.i16); - break; - - case AMQP_FIELD_KIND_U16: - fprintf(out, " %"PRIu16"\n", v.value.u16); - break; - - case AMQP_FIELD_KIND_I32: - fprintf(out, " %"PRId32"\n", v.value.i32); - break; - - case AMQP_FIELD_KIND_U32: - fprintf(out, " %"PRIu32"\n", v.value.u32); - break; - - case AMQP_FIELD_KIND_I64: - fprintf(out, " %"PRId64"\n", v.value.i64); - break; - - case AMQP_FIELD_KIND_F32: - fprintf(out, " %g\n", (double) v.value.f32); - break; - - case AMQP_FIELD_KIND_F64: - fprintf(out, " %g\n", v.value.f64); - break; - - case AMQP_FIELD_KIND_DECIMAL: - fprintf(out, " %d:::%u\n", v.value.decimal.decimals, - v.value.decimal.value); - break; - - case AMQP_FIELD_KIND_UTF8: - fprintf(out, " %.*s\n", (int)v.value.bytes.len, - (char *)v.value.bytes.bytes); - break; - - case AMQP_FIELD_KIND_BYTES: - fputc(' ', out); - for (i = 0; i < v.value.bytes.len; i++) - fprintf(out, "%02x", ((char *) v.value.bytes.bytes)[i]); - - fputc('\n', out); - break; - - case AMQP_FIELD_KIND_ARRAY: - fputc('\n', out); - for (i = 0; i < v.value.array.num_entries; i++) - dump_value(indent + 2, v.value.array.entries[i], out); - - break; - - case AMQP_FIELD_KIND_TIMESTAMP: - fprintf(out, " %"PRIu64"\n", v.value.u64); - break; - - case AMQP_FIELD_KIND_TABLE: - fputc('\n', out); - for (i = 0; i < v.value.table.num_entries; i++) { - dump_indent(indent + 2, out); - fprintf(out, "%.*s ->\n", - (int)v.value.table.entries[i].key.len, - (char *)v.value.table.entries[i].key.bytes); - dump_value(indent + 4, v.value.table.entries[i].value, out); - } - - break; - - case AMQP_FIELD_KIND_VOID: - fputc('\n', out); - break; - - default: - fprintf(out, "???\n"); - break; - } -} - -static void test_dump_value(FILE *out) -{ - amqp_table_entry_t entries[8]; - amqp_table_t table; - amqp_field_value_t val; - - entries[0].key = amqp_cstring_bytes("zebra"); - entries[0].value.kind = AMQP_FIELD_KIND_UTF8; - entries[0].value.value.bytes = amqp_cstring_bytes("last"); - - entries[1].key = amqp_cstring_bytes("aardvark"); - entries[1].value.kind = AMQP_FIELD_KIND_UTF8; - entries[1].value.value.bytes = amqp_cstring_bytes("first"); - - entries[2].key = amqp_cstring_bytes("middle"); - entries[2].value.kind = AMQP_FIELD_KIND_UTF8; - entries[2].value.value.bytes = amqp_cstring_bytes("third"); - - entries[3].key = amqp_cstring_bytes("number"); - entries[3].value.kind = AMQP_FIELD_KIND_I32; - entries[3].value.value.i32 = 1234; - - entries[4].key = amqp_cstring_bytes("decimal"); - entries[4].value.kind = AMQP_FIELD_KIND_DECIMAL; - entries[4].value.value.decimal.decimals = 2; - entries[4].value.value.decimal.value = 1234; - - entries[5].key = amqp_cstring_bytes("time"); - entries[5].value.kind = AMQP_FIELD_KIND_TIMESTAMP; - entries[5].value.value.u64 = 1234123412341234; - - entries[6].key = amqp_cstring_bytes("beta"); - entries[6].value.kind = AMQP_FIELD_KIND_UTF8; - entries[6].value.value.bytes = amqp_cstring_bytes("second"); - - entries[7].key = amqp_cstring_bytes("wombat"); - entries[7].value.kind = AMQP_FIELD_KIND_UTF8; - entries[7].value.value.bytes = amqp_cstring_bytes("fourth"); - - table.num_entries = 8; - table.entries = entries; - - qsort(table.entries, table.num_entries, sizeof(amqp_table_entry_t), &amqp_table_entry_cmp); - - val.kind = AMQP_FIELD_KIND_TABLE; - val.value.table = table; - - dump_value(0, val, out); -} - -static uint8_t pre_encoded_table[] = { - 0x00, 0x00, 0x00, 0xff, 0x07, 0x6c, 0x6f, 0x6e, - 0x67, 0x73, 0x74, 0x72, 0x53, 0x00, 0x00, 0x00, - 0x15, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, - 0x20, 0x61, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x20, - 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x09, 0x73, - 0x69, 0x67, 0x6e, 0x65, 0x64, 0x69, 0x6e, 0x74, - 0x49, 0x00, 0x00, 0x30, 0x39, 0x07, 0x64, 0x65, - 0x63, 0x69, 0x6d, 0x61, 0x6c, 0x44, 0x03, 0x00, - 0x01, 0xe2, 0x40, 0x09, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x54, 0x00, 0x00, - 0x63, 0xee, 0xa0, 0x53, 0xc1, 0x94, 0x05, 0x74, - 0x61, 0x62, 0x6c, 0x65, 0x46, 0x00, 0x00, 0x00, - 0x1f, 0x03, 0x6f, 0x6e, 0x65, 0x49, 0x00, 0x00, - 0xd4, 0x31, 0x03, 0x74, 0x77, 0x6f, 0x53, 0x00, - 0x00, 0x00, 0x0d, 0x41, 0x20, 0x6c, 0x6f, 0x6e, - 0x67, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x04, 0x62, 0x79, 0x74, 0x65, 0x62, 0xff, 0x04, - 0x6c, 0x6f, 0x6e, 0x67, 0x6c, 0x00, 0x00, 0x00, - 0x00, 0x49, 0x96, 0x02, 0xd2, 0x05, 0x73, 0x68, - 0x6f, 0x72, 0x74, 0x73, 0x02, 0x8f, 0x04, 0x62, - 0x6f, 0x6f, 0x6c, 0x74, 0x01, 0x06, 0x62, 0x69, - 0x6e, 0x61, 0x72, 0x79, 0x78, 0x00, 0x00, 0x00, - 0x0f, 0x61, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, - 0x79, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x04, 0x76, 0x6f, 0x69, 0x64, 0x56, 0x05, 0x61, - 0x72, 0x72, 0x61, 0x79, 0x41, 0x00, 0x00, 0x00, - 0x17, 0x49, 0x00, 0x00, 0xd4, 0x31, 0x53, 0x00, - 0x00, 0x00, 0x0d, 0x41, 0x20, 0x6c, 0x6f, 0x6e, - 0x67, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x05, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x66, 0x40, - 0x49, 0x0f, 0xdb, 0x06, 0x64, 0x6f, 0x75, 0x62, - 0x6c, 0x65, 0x64, 0x40, 0x09, 0x21, 0xfb, 0x54, - 0x44, 0x2d, 0x18 -}; - -static void test_table_codec(FILE *out) -{ - amqp_pool_t pool; - int result; - - amqp_table_entry_t inner_entries[2]; - amqp_table_t inner_table; - - amqp_field_value_t inner_values[2]; - amqp_array_t inner_array; - - amqp_table_entry_t entries[14]; - amqp_table_t table; - - inner_entries[0].key = amqp_cstring_bytes("one"); - inner_entries[0].value.kind = AMQP_FIELD_KIND_I32; - inner_entries[0].value.value.i32 = 54321; - - inner_entries[1].key = amqp_cstring_bytes("two"); - inner_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; - inner_entries[1].value.value.bytes = amqp_cstring_bytes("A long string"); - - inner_table.num_entries = 2; - inner_table.entries = inner_entries; - - inner_values[0].kind = AMQP_FIELD_KIND_I32; - inner_values[0].value.i32 = 54321; - - inner_values[1].kind = AMQP_FIELD_KIND_UTF8; - inner_values[1].value.bytes = amqp_cstring_bytes("A long string"); - - inner_array.num_entries = 2; - inner_array.entries = inner_values; - - entries[0].key = amqp_cstring_bytes("longstr"); - entries[0].value.kind = AMQP_FIELD_KIND_UTF8; - entries[0].value.value.bytes = amqp_cstring_bytes("Here is a long string"); - - entries[1].key = amqp_cstring_bytes("signedint"); - entries[1].value.kind = AMQP_FIELD_KIND_I32; - entries[1].value.value.i32 = 12345; - - entries[2].key = amqp_cstring_bytes("decimal"); - entries[2].value.kind = AMQP_FIELD_KIND_DECIMAL; - entries[2].value.value.decimal.decimals = 3; - entries[2].value.value.decimal.value = 123456; - - entries[3].key = amqp_cstring_bytes("timestamp"); - entries[3].value.kind = AMQP_FIELD_KIND_TIMESTAMP; - entries[3].value.value.u64 = 109876543209876; - - entries[4].key = amqp_cstring_bytes("table"); - entries[4].value.kind = AMQP_FIELD_KIND_TABLE; - entries[4].value.value.table = inner_table; - - entries[5].key = amqp_cstring_bytes("byte"); - entries[5].value.kind = AMQP_FIELD_KIND_I8; - entries[5].value.value.i8 = (int8_t)255; - - entries[6].key = amqp_cstring_bytes("long"); - entries[6].value.kind = AMQP_FIELD_KIND_I64; - entries[6].value.value.i64 = 1234567890; - - entries[7].key = amqp_cstring_bytes("short"); - entries[7].value.kind = AMQP_FIELD_KIND_I16; - entries[7].value.value.i16 = 655; - - entries[8].key = amqp_cstring_bytes("bool"); - entries[8].value.kind = AMQP_FIELD_KIND_BOOLEAN; - entries[8].value.value.boolean = 1; - - entries[9].key = amqp_cstring_bytes("binary"); - entries[9].value.kind = AMQP_FIELD_KIND_BYTES; - entries[9].value.value.bytes = amqp_cstring_bytes("a binary string"); - - entries[10].key = amqp_cstring_bytes("void"); - entries[10].value.kind = AMQP_FIELD_KIND_VOID; - - entries[11].key = amqp_cstring_bytes("array"); - entries[11].value.kind = AMQP_FIELD_KIND_ARRAY; - entries[11].value.value.array = inner_array; - - entries[12].key = amqp_cstring_bytes("float"); - entries[12].value.kind = AMQP_FIELD_KIND_F32; - entries[12].value.value.f32 = M_PI; - - entries[13].key = amqp_cstring_bytes("double"); - entries[13].value.kind = AMQP_FIELD_KIND_F64; - entries[13].value.value.f64 = M_PI; - - table.num_entries = 14; - table.entries = entries; - - fprintf(out, "AAAAAAAAAA\n"); - - { - amqp_field_value_t val; - val.kind = AMQP_FIELD_KIND_TABLE; - val.value.table = table; - dump_value(0, val, out); - } - - init_amqp_pool(&pool, 4096); - - { - amqp_table_t decoded; - size_t decoding_offset = 0; - amqp_bytes_t decoding_bytes; - decoding_bytes.len = sizeof(pre_encoded_table); - decoding_bytes.bytes = pre_encoded_table; - - result = amqp_decode_table(decoding_bytes, &pool, &decoded, - &decoding_offset); - if (result < 0) - die("Table decoding failed: %s", amqp_error_string(-result)); - - fprintf(out, "BBBBBBBBBB\n"); - - { - amqp_field_value_t val; - val.kind = AMQP_FIELD_KIND_TABLE; - val.value.table = decoded; - - dump_value(0, val, out); - } - } - - { - uint8_t encoding_buffer[4096]; - amqp_bytes_t encoding_result; - size_t offset = 0; - - memset(&encoding_buffer[0], 0, sizeof(encoding_buffer)); - encoding_result.len = sizeof(encoding_buffer); - encoding_result.bytes = &encoding_buffer[0]; - - result = amqp_encode_table(encoding_result, &table, &offset); - if (result < 0) - die("Table encoding failed: %s", amqp_error_string(-result)); - - if (offset != sizeof(pre_encoded_table)) - die("Offset should be %ld, was %ld", (long)sizeof(pre_encoded_table), - (long)offset); - - result = memcmp(pre_encoded_table, encoding_buffer, offset); - if (result != 0) - die("Table encoding differed", result); - } - - empty_amqp_pool(&pool); -} - -#define CHUNK_SIZE 4096 - -static int compare_files(const char *f1, const char *f2) -{ - FILE *f1_in; - FILE *f2_in; - char f1_buf[CHUNK_SIZE]; - char f2_buf[CHUNK_SIZE]; - int res; - - f1_in = fopen(f1, "r"); - if (f1_in == NULL) - die("opening %s: %s", f1, strerror(errno)); - - f2_in = fopen(f2, "r"); - if (f2_in == NULL) - die("opening %s: %s", f2, strerror(errno)); - - for (;;) { - size_t f1_got = fread(f1_buf, 1, CHUNK_SIZE, f1_in); - size_t f2_got = fread(f2_buf, 1, CHUNK_SIZE, f2_in); - res = memcmp(f1_buf, f2_buf, f1_got < f2_got ? f1_got : f2_got); - - if (res) - break; - - if (f1_got < CHUNK_SIZE || f2_got < CHUNK_SIZE) { - if (f1_got != f2_got) - res = (f1_got < f2_got ? -1 : 1); - break; - } - } - - fclose(f1_in); - fclose(f2_in); - - return res; -} - -const char *expected_file_name = "test_tables.expected"; - -int main(int argc, char **argv) -{ - char *srcdir = getenv("srcdir"); - char out_path[L_tmpnam]; - FILE *out = fopen(tmpnam(out_path), "w"); - char *expected_path; - - if (out == NULL) - die("opening %s: %s", out_path, strerror(errno)); - - test_table_codec(out); - fprintf(out, "----------\n"); - test_dump_value(out); - - fclose(out); - - if (srcdir == NULL) - die("'srcdir' environment variable not defined"); - - expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2); - sprintf(expected_path, "%s/%s", srcdir, expected_file_name); - if (compare_files(expected_path, out_path)) - die("output file did not have expected contents; see %s", out_path); - - if (remove(out_path)) - die("deleting %s: %s", out_path, strerror(errno)); - - return 0; -} diff --git a/tests/test_tables.expected b/tests/test_tables.expected deleted file mode 100644 index 44d208528..000000000 --- a/tests/test_tables.expected +++ /dev/null @@ -1,90 +0,0 @@ -AAAAAAAAAA -F - longstr -> - S Here is a long string - signedint -> - I 12345 - decimal -> - D 3:::123456 - timestamp -> - T 109876543209876 - table -> - F - one -> - I 54321 - two -> - S A long string - byte -> - b -1 - long -> - l 1234567890 - short -> - s 655 - bool -> - t true - binary -> - x 612062696e61727920737472696e67 - void -> - V - array -> - A - I 54321 - S A long string - float -> - f 3.14159 - double -> - d 3.14159 -BBBBBBBBBB -F - longstr -> - S Here is a long string - signedint -> - I 12345 - decimal -> - D 3:::123456 - timestamp -> - T 109876543209876 - table -> - F - one -> - I 54321 - two -> - S A long string - byte -> - b -1 - long -> - l 1234567890 - short -> - s 655 - bool -> - t true - binary -> - x 612062696e61727920737472696e67 - void -> - V - array -> - A - I 54321 - S A long string - float -> - f 3.14159 - double -> - d 3.14159 ----------- -F - aardvark -> - S first - beta -> - S second - decimal -> - D 2:::1234 - middle -> - S third - number -> - I 1234 - time -> - T 1234123412341234 - wombat -> - S fourth - zebra -> - S last diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt deleted file mode 100644 index 579a3b9f3..000000000 --- a/tools/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${librabbitmq_SOURCE_DIR} ${librabbitmq_BINARY_DIR} ${POPT_INCLUDE_DIRS}) - -if (WIN32) - set(PLATFORM_DIR win32) - set(PLATFORM_SRCS - windows/compat.c - ) -else (WIN32) - set(PLATFORM_DIR unix) -endif (WIN32) - -include_directories(${PLATFORM_DIR}) - -set(COMMON_SRCS - common.h - common.c - ${PLATFORM_SRCS} - ) - -add_executable(amqp-publish publish.c ${COMMON_SRCS}) -target_link_libraries(amqp-publish rabbitmq ${POPT_LIBRARY}) - -add_executable(amqp-get get.c ${COMMON_SRCS}) -target_link_libraries(amqp-get rabbitmq ${POPT_LIBRARY}) - -add_executable(amqp-consume consume.c ${PLATFORM_DIR}/process.c ${COMMON_SRCS}) -target_link_libraries(amqp-consume rabbitmq ${POPT_LIBRARY}) - -add_executable(amqp-declare-queue declare_queue.c ${COMMON_SRCS}) -target_link_libraries(amqp-declare-queue rabbitmq ${POPT_LIBRARY}) - -add_executable(amqp-delete-queue delete_queue.c ${COMMON_SRCS}) -target_link_libraries(amqp-delete-queue rabbitmq ${POPT_LIBRARY}) - diff --git a/tools/Makefile.am b/tools/Makefile.am deleted file mode 100644 index 6fa1e4b76..000000000 --- a/tools/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -SUBDIRS=doc - -bin_PROGRAMS = amqp-publish amqp-get amqp-consume amqp-declare-queue amqp-delete-queue - -# The -I to srcdir's librabbitmq is for the main amqp header -# files. The -I to builddir's librabbitmq is less obvious; it's for -# VPATH-based builds: the amqp_framing.h gets generated into the -# *build* directory, not the source directory. -AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(srcdir)/$(PLATFORM_DIR) -I$(top_builddir)/librabbitmq -AM_LDFLAGS = $(top_builddir)/librabbitmq/librabbitmq.la - -LDADD=$(LIBPOPT) - -noinst_HEADERS = common.h $(PLATFORM_DIR)/process.h - -COMMON_SOURCES = common.c - -if WINDOWS -COMMON_SOURCES += windows/compat.c -endif - -amqp_publish_SOURCES = publish.c $(COMMON_SOURCES) -amqp_get_SOURCES = get.c $(COMMON_SOURCES) -amqp_consume_SOURCES = consume.c $(PLATFORM_DIR)/process.c $(COMMON_SOURCES) -amqp_declare_queue_SOURCES = declare_queue.c $(COMMON_SOURCES) -amqp_delete_queue_SOURCES = delete_queue.c $(COMMON_SOURCES) - -EXTRA_DIST = \ - unix/process.c unix/process.h \ - windows/process.c windows/process.h \ - windows/compat.c windows/compat.h diff --git a/tools/common.c b/tools/common.c deleted file mode 100644 index 38df7514a..000000000 --- a/tools/common.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include "common.h" - -#ifdef WINDOWS -#include "compat.h" -#endif - -void die(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - exit(1); -} - -void die_errno(int err, const char *fmt, ...) -{ - va_list ap; - - if (err == 0) - return; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, ": %s\n", strerror(err)); - exit(1); -} - -void die_amqp_error(int err, const char *fmt, ...) -{ - va_list ap; - char *errstr; - - if (err >= 0) - return; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, ": %s\n", errstr = amqp_error_string(-err)); - free(errstr); - exit(1); -} - -char *amqp_server_exception_string(amqp_rpc_reply_t r) -{ - int res; - char *s; - - switch (r.reply.id) { - case AMQP_CONNECTION_CLOSE_METHOD: { - amqp_connection_close_t *m - = (amqp_connection_close_t *)r.reply.decoded; - res = asprintf(&s, "server connection error %d, message: %.*s", - m->reply_code, - (int)m->reply_text.len, - (char *)m->reply_text.bytes); - break; - } - - case AMQP_CHANNEL_CLOSE_METHOD: { - amqp_channel_close_t *m - = (amqp_channel_close_t *)r.reply.decoded; - res = asprintf(&s, "server channel error %d, message: %.*s", - m->reply_code, - (int)m->reply_text.len, - (char *)m->reply_text.bytes); - break; - } - - default: - res = asprintf(&s, "unknown server error, method id 0x%08X", - r.reply.id); - break; - } - - return res >= 0 ? s : NULL; -} - -char *amqp_rpc_reply_string(amqp_rpc_reply_t r) -{ - switch (r.reply_type) { - case AMQP_RESPONSE_NORMAL: - return strdup("normal response"); - - case AMQP_RESPONSE_NONE: - return strdup("missing RPC reply type"); - - case AMQP_RESPONSE_LIBRARY_EXCEPTION: - return amqp_error_string(r.library_error); - - case AMQP_RESPONSE_SERVER_EXCEPTION: - return amqp_server_exception_string(r); - - default: - abort(); - } -} - -void die_rpc(amqp_rpc_reply_t r, const char *fmt, ...) -{ - va_list ap; - char *errstr; - - if (r.reply_type == AMQP_RESPONSE_NORMAL) - return; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, ": %s\n", errstr = amqp_rpc_reply_string(r)); - free(errstr); - exit(1); -} - -static char *amqp_url; -static char *amqp_server; -static int amqp_port = -1; -static char *amqp_vhost; -static char *amqp_username; -static char *amqp_password; - -const char *connect_options_title = "Connection options"; -struct poptOption connect_options[] = { - {"url", 'u', POPT_ARG_STRING, &amqp_url, 0, - "the AMQP URL to connect to", "amqp://..."}, - {"server", 's', POPT_ARG_STRING, &amqp_server, 0, - "the AMQP server to connect to", "hostname"}, - {"port", 0, POPT_ARG_INT, &amqp_port, 0, - "the port to connect on", "port" }, - {"vhost", 0, POPT_ARG_STRING, &amqp_vhost, 0, - "the vhost to use when connecting", "vhost"}, - {"username", 0, POPT_ARG_STRING, &amqp_username, 0, - "the username to login with", "username"}, - {"password", 0, POPT_ARG_STRING, &amqp_password, 0, - "the password to login with", "password"}, - { NULL, 0, 0, NULL, 0 } -}; - -static void init_connection_info(struct amqp_connection_info *ci) -{ - struct amqp_connection_info defaults; - - ci->user = NULL; - ci->password = NULL; - ci->host = NULL; - ci->port = -1; - ci->vhost = NULL; - ci->user = NULL; - - if (amqp_url) - die_amqp_error(amqp_parse_url(strdup(amqp_url), ci), - "Parsing URL '%s'", amqp_url); - - if (amqp_server) { - if (ci->host) - die("both --server and --url options specify" - " server host"); - - /* parse the server string into a hostname and a port */ - char *colon = strchr(amqp_server, ':'); - if (colon) { - char *port_end; - size_t host_len; - - /* Deprecate specifying the port number with the - --server option, because it is not ipv6 friendly. - --url now allows connection options to be - specificied concisely. */ - fprintf(stderr, "Specifying the port number with" - " --server is deprecated\n"); - - host_len = colon - amqp_server; - ci->host = malloc(host_len + 1); - memcpy(ci->host, amqp_server, host_len); - ci->host[host_len] = 0; - - if (ci->port >= 0) - die("both --server and --url options specify" - " server port"); - if (amqp_port >= 0) - die("both --server and --port options specify" - " server port"); - - ci->port = strtol(colon+1, &port_end, 10); - if (ci->port < 0 - || ci->port > 65535 - || port_end == colon+1 - || *port_end != 0) - die("bad server port number in '%s'", - amqp_server); - } - } - - if (amqp_port >= 0) { - if (ci->port >= 0) - die("both --port and --url options specify" - " server port"); - - ci->port = amqp_port; - } - - if (amqp_username) { - if (ci->user) - die("both --username and --url options specify" - " AMQP username"); - - ci->user = amqp_username; - } - - if (amqp_password) { - if (ci->password) - die("both --password and --url options specify" - " AMQP password"); - - ci->password = amqp_password; - } - - if (amqp_vhost) { - if (ci->vhost) - die("both --vhost and --url options specify" - " AMQP vhost"); - - ci->vhost = amqp_vhost; - } - - amqp_default_connection_info(&defaults); - - if (!ci->user) - ci->user = defaults.user; - if (!ci->password) - ci->password = defaults.password; - if (!ci->host) - ci->host = defaults.host; - if (ci->port < 0) - ci->port = defaults.port; - if (!ci->vhost) - ci->vhost = defaults.vhost; -} - -amqp_connection_state_t make_connection(void) -{ - int s; - struct amqp_connection_info ci; - amqp_connection_state_t conn; - - init_connection_info(&ci); - - s = amqp_open_socket(ci.host, ci.port); - die_amqp_error(s, "opening socket to %s:%d", ci.host, ci.port); - - conn = amqp_new_connection(); - amqp_set_sockfd(conn, s); - - die_rpc(amqp_login(conn, ci.vhost, 0, 131072, 0, - AMQP_SASL_METHOD_PLAIN, - ci.user, ci.password), - "logging in to AMQP server"); - - if (!amqp_channel_open(conn, 1)) - die_rpc(amqp_get_rpc_reply(conn), "opening channel"); - - return conn; -} - -void close_connection(amqp_connection_state_t conn) -{ - int res; - die_rpc(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), - "closing channel"); - die_rpc(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), - "closing connection"); - - res = amqp_destroy_connection(conn); - die_amqp_error(res, "closing connection"); -} - -amqp_bytes_t read_all(int fd) -{ - size_t space = 4096; - amqp_bytes_t bytes; - - bytes.bytes = malloc(space); - bytes.len = 0; - - for (;;) { - ssize_t res = read(fd, bytes.bytes+bytes.len, space-bytes.len); - if (res == 0) - break; - - if (res < 0) { - if (errno == EINTR) - continue; - - die_errno(errno, "reading"); - } - - bytes.len += res; - if (bytes.len == space) { - space *= 2; - bytes.bytes = realloc(bytes.bytes, space); - } - } - - return bytes; -} - -void write_all(int fd, amqp_bytes_t data) -{ - while (data.len > 0) { - ssize_t res = write(fd, data.bytes, data.len); - if (res < 0) - die_errno(errno, "write"); - - data.len -= res; - data.bytes += res; - } -} - -void copy_body(amqp_connection_state_t conn, int fd) -{ - size_t body_remaining; - amqp_frame_t frame; - - int res = amqp_simple_wait_frame(conn, &frame); - die_amqp_error(res, "waiting for header frame"); - if (frame.frame_type != AMQP_FRAME_HEADER) - die("expected header, got frame type 0x%X", - frame.frame_type); - - body_remaining = frame.payload.properties.body_size; - while (body_remaining) { - res = amqp_simple_wait_frame(conn, &frame); - die_amqp_error(res, "waiting for body frame"); - if (frame.frame_type != AMQP_FRAME_BODY) - die("expected body, got frame type 0x%X", - frame.frame_type); - - write_all(fd, frame.payload.body_fragment); - body_remaining -= frame.payload.body_fragment.len; - } -} - -poptContext process_options(int argc, const char **argv, - struct poptOption *options, - const char *help) -{ - int c; - poptContext opts = poptGetContext(NULL, argc, argv, options, 0); - poptSetOtherOptionHelp(opts, help); - - while ((c = poptGetNextOpt(opts)) >= 0) { - /* no options require explicit handling */ - } - - if (c < -1) { - fprintf(stderr, "%s: %s\n", - poptBadOption(opts, POPT_BADOPTION_NOALIAS), - poptStrerror(c)); - poptPrintUsage(opts, stderr, 0); - exit(1); - } - - return opts; -} - -void process_all_options(int argc, const char **argv, - struct poptOption *options) -{ - poptContext opts = process_options(argc, argv, options, - "[OPTIONS]..."); - const char *opt = poptPeekArg(opts); - - if (opt) { - fprintf(stderr, "unexpected operand: %s\n", opt); - poptPrintUsage(opts, stderr, 0); - exit(1); - } - - poptFreeContext(opts); -} - -amqp_bytes_t cstring_bytes(const char *str) -{ - return str ? amqp_cstring_bytes(str) : amqp_empty_bytes; -} diff --git a/tools/common.h b/tools/common.h deleted file mode 100644 index c88c6bc54..000000000 --- a/tools/common.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include - -#include - -#include -#include - -extern char *amqp_server_exception_string(amqp_rpc_reply_t r); -extern char *amqp_rpc_reply_string(amqp_rpc_reply_t r); - -extern void die(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -extern void die_errno(int err, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); -extern void die_amqp_error(int err, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); -extern void die_rpc(amqp_rpc_reply_t r, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); - -extern const char *connect_options_title; -extern struct poptOption connect_options[]; -extern amqp_connection_state_t make_connection(void); -extern void close_connection(amqp_connection_state_t conn); - -extern amqp_bytes_t read_all(int fd); -extern void write_all(int fd, amqp_bytes_t data); - -extern void copy_body(amqp_connection_state_t conn, int fd); - -#define INCLUDE_OPTIONS(options) \ - {NULL, 0, POPT_ARG_INCLUDE_TABLE, options, 0, options ## _title, NULL} - -extern poptContext process_options(int argc, const char **argv, - struct poptOption *options, - const char *help); -extern void process_all_options(int argc, const char **argv, - struct poptOption *options); - -extern amqp_bytes_t cstring_bytes(const char *str); diff --git a/tools/consume.c b/tools/consume.c deleted file mode 100644 index 83a516428..000000000 --- a/tools/consume.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include - -#include "common.h" -#include "process.h" - -/* Convert a amqp_bytes_t to an escaped string form for printing. We - use the same escaping conventions as rabbitmqctl. */ -static char *stringify_bytes(amqp_bytes_t bytes) -{ - /* We will need up to 4 chars per byte, plus the terminating 0 */ - char *res = malloc(bytes.len * 4 + 1); - uint8_t *data = bytes.bytes; - char *p = res; - size_t i; - - for (i = 0; i < bytes.len; i++) { - if (data[i] >= 32 && data[i] != 127) { - *p++ = data[i]; - } - else { - *p++ = '\\'; - *p++ = '0' + (data[i] >> 6); - *p++ = '0' + (data[i] >> 3 & 0x7); - *p++ = '0' + (data[i] & 0x7); - } - } - - *p = 0; - return res; -} - -static amqp_bytes_t setup_queue(amqp_connection_state_t conn, - char *queue, char *exchange, - char *routing_key, int declare) -{ - amqp_bytes_t queue_bytes = cstring_bytes(queue); - - /* if an exchange name wasn't provided, check that we don't - have options that require it. */ - if (!exchange && routing_key) { - fprintf(stderr, "--routing-key option requires an exchange" - " name to be provided with --exchange\n"); - exit(1); - } - - if (!queue || exchange || declare) { - /* Declare the queue as auto-delete. */ - amqp_queue_declare_ok_t *res = amqp_queue_declare(conn, 1, - queue_bytes, 0, 0, 1, 1, - amqp_empty_table); - if (!res) - die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); - - if (!queue) { - /* the server should have provided a queue name */ - char *sq; - queue_bytes = amqp_bytes_malloc_dup(res->queue); - sq = stringify_bytes(queue_bytes); - fprintf(stderr, "Server provided queue name: %s\n", - sq); - free(sq); - } - - /* Bind to an exchange if requested */ - if (exchange) { - amqp_bytes_t eb = amqp_cstring_bytes(exchange); - if (!amqp_queue_bind(conn, 1, queue_bytes, eb, - cstring_bytes(routing_key), - amqp_empty_table)) - die_rpc(amqp_get_rpc_reply(conn), - "queue.bind"); - } - } - - return queue_bytes; -} - -static void do_consume(amqp_connection_state_t conn, amqp_bytes_t queue, - int no_ack, int count, const char * const *argv) -{ - int i; - - /* If there is a limit, set the qos to match */ - if (count > 0 && count <= 65535 - && !amqp_basic_qos(conn, 1, 0, count, 0)) - die_rpc(amqp_get_rpc_reply(conn), "basic.qos"); - - if (!amqp_basic_consume(conn, 1, queue, amqp_empty_bytes, 0, no_ack, - 0, amqp_empty_table)) - die_rpc(amqp_get_rpc_reply(conn), "basic.consume"); - - for (i = 0; count < 0 || i < count; i++) { - amqp_frame_t frame; - struct pipeline pl; - uint64_t delivery_tag; - int res = amqp_simple_wait_frame(conn, &frame); - die_amqp_error(res, "waiting for header frame"); - - if (frame.frame_type != AMQP_FRAME_METHOD - || frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) - continue; - - amqp_basic_deliver_t *deliver - = (amqp_basic_deliver_t *)frame.payload.method.decoded; - delivery_tag = deliver->delivery_tag; - - pipeline(argv, &pl); - copy_body(conn, pl.infd); - - if (finish_pipeline(&pl) && !no_ack) - die_amqp_error(amqp_basic_ack(conn, 1, delivery_tag, - 0), - "basic.ack"); - - amqp_maybe_release_buffers(conn); - } -} - -int main(int argc, const char **argv) -{ - poptContext opts; - amqp_connection_state_t conn; - const char * const *cmd_argv; - char *queue = NULL; - char *exchange = NULL; - char *routing_key = NULL; - int declare = 0; - int no_ack = 0; - int count = -1; - amqp_bytes_t queue_bytes; - - struct poptOption options[] = { - INCLUDE_OPTIONS(connect_options), - {"queue", 'q', POPT_ARG_STRING, &queue, 0, - "the queue to consume from", "queue"}, - {"exchange", 'e', POPT_ARG_STRING, &exchange, 0, - "bind the queue to this exchange", "exchange"}, - {"routing-key", 'r', POPT_ARG_STRING, &routing_key, 0, - "the routing key to bind with", "routing key"}, - {"declare", 'd', POPT_ARG_NONE, &declare, 0, - "declare an exclusive queue", NULL}, - {"no-ack", 'A', POPT_ARG_NONE, &no_ack, 0, - "consume in no-ack mode", NULL}, - {"count", 'c', POPT_ARG_INT, &count, 0, - "stop consuming after this many messages are consumed", - "limit"}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - opts = process_options(argc, argv, options, - "[OPTIONS]... "); - - cmd_argv = poptGetArgs(opts); - if (!cmd_argv || !cmd_argv[0]) { - fprintf(stderr, "consuming command not specified\n"); - poptPrintUsage(opts, stderr, 0); - goto error; - } - - conn = make_connection(); - queue_bytes = setup_queue(conn, queue, exchange, routing_key, declare); - do_consume(conn, queue_bytes, no_ack, count, cmd_argv); - close_connection(conn); - return 0; - -error: - poptFreeContext(opts); - return 1; -} diff --git a/tools/declare_queue.c b/tools/declare_queue.c deleted file mode 100644 index d6bb9db5f..000000000 --- a/tools/declare_queue.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include -#include - -#include "common.h" - -int main(int argc, const char **argv) -{ - amqp_connection_state_t conn; - char *queue = NULL; - int durable = 0; - - struct poptOption options[] = { - INCLUDE_OPTIONS(connect_options), - {"queue", 'q', POPT_ARG_STRING, &queue, 0, - "the queue name to declare, or the empty string", "queue"}, - {"durable", 'd', POPT_ARG_VAL, &durable, 1, - "declare a durable queue", NULL}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - process_all_options(argc, argv, options); - - if (queue == NULL) { - fprintf(stderr, "queue name not specified\n"); - return 1; - } - - conn = make_connection(); - { - amqp_queue_declare_ok_t *reply = amqp_queue_declare(conn, 1, - cstring_bytes(queue), - 0, - durable, - 0, - 0, - amqp_empty_table); - if (reply == NULL) - die_rpc(amqp_get_rpc_reply(conn), "queue.declare"); - - printf("%.*s\n", (int)reply->queue.len, (char *)reply->queue.bytes); - } - close_connection(conn); - return 0; -} diff --git a/tools/delete_queue.c b/tools/delete_queue.c deleted file mode 100644 index e596096cc..000000000 --- a/tools/delete_queue.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include -#include - -#include "common.h" - -int main(int argc, const char **argv) -{ - amqp_connection_state_t conn; - char *queue = NULL; - int if_unused = 0; - int if_empty = 0; - - struct poptOption options[] = { - INCLUDE_OPTIONS(connect_options), - {"queue", 'q', POPT_ARG_STRING, &queue, 0, - "the queue name to delete", "queue"}, - {"if-unused", 'u', POPT_ARG_VAL, &if_unused, 1, - "do not delete unless queue is unused", NULL}, - {"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1, - "do not delete unless queue is empty", NULL}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - process_all_options(argc, argv, options); - - if (queue == NULL || *queue == '\0') { - fprintf(stderr, "queue name not specified\n"); - return 1; - } - - conn = make_connection(); - { - amqp_queue_delete_ok_t *reply = amqp_queue_delete(conn, 1, - cstring_bytes(queue), - if_unused, - if_empty); - if (reply == NULL) { - die_rpc(amqp_get_rpc_reply(conn), "queue.delete"); - } - printf("%u\n", reply->message_count); - } - close_connection(conn); - return 0; -} diff --git a/tools/doc/Makefile.am b/tools/doc/Makefile.am deleted file mode 100644 index f482d94a1..000000000 --- a/tools/doc/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -EXTRA_DIST = \ - publish.xml \ - consume.xml \ - get.xml \ - declare_queue.xml \ - delete_queue.xml \ - librabbitmq-tools.xml - -if TOOLS_DOC -man_MANS = \ - amqp-publish.1 \ - amqp-consume.1 \ - amqp-get.1 \ - amqp-declare-queue.1 \ - amqp-delete-queue.1 \ - librabbitmq-tools.7 -MOSTLYCLEANFILES = man-date.ent $(man_MANS) - -# automake complains about % pattern rules, and suffix rules don't -# support multiple dependencies, so we have to expand all these out. -# -# Also, xmlto's --searchpath doesn't get passed through to xmllint, so -# we disable xmllint validation with --skip-validation for the benefit -# of build/source separation as required by distcheck, debian -# packaging etc. -amqp-publish.1: publish.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< -amqp-consume.1: consume.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< -amqp-get.1: get.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< -amqp-declare-queue.1: declare_queue.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< -amqp-delete-queue.1: delete_queue.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< -librabbitmq-tools.7: librabbitmq-tools.xml man-date.ent - $(XMLTO) --skip-validation --searchpath $(CURDIR) man $< - -man-date.ent: - date +'%Y-%m-%d' >$@ - -endif diff --git a/tools/doc/consume.xml b/tools/doc/consume.xml deleted file mode 100644 index b5f40d7ce..000000000 --- a/tools/doc/consume.xml +++ /dev/null @@ -1,187 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - amqp-consume - 1 - RabbitMQ C Client - - - - amqp-consume - Consume messages from a queue on an AMQP server - - - - - amqp-consume - - OPTION - - - command - - - args - - - - - - Description - - amqp-consume consumes messages from a - queue on an AMQP server. For each message that arrives, a - receiving command is run, with the message body supplied - to it on standard input. - - - amqp-consume can consume from an - existing queue, or it can create a new queue. It can - optionally bind the queue to an existing exchange. - - - By default, messages will be consumed with explicit - acknowledgements. A message will only be acknowledged if - the receiving command exits successfully (i.e. with an - exit code of zero). The AMQP no ack mode - (a.k.a. auto-ack mode) can be enable with the - option. - - - - - Options - - - - =queue name - - - The name of the queue to consume messages - from. - - - - If the option is - omitted, the AMQP server will assign a unique - name to the queue, and that server-assigned - name will be dixsplayed on stderr; this case - implies that an exclusive queue should be - declared. - - - - - - =exchange name - - - Specifies that an exclusive queue should - be declared, and bound to the given exchange. - The specified exchange should already exist - unless the - option is used to request the creation of an - exchange. - - - - - - =routing key - - - The routing key for binding. If omitted, an - empty routing key is assumed. - - - - - - - - - Forces an exclusive queue to be declared, - even when it otherwise would not be. That is, - when a queue name is specified with the - option, but no - binding to an exchange is requested with the - option. - - - - - - =routing key - - - Enable no ack mode: The AMQP - server will unconditionally acknowledge each - message that is delivered, regardless of - whether the target command exits successfully - or not. - - - - - - =limit - - - Stop consuming after the given number of - messages have been received. - - - - - - - - Examples - - - Consume messages from an existing queue - myqueue, and - output the message bodies on standard output via - cat: - - $ amqp-publish -q myqueue cat - - - - - Bind a new exclusive queue to an - exchange myexch, and send - each message body to the script - myscript, automatically - acknowledging them on the server: - - $ amqp-consume -A -e myexch ./myscript - - - - - - - See also - - librabbitmq-tools7 - describes connection-related options common to all the - RabbitMQ C Client tools. - - - diff --git a/tools/doc/declare_queue.xml b/tools/doc/declare_queue.xml deleted file mode 100644 index 0fc04407b..000000000 --- a/tools/doc/declare_queue.xml +++ /dev/null @@ -1,122 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - amqp-declare-queue - 1 - RabbitMQ C Client - - - - amqp-declare-queue - Declare (create or assert the existence of) a queue on an AMQP server - - - - - amqp-declare-queue - - OPTION - - -d - -q queue name - - - - - Description - - amqp-declare-queue attempts to create a - queue on an AMQP server, and exits. If the empty-string is - supplied as the queue name, a fresh queue name is - generated by the server and returned. In all cases, if a - queue was successfully declared, the (raw binary) name of - the queue is printed to standard output, followed by a - newline. - - - - - Options - - - - =queue name - - - The name of the queue to declare. If the - empty string is supplied, a fresh queue name - is generated by the server. - - - - - - - - - Causes the queue to be declared with the - "durable" flag set. Durable queues survive - server restarts. By default, queues are declared - in "transient" mode. - - - - - - - - Exit Status - - If the queue was successfully declared, the exit status is - 0. If an error occurs, the exit status is 1. - - - - - Examples - - - Declare the durable queue myqueue, and - display the name of the queue on standard output: - - $ amqp-declare-queue -d -q myqueue -myqueue - - - - Declare a fresh, server-named transient queue, - and display the name of the queue on standard output - (use amqp-delete-queue - 1 to delete - it from the server once you're done): - - $ amqp-declare-queue -q "" -amq.gen-BW/wvociA8g6LFpb1PlqOA== - - - - - - - See also - - librabbitmq-tools7 - describes connection-related options common to all the - RabbitMQ C Client tools. - - - diff --git a/tools/doc/delete_queue.xml b/tools/doc/delete_queue.xml deleted file mode 100644 index 040a384de..000000000 --- a/tools/doc/delete_queue.xml +++ /dev/null @@ -1,94 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - amqp-delete-queue - 1 - RabbitMQ C Client - - - - amqp-delete-queue - Delete a queue from an AMQP server - - - - - amqp-delete-queue - - OPTION - - -q queue name - - - - - Description - - amqp-delete-queue deletes a queue from - an AMQP server, and exits after printing to standard - output the number of messages that were in the queue at - the time of its deletion. - - - - - Options - - - - =queue name - - - The name of the queue to delete. - - - - - - - - Exit Status - - If the queue was successfully deleted, the exit status is - 0. If an error occurs, the exit status is 1. - - - - - Examples - - - Delete the - queue myqueue - at a moment when it has 123 messages waiting on - it: - - $ amqp-delete-queue -q myqueue -123 - - - - - - - See also - - librabbitmq-tools7 - describes connection-related options common to all the - RabbitMQ C Client tools. - - - diff --git a/tools/doc/get.xml b/tools/doc/get.xml deleted file mode 100644 index 08abe2bdd..000000000 --- a/tools/doc/get.xml +++ /dev/null @@ -1,95 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - amqp-get - 1 - RabbitMQ C Client - - - - amqp-get - Get a message from a queue on an AMQP server - - - - - amqp-get - - OPTION - - -q queue name - - - - - Description - - amqp-get attempts to consume a single - message from a queue on an AMQP server, and exits. Unless - the queue was empty, the body of the resulting message is - sent to standard output. - - - - - Options - - - - =queue name - - - The name of the queue to consume messages - from. - - - - - - - - Exit Status - - If the queue is not empty, and a message is successfully - retrieved, the exit status is 0. If an error occurs, the - exit status is 1. If the queue is found to be empty, the - exit status is 2. - - - - - Examples - - - Get a message from the queue myqueue, and - display its body on standard output: - - $ amqp-get -q myqueue - - - - - - - See also - - librabbitmq-tools7 - describes connection-related options common to all the - RabbitMQ C Client tools. - - - diff --git a/tools/doc/librabbitmq-tools.xml b/tools/doc/librabbitmq-tools.xml deleted file mode 100644 index 41f092a8e..000000000 --- a/tools/doc/librabbitmq-tools.xml +++ /dev/null @@ -1,90 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - librabbitmq-tools - 7 - RabbitMQ C Client - - - - librabbitmq-tools - Command line AMQP tools - - - - Description - - A set of command line AMQP tools based on librabbitmq. This page - describes common options and conventions used by all of - the tools. - - - - - Common Options - - - - =hostname:port - - - The host name (or address) to connect to. - Defaults to localhost. The port number may - also be specified; if omitted, it defaults to - the standard AMQP port number (5672). - - - - - =vhost - - - The AMQP vhost to specify when connnecting. - Defaults to /. - - - - - =username - - - The username to authenticate to the AMQP server with. Defaults to guest. - - - - - =password - - - The password to authenticate to the AMQP server with. Defaults to guest. - - - - - - - - See also - - - amqp-publish1 - amqp-consume1 - amqp-get1 - - - - diff --git a/tools/doc/publish.xml b/tools/doc/publish.xml deleted file mode 100644 index e609972ad..000000000 --- a/tools/doc/publish.xml +++ /dev/null @@ -1,160 +0,0 @@ - - -] -> - - - RabbitMQ C Client - - The RabbitMQ Team <info@rabbitmq.com> - - &date; - - - - amqp-publish - 1 - RabbitMQ C Client - - - - amqp-publish - Publish a message on an AMQP server - - - - - amqp-publish - - OPTION - - - - - - Description - - Publishes a message to an exchange on an AMQP server. - Options allow the various properties of the message and - parameters of the AMQP basic.publish - method to be specified. - - - By default, the message body is read from standard input. - Alternatively, the option allows the message - body to be provided as part of the command. - - - - - Options - - - - =exchange name - - - The name of the exchange to publish to. If - omitted, the default exchange (also known as - the nameless exchange) is used. - - - - - - =routing key - - - The routing key to publish with. If omitted, - an empty routing key is assumed. A routing - key must be specified when publishing to the - default exchange; in that case, accoding to - the AMQP specification, the routing key - corresponds to a queue name. - - - - - - - - - Use the persistent delivery mode. Without - this option, non-persistent delivery is used. - - - - - - =MIME type - - - Specifies the content-type property for the - message. If omitted, the content-type - property is not set on the message. - - - - - - =content coding - - - Specifies the content-encoding property for - the message. If omitted, the content-encoding - property is not set on the message. - - - - - - =message body - - - Specifies the message body. If omitted, the - message body is read from standard input. - - - - - - - - Examples - - - Send a short message, consisting of the word - Hello to the queue - myqueue via the - default exchange: - - $ amqp-publish -r myqueue -b Hello - - - - - Send some XML data from a file to the exchange - events, with - persistent delivery mode, setting the content-type - property on the message to make the data format - explicit: - - $ amqp-publish -e events -p -C text/xml <event.xml - - - - - - - See also - - librabbitmq-tools7 - describes connection-related options common to all the - RabbitMQ C Client tools. - - - diff --git a/tools/get.c b/tools/get.c deleted file mode 100644 index 57ebedb02..000000000 --- a/tools/get.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include - -#include "common.h" - -static int do_get(amqp_connection_state_t conn, char *queue) -{ - amqp_rpc_reply_t r - = amqp_basic_get(conn, 1, cstring_bytes(queue), 1); - die_rpc(r, "basic.get"); - - if (r.reply.id == AMQP_BASIC_GET_EMPTY_METHOD) - return 0; - - copy_body(conn, 1); - return 1; -} - -int main(int argc, const char **argv) -{ - amqp_connection_state_t conn; - char *queue = NULL; - int got_something; - - struct poptOption options[] = { - INCLUDE_OPTIONS(connect_options), - {"queue", 'q', POPT_ARG_STRING, &queue, 0, - "the queue to consume from", "queue"}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - process_all_options(argc, argv, options); - - if (!queue) { - fprintf(stderr, "queue not specified\n"); - return 1; - } - - conn = make_connection(); - got_something = do_get(conn, queue); - close_connection(conn); - return got_something ? 0 : 2; -} diff --git a/tools/publish.c b/tools/publish.c deleted file mode 100644 index 57060df10..000000000 --- a/tools/publish.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include -#include -#include - -#include "common.h" - -static void do_publish(amqp_connection_state_t conn, - char *exchange, char *routing_key, - amqp_basic_properties_t *props, amqp_bytes_t body) -{ - int res = amqp_basic_publish(conn, 1, - cstring_bytes(exchange), - cstring_bytes(routing_key), - 0, 0, props, body); - die_amqp_error(res, "basic.publish"); -} - -int main(int argc, const char **argv) -{ - amqp_connection_state_t conn; - char *exchange = NULL; - char *routing_key = NULL; - char *content_type = NULL; - char *content_encoding = NULL; - char *body = NULL; - amqp_basic_properties_t props; - amqp_bytes_t body_bytes; - int delivery = 1; /* non-persistent by default */ - - struct poptOption options[] = { - INCLUDE_OPTIONS(connect_options), - {"exchange", 'e', POPT_ARG_STRING, &exchange, 0, - "the exchange to publish to", "exchange"}, - {"routing-key", 'r', POPT_ARG_STRING, &routing_key, 0, - "the routing key to publish with", "routing key"}, - {"persistent", 'p', POPT_ARG_VAL, &delivery, 2, - "use the persistent delivery mode", NULL}, - {"content-type", 'C', POPT_ARG_STRING, &content_type, 0, - "the content-type for the message", "content type"}, - {"content-encoding", 'E', POPT_ARG_STRING, - &content_encoding, 0, - "the content-encoding for the message", "content encoding"}, - {"body", 'b', POPT_ARG_STRING, &body, 0, - "specify the message body", "body"}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - process_all_options(argc, argv, options); - - if (!exchange && !routing_key) { - fprintf(stderr, - "neither exchange nor routing key specified\n"); - return 1; - } - - memset(&props, 0, sizeof props); - props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG; - props.delivery_mode = 2; /* persistent delivery mode */ - - if (content_type) { - props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG; - props.content_type = amqp_cstring_bytes(content_type); - } - - if (content_encoding) { - props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG; - props.content_encoding = amqp_cstring_bytes(content_encoding); - } - - conn = make_connection(); - - if (body) - body_bytes = amqp_cstring_bytes(body); - else - body_bytes = read_all(0); - - do_publish(conn, exchange, routing_key, &props, body_bytes); - - if (!body) - free(body_bytes.bytes); - - close_connection(conn); - return 0; -} diff --git a/tools/unix/process.c b/tools/unix/process.c deleted file mode 100644 index 1e0d1d639..000000000 --- a/tools/unix/process.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include -#include - -#include "common.h" -#include "process.h" - -extern char **environ; - -void pipeline(const char *const *argv, struct pipeline *pl) -{ - posix_spawn_file_actions_t file_acts; - - int pipefds[2]; - if (pipe(pipefds)) - die_errno(errno, "pipe"); - - die_errno(posix_spawn_file_actions_init(&file_acts), - "posix_spawn_file_actions_init"); - die_errno(posix_spawn_file_actions_adddup2(&file_acts, pipefds[0], 0), - "posix_spawn_file_actions_adddup2"); - die_errno(posix_spawn_file_actions_addclose(&file_acts, pipefds[0]), - "posix_spawn_file_actions_addclose"); - die_errno(posix_spawn_file_actions_addclose(&file_acts, pipefds[1]), - "posix_spawn_file_actions_addclose"); - - die_errno(posix_spawnp(&pl->pid, argv[0], &file_acts, NULL, - (char * const *)argv, environ), - "posix_spawnp: %s", argv[0]); - - die_errno(posix_spawn_file_actions_destroy(&file_acts), - "posix_spawn_file_actions_destroy"); - - if (close(pipefds[0])) - die_errno(errno, "close"); - - pl->infd = pipefds[1]; -} - -int finish_pipeline(struct pipeline *pl) -{ - int status; - - if (close(pl->infd)) - die_errno(errno, "close"); - if (waitpid(pl->pid, &status, 0) < 0) - die_errno(errno, "waitpid"); - return WIFEXITED(status) && WEXITSTATUS(status) == 0; -} diff --git a/tools/unix/process.h b/tools/unix/process.h deleted file mode 100644 index 6b6d93dc2..000000000 --- a/tools/unix/process.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -struct pipeline { - int pid; - int infd; -}; - -extern void pipeline(const char *const *argv, struct pipeline *pl); -extern int finish_pipeline(struct pipeline *pl); diff --git a/tools/windows/compat.c b/tools/windows/compat.c deleted file mode 100644 index acba42e9f..000000000 --- a/tools/windows/compat.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include "compat.h" - -int asprintf(char **strp, const char *fmt, ...) -{ - va_list ap; - int len; - - va_start(ap, fmt); - len = _vscprintf(fmt, ap); - va_end(ap); - - *strp = malloc(len+1); - if (!*strp) - return -1; - - va_start(ap, fmt); - _vsnprintf(*strp, len+1, fmt, ap); - va_end(ap); - - (*strp)[len] = 0; - return len; -} diff --git a/tools/windows/compat.h b/tools/windows/compat.h deleted file mode 100644 index 9b9c96a5e..000000000 --- a/tools/windows/compat.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -extern int asprintf(char **strp, const char *fmt, ...); diff --git a/tools/windows/process.c b/tools/windows/process.c deleted file mode 100644 index 26b9a701c..000000000 --- a/tools/windows/process.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include -#include -#include - -#include "common.h" -#include "process.h" - -void die_windows_error(const char *fmt, ...) -{ - char *msg; - - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&msg, 0, NULL)) - msg = "(failed to retrieve Windows error message)"; - - fprintf(stderr, ": %s\n", msg); - exit(1); -} - -static char *make_command_line(const char *const *argv) -{ - int i; - size_t len = 1; /* initial quotes */ - char *buf; - char *dest; - - /* calculate the length of the required buffer, making worst - case assumptions for simplicity */ - for (i = 0;;) { - /* each character could need escaping */ - len += strlen(argv[i]) * 2; - - if (!argv[++i]) - break; - - len += 3; /* quotes, space, quotes */ - } - - len += 2; /* final quotes and the terminating zero */ - - dest = buf = malloc(len); - if (!buf) - die("allocating memory for subprocess command line"); - - /* Here we perform the inverse of the CommandLineToArgvW - function. Note that its rules are slightly crazy: A - sequence of backslashes only act to escape if followed by - double quotes. A sequence of backslashes not followed by - double quotes is untouched. */ - - for (i = 0;;) { - const char *src = argv[i]; - int backslashes = 0; - - *dest++ = '\"'; - - for (;;) { - switch (*src) { - case 0: - goto done; - - case '\"': - for (; backslashes; backslashes--) - *dest++ = '\\'; - - *dest++ = '\\'; - *dest++ = '\"'; - break; - - case '\\': - backslashes++; - *dest++ = '\\'; - break; - - default: - backslashes = 0; - *dest++ = *src; - break; - } - - src++; - } - done: - for (; backslashes; backslashes--) - *dest++ = '\\'; - - *dest++ = '\"'; - - if (!argv[++i]) - break; - - *dest++ = ' '; - } - - *dest++ = 0; - return buf; -} - -void pipeline(const char *const *argv, struct pipeline *pl) -{ - HANDLE in_read_handle, in_write_handle; - SECURITY_ATTRIBUTES sec_attr; - PROCESS_INFORMATION proc_info; - STARTUPINFO start_info; - char *cmdline = make_command_line(argv); - - sec_attr.nLength = sizeof sec_attr; - sec_attr.bInheritHandle = TRUE; - sec_attr.lpSecurityDescriptor = NULL; - - if (!CreatePipe(&in_read_handle, &in_write_handle, &sec_attr, 0)) - die_windows_error("CreatePipe"); - - if (!SetHandleInformation(in_write_handle, HANDLE_FLAG_INHERIT, 0)) - die_windows_error("SetHandleInformation"); - - /* when in Rome... */ - ZeroMemory(&proc_info, sizeof proc_info); - ZeroMemory(&start_info, sizeof start_info); - - start_info.cb = sizeof start_info; - start_info.dwFlags |= STARTF_USESTDHANDLES; - - if ((start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE)) - == INVALID_HANDLE_VALUE - || (start_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE)) - == INVALID_HANDLE_VALUE) - die_windows_error("GetStdHandle"); - - start_info.hStdInput = in_read_handle; - - if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, - NULL, NULL, &start_info, &proc_info)) - die_windows_error("CreateProcess"); - - free(cmdline); - - if (!CloseHandle(proc_info.hThread)) - die_windows_error("CloseHandle for thread"); - if (!CloseHandle(in_read_handle)) - die_windows_error("CloseHandle"); - - pl->proc_handle = proc_info.hProcess; - pl->infd = _open_osfhandle((intptr_t)in_write_handle, 0); -} - -int finish_pipeline(struct pipeline *pl) -{ - DWORD code; - - if (close(pl->infd)) - die_errno(errno, "close"); - - for (;;) { - if (!GetExitCodeProcess(pl->proc_handle, &code)) - die_windows_error("GetExitCodeProcess"); - if (code != STILL_ACTIVE) - break; - - if (WaitForSingleObject(pl->proc_handle, INFINITE) - == WAIT_FAILED) - die_windows_error("WaitForSingleObject"); - } - - if (!CloseHandle(pl->proc_handle)) - die_windows_error("CloseHandle for process"); - - return code; -} diff --git a/tools/windows/process.h b/tools/windows/process.h deleted file mode 100644 index c2a8a0ded..000000000 --- a/tools/windows/process.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MIT - * - * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. - * All Rights Reserved. - * - * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 - * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * ***** END LICENSE BLOCK ***** - */ - -#include - -struct pipeline { - HANDLE proc_handle; - int infd; -}; - -extern void pipeline(const char *const *argv, struct pipeline *pl); -extern int finish_pipeline(struct pipeline *pl);