diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-05-12 13:08:45 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-05-12 13:08:45 +0100 |
commit | 36a1423f8ad3626303e24ba34abb2ba7429e91bc (patch) | |
tree | 9bacec0e0273010e6f44d386ebc4fdfaaafda470 /tools | |
parent | 11a5577f7c6ee26ec832bc806567e1909449dfc4 (diff) | |
download | rabbitmq-c-github-ask-bug24079.tar.gz |
Pre-junk. rabbitmq-c is not in fact a plugin.bug24079
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 27 | ||||
-rw-r--r-- | tools/common.c | 358 | ||||
-rw-r--r-- | tools/common.h | 89 | ||||
-rw-r--r-- | tools/consume.c | 212 | ||||
-rw-r--r-- | tools/declare_queue.c | 99 | ||||
-rw-r--r-- | tools/delete_queue.c | 99 | ||||
-rw-r--r-- | tools/doc/Makefile.am | 42 | ||||
-rw-r--r-- | tools/doc/consume.xml | 177 | ||||
-rw-r--r-- | tools/doc/declare_queue.xml | 122 | ||||
-rw-r--r-- | tools/doc/delete_queue.xml | 94 | ||||
-rw-r--r-- | tools/doc/get.xml | 95 | ||||
-rw-r--r-- | tools/doc/librabbitmq-tools.xml | 90 | ||||
-rw-r--r-- | tools/doc/publish.xml | 160 | ||||
-rw-r--r-- | tools/get.c | 95 | ||||
-rw-r--r-- | tools/publish.c | 137 | ||||
-rw-r--r-- | tools/unix/process.c | 100 | ||||
-rw-r--r-- | tools/unix/process.h | 57 | ||||
-rw-r--r-- | tools/windows/compat.c | 76 | ||||
-rw-r--r-- | tools/windows/compat.h | 51 | ||||
-rw-r--r-- | tools/windows/process.c | 227 | ||||
-rw-r--r-- | tools/windows/process.h | 59 |
21 files changed, 0 insertions, 2466 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am deleted file mode 100644 index ccd36ca..0000000 --- a/tools/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -SUBDIRS=doc - -bin_PROGRAMS = amqp-publish amqp-get amqp-consume amqp-declare-queue amqp-delete-queue - -AM_CFLAGS = -I$(top_srcdir)/librabbitmq -I$(srcdir)/$(PLATFORM_DIR) -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 7b0a969..0000000 --- a/tools/common.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#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(errno)); - 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_server = "localhost"; -static char *amqp_vhost = "/"; -static char *amqp_username = "guest"; -static char *amqp_password = "guest"; - -const char *connect_options_title = "Connection options"; -struct poptOption connect_options[] = { - {"server", 's', POPT_ARG_STRING, &amqp_server, 0, - "the AMQP server to connect to", "hostname: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 } -}; - -amqp_connection_state_t make_connection(void) -{ - int s; - amqp_connection_state_t conn; - char *host = amqp_server; - int port = 0; - - /* parse the server string into a hostname and a port */ - char *colon = strchr(amqp_server, ':'); - if (colon) { - char *port_end; - size_t host_len = colon - amqp_server; - host = malloc(host_len + 1); - memcpy(host, amqp_server, host_len); - host[host_len] = 0; - - port = strtol(colon+1, &port_end, 10); - if (port < 0 - || port > 65535 - || port_end == colon+1 - || *port_end != 0) - die("bad server port number in %s", amqp_server); - } - - s = amqp_open_socket(host, port ? port : 5672); - die_amqp_error(s, "opening socket to %s", amqp_server); - - conn = amqp_new_connection(); - amqp_set_sockfd(conn, s); - - die_rpc(amqp_login(conn, amqp_vhost, 0, 131072, 0, - AMQP_SASL_METHOD_PLAIN, - amqp_username, amqp_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 84889d3..0000000 --- a/tools/common.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdint.h> - -#include <popt.h> - -#include <amqp.h> -#include <amqp_framing.h> - -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 434a6f5..0000000 --- a/tools/consume.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> - -#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, const char * const *argv) -{ - 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 (;;) { - 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; - 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}, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0 } - }; - - opts = process_options(argc, argv, options, - "[OPTIONS]... <command> <args>"); - - 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, 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 145a15e..0000000 --- a/tools/declare_queue.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#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 ccd157e..0000000 --- a/tools/delete_queue.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#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 f482d94..0000000 --- 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 c6dc65c..0000000 --- a/tools/doc/consume.xml +++ /dev/null @@ -1,177 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>amqp-consume</refentrytitle> - <manvolnum>1</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>amqp-consume</refname> - <refpurpose>Consume messages from a queue on an AMQP server</refpurpose> - </refnamediv> - - <refsynopsisdiv> - <cmdsynopsis> - <command>amqp-consume</command> - <arg choice="opt" rep="repeat"> - <replaceable>OPTION</replaceable> - </arg> - <arg choice="req"> - <replaceable>command</replaceable> - </arg> - <arg choice="opt" rep="repeat"> - <replaceable>args</replaceable> - </arg> - </cmdsynopsis> - </refsynopsisdiv> - - <refsect1> - <title>Description</title> - <para> - <command>amqp-consume</command> 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. - </para> - <para> - <command>amqp-consume</command> can consume from an - existing queue, or it can create a new queue. It can - optionally bind the queue to an existing exchange. - </para> - <para> - 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 <quote>no ack</quote> mode - (a.k.a. auto-ack mode) can be enable with the - <option>-A</option> option. - </para> - </refsect1> - - <refsect1> - <title>Options</title> - <variablelist> - <varlistentry> - <term><option>-q</option></term> - <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term> - <listitem> - <para> - The name of the queue to consume messages - from. - </para> - - <para> - If the <option>--queue</option> 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. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-e</option></term> - <term><option>--exchange</option>=<replaceable class="parameter">exchange name</replaceable></term> - <listitem> - <para> - Specifies that an exclusive queue should - be declared, and bound to the given exchange. - The specified exchange should already exist - unless the <option>--exchange-type</option> - option is used to request the creation of an - exchange. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-r</option></term> - <term><option>--routing-key</option>=<replaceable class="parameter">routing key</replaceable></term> - <listitem> - <para> - The routing key for binding. If omitted, an - empty routing key is assumed. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-d</option></term> - <term><option>--declare</option></term> - <listitem> - <para> - 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>--queue</option> option, but no - binding to an exchange is requested with the - <option>--exchange</option> option. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-A</option></term> - <term><option>--no-ack</option>=<replaceable class="parameter">routing key</replaceable></term> - <listitem> - <para> - Enable <quote>no ack</quote> mode: The AMQP - server will unconditionally acknowledge each - message that is delivered, regardless of - whether the target command exits successfully - or not. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>Examples</title> - <variablelist> - <varlistentry> - <term>Consume messages from an existing queue - <quote><systemitem - class="resource">myqueue</systemitem></quote>, and - output the message bodies on standard output via - <command>cat</command>:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-publish -q myqueue cat</userinput></screen> - </listitem> - </varlistentry> - - <varlistentry> - <term>Bind a new exclusive queue to an - exchange <quote><systemitem - class="resource">myexch</systemitem></quote>, and send - each message body to the script - <filename>myscript</filename>, automatically - acknowledging them on the server:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-consume -A -e myexch ./myscript</userinput></screen> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry> - describes connection-related options common to all the - RabbitMQ C Client tools. - </para> - </refsect1> -</refentry> diff --git a/tools/doc/declare_queue.xml b/tools/doc/declare_queue.xml deleted file mode 100644 index 7e9da32..0000000 --- a/tools/doc/declare_queue.xml +++ /dev/null @@ -1,122 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>amqp-declare-queue</refentrytitle> - <manvolnum>1</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>amqp-declare-queue</refname> - <refpurpose>Declare (create or assert the existence of) a queue on an AMQP server</refpurpose> - </refnamediv> - - <refsynopsisdiv> - <cmdsynopsis> - <command>amqp-declare-queue</command> - <arg choice="opt" rep="repeat"> - <replaceable>OPTION</replaceable> - </arg> - <arg choice="opt">-d</arg> - <arg choice="req">-q <replaceable>queue name</replaceable></arg> - </cmdsynopsis> - </refsynopsisdiv> - - <refsect1> - <title>Description</title> - <para> - <command>amqp-declare-queue</command> 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. - </para> - </refsect1> - - <refsect1> - <title>Options</title> - <variablelist> - <varlistentry> - <term><option>-q</option></term> - <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term> - <listitem> - <para> - The name of the queue to declare. If the - empty string is supplied, a fresh queue name - is generated by the server. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-d</option></term> - <term><option>--durable</option></term> - <listitem> - <para> - Causes the queue to be declared with the - "durable" flag set. Durable queues survive - server restarts. By default, queues are declared - in "transient" mode. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>Exit Status</title> - <para> - If the queue was successfully declared, the exit status is - 0. If an error occurs, the exit status is 1. - </para> - </refsect1> - - <refsect1> - <title>Examples</title> - <variablelist> - <varlistentry> - <term>Declare the durable queue <quote><systemitem - class="resource">myqueue</systemitem></quote>, and - display the name of the queue on standard output:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-declare-queue -d -q myqueue</userinput> -myqueue</screen> - </listitem> - </varlistentry> - <varlistentry> - <term>Declare a fresh, server-named transient queue, - and display the name of the queue on standard output - (use <citerefentry><refentrytitle>amqp-delete-queue</refentrytitle> - <manvolnum>1</manvolnum></citerefentry> to delete - it from the server once you're done):</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-declare-queue -q ""</userinput> -amq.gen-BW/wvociA8g6LFpb1PlqOA==</screen> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry> - describes connection-related options common to all the - RabbitMQ C Client tools. - </para> - </refsect1> -</refentry> diff --git a/tools/doc/delete_queue.xml b/tools/doc/delete_queue.xml deleted file mode 100644 index 69d03d8..0000000 --- a/tools/doc/delete_queue.xml +++ /dev/null @@ -1,94 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>amqp-delete-queue</refentrytitle> - <manvolnum>1</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>amqp-delete-queue</refname> - <refpurpose>Delete a queue from an AMQP server</refpurpose> - </refnamediv> - - <refsynopsisdiv> - <cmdsynopsis> - <command>amqp-delete-queue</command> - <arg choice="opt" rep="repeat"> - <replaceable>OPTION</replaceable> - </arg> - <arg choice="req">-q <replaceable>queue name</replaceable></arg> - </cmdsynopsis> - </refsynopsisdiv> - - <refsect1> - <title>Description</title> - <para> - <command>amqp-delete-queue</command> 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. - </para> - </refsect1> - - <refsect1> - <title>Options</title> - <variablelist> - <varlistentry> - <term><option>-q</option></term> - <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term> - <listitem> - <para> - The name of the queue to delete. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>Exit Status</title> - <para> - If the queue was successfully deleted, the exit status is - 0. If an error occurs, the exit status is 1. - </para> - </refsect1> - - <refsect1> - <title>Examples</title> - <variablelist> - <varlistentry> - <term>Delete the - queue <quote><systemitem class="resource">myqueue</systemitem></quote> - at a moment when it has 123 messages waiting on - it:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-delete-queue -q myqueue</userinput> -123</screen> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry> - describes connection-related options common to all the - RabbitMQ C Client tools. - </para> - </refsect1> -</refentry> diff --git a/tools/doc/get.xml b/tools/doc/get.xml deleted file mode 100644 index 9770a8b..0000000 --- a/tools/doc/get.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>amqp-get</refentrytitle> - <manvolnum>1</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>amqp-get</refname> - <refpurpose>Get a message from a queue on an AMQP server</refpurpose> - </refnamediv> - - <refsynopsisdiv> - <cmdsynopsis> - <command>amqp-get</command> - <arg choice="opt" rep="repeat"> - <replaceable>OPTION</replaceable> - </arg> - <arg choice="req">-q <replaceable>queue name</replaceable></arg> - </cmdsynopsis> - </refsynopsisdiv> - - <refsect1> - <title>Description</title> - <para> - <command>amqp-get</command> 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. - </para> - </refsect1> - - <refsect1> - <title>Options</title> - <variablelist> - <varlistentry> - <term><option>-q</option></term> - <term><option>--queue</option>=<replaceable class="parameter">queue name</replaceable></term> - <listitem> - <para> - The name of the queue to consume messages - from. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>Exit Status</title> - <para> - 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. - </para> - </refsect1> - - <refsect1> - <title>Examples</title> - <variablelist> - <varlistentry> - <term>Get a message from the queue <quote><systemitem - class="resource">myqueue</systemitem></quote>, and - display its body on standard output:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-get -q myqueue</userinput></screen> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry> - describes connection-related options common to all the - RabbitMQ C Client tools. - </para> - </refsect1> -</refentry> diff --git a/tools/doc/librabbitmq-tools.xml b/tools/doc/librabbitmq-tools.xml deleted file mode 100644 index 41f092a..0000000 --- a/tools/doc/librabbitmq-tools.xml +++ /dev/null @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>librabbitmq-tools</refentrytitle> - <manvolnum>7</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>librabbitmq-tools</refname> - <refpurpose>Command line AMQP tools</refpurpose> - </refnamediv> - - <refsect1> - <title>Description</title> - <para> - A set of command line AMQP tools based on <systemitem - class="library">librabbitmq</systemitem>. This page - describes common options and conventions used by all of - the tools. - </para> - </refsect1> - - <refsect1> - <title>Common Options</title> - <variablelist> - <varlistentry> - <term><option>-s</option></term> - <term><option>--server</option>=<replaceable class="parameter">hostname:port</replaceable></term> - <listitem> - <para> - 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). - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>--vhost</option>=<replaceable class="parameter">vhost</replaceable></term> - <listitem> - <para> - The AMQP vhost to specify when connnecting. - Defaults to <literal>/</literal>. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>--username</option>=<replaceable class="parameter">username</replaceable></term> - <listitem> - <para> - The username to authenticate to the AMQP server with. Defaults to <literal>guest</literal>. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>--password</option>=<replaceable class="parameter">password</replaceable></term> - <listitem> - <para> - The password to authenticate to the AMQP server with. Defaults to <literal>guest</literal>. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <simplelist type='inline'> - <member><citerefentry><refentrytitle>amqp-publish</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> - <member><citerefentry><refentrytitle>amqp-consume</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> - <member><citerefentry><refentrytitle>amqp-get</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> - </simplelist> - </para> - </refsect1> -</refentry> diff --git a/tools/doc/publish.xml b/tools/doc/publish.xml deleted file mode 100644 index d2e8d2e..0000000 --- a/tools/doc/publish.xml +++ /dev/null @@ -1,160 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.docbook.org/xml/4.5/docbookx.dtd" -[ -<!ENTITY date SYSTEM "man-date.ent" > -] -> -<refentry lang="en"> - <refentryinfo> - <productname>RabbitMQ C Client</productname> - <authorgroup> - <corpauthor>The RabbitMQ Team <<ulink url="mailto:info@rabbitmq.com"><email>info@rabbitmq.com</email></ulink>></corpauthor> - </authorgroup> - <date>&date;</date> - </refentryinfo> - - <refmeta> - <refentrytitle>amqp-publish</refentrytitle> - <manvolnum>1</manvolnum> - <refmiscinfo class="manual">RabbitMQ C Client</refmiscinfo> - </refmeta> - - <refnamediv> - <refname>amqp-publish</refname> - <refpurpose>Publish a message on an AMQP server</refpurpose> - </refnamediv> - - <refsynopsisdiv> - <cmdsynopsis> - <command>amqp-publish</command> - <arg choice="opt" rep="repeat"> - <replaceable>OPTION</replaceable> - </arg> - </cmdsynopsis> - </refsynopsisdiv> - - <refsect1> - <title>Description</title> - <para> - Publishes a message to an exchange on an AMQP server. - Options allow the various properties of the message and - parameters of the AMQP <function>basic.publish</function> - method to be specified. - </para> - <para> - By default, the message body is read from standard input. - Alternatively, the <option>-b</option> option allows the message - body to be provided as part of the command. - </para> - </refsect1> - - <refsect1> - <title>Options</title> - <variablelist> - <varlistentry> - <term><option>-e</option></term> - <term><option>--exchange</option>=<replaceable class="parameter">exchange name</replaceable></term> - <listitem> - <para> - The name of the exchange to publish to. If - omitted, the default exchange (also known as - the nameless exchange) is used. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-r</option></term> - <term><option>--routing-key</option>=<replaceable class="parameter">routing key</replaceable></term> - <listitem> - <para> - 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. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-p</option></term> - <term><option>--persistent</option></term> - <listitem> - <para> - Use the persistent delivery mode. Without - this option, non-persistent delivery is used. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-C</option></term> - <term><option>--content-type</option>=<replaceable class="parameter">MIME type</replaceable></term> - <listitem> - <para> - Specifies the content-type property for the - message. If omitted, the content-type - property is not set on the message. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-E</option></term> - <term><option>--content-encoding</option>=<replaceable class="parameter">content coding</replaceable></term> - <listitem> - <para> - Specifies the content-encoding property for - the message. If omitted, the content-encoding - property is not set on the message. - </para> - </listitem> - </varlistentry> - <varlistentry> - <term><option>-b</option></term> - <term><option>--body</option>=<replaceable class="parameter">message body</replaceable></term> - <listitem> - <para> - Specifies the message body. If omitted, the - message body is read from standard input. - </para> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>Examples</title> - <variablelist> - <varlistentry> - <term>Send a short message, consisting of the word - <quote><literal>Hello</literal></quote> to the queue - <quote><systemitem - class="resource">myqueue</systemitem></quote> via the - default exchange:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-publish -r myqueue -b Hello</userinput></screen> - </listitem> - </varlistentry> - - <varlistentry> - <term>Send some XML data from a file to the exchange - <quote><systemitem - class="resource">events</systemitem></quote>, with - persistent delivery mode, setting the content-type - property on the message to make the data format - explicit:</term> - <listitem> - <screen><prompt>$ </prompt><userinput>amqp-publish -e events -p -C text/xml <event.xml</userinput></screen> - </listitem> - </varlistentry> - </variablelist> - </refsect1> - - <refsect1> - <title>See also</title> - <para> - <citerefentry><refentrytitle>librabbitmq-tools</refentrytitle><manvolnum>7</manvolnum></citerefentry> - describes connection-related options common to all the - RabbitMQ C Client tools. - </para> - </refsect1> -</refentry> diff --git a/tools/get.c b/tools/get.c deleted file mode 100644 index 8f8e0d0..0000000 --- a/tools/get.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> - -#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 0917dae..0000000 --- a/tools/publish.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2009 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2009 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#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 8a02afb..0000000 --- a/tools/unix/process.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <unistd.h> -#include <errno.h> -#include <spawn.h> -#include <sys/wait.h> - -#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 ac2939d..0000000 --- a/tools/unix/process.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** 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 bce318b..0000000 --- a/tools/windows/compat.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> - -#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 8211b37..0000000 --- a/tools/windows/compat.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** 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 730a5b6..0000000 --- a/tools/windows/process.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <stdio.h> -#include <io.h> -#include <windows.h> - -#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 df276a7..0000000 --- a/tools/windows/process.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The Original Code is librabbitmq. - * - * The Initial Developers of the Original Code are LShift Ltd, Cohesive - * Financial Technologies LLC, and Rabbit Technologies Ltd. Portions - * created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, Cohesive - * Financial Technologies LLC, or Rabbit Technologies Ltd are Copyright - * (C) 2007-2008 LShift Ltd, Cohesive Financial Technologies LLC, and - * Rabbit Technologies Ltd. - * - * Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift - * Ltd. Portions created by Cohesive Financial Technologies LLC are - * Copyright (C) 2007-2010 Cohesive Financial Technologies - * LLC. Portions created by Rabbit Technologies Ltd are Copyright (C) - * 2007-2010 Rabbit Technologies Ltd. - * - * Portions created by Tony Garnock-Jones are Copyright (C) 2009-2010 - * LShift Ltd and Tony Garnock-Jones. - * - * All Rights Reserved. - * - * Contributor(s): ______________________________________. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU General Public License Version 2 or later (the "GPL"), in - * which case the provisions of the GPL are applicable instead of those - * above. If you wish to allow use of your version of this file only - * under the terms of the GPL, and not to allow others to use your - * version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the - * notice and other provisions required by the GPL. If you do not - * delete the provisions above, a recipient may use your version of - * this file under the terms of any one of the MPL or the GPL. - * - * ***** END LICENSE BLOCK ***** - */ - -#include <windef.h> - -struct pipeline { - HANDLE proc_handle; - int infd; -}; - -extern void pipeline(const char *const *argv, struct pipeline *pl); -extern int finish_pipeline(struct pipeline *pl); |