Author: rhs
Date: Tue Jul 3 20:46:39 2012
New Revision: 1356929
URL: http://svn.apache.org/viewvc?rev=1356929&view=rev
Log:
added proton-dump utility
Added:
qpid/proton/trunk/proton-c/src/proton-dump.c
Modified:
qpid/proton/trunk/proton-c/CMakeLists.txt
Modified: qpid/proton/trunk/proton-c/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/CMakeLists.txt?rev=1356929&r1=1356928&r2=1356929&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/CMakeLists.txt (original)
+++ qpid/proton/trunk/proton-c/CMakeLists.txt Tue Jul 3 20:46:39 2012
@@ -60,10 +60,13 @@ endif (SWIG_FOUND)
add_executable (proton src/proton.c)
target_link_libraries (proton qpidproton ${LINK_DEPS})
+add_executable (proton-dump src/proton-dump.c)
+target_link_libraries (proton-dump qpidproton ${LINK_DEPS})
+
add_subdirectory(docs/api)
set_target_properties (
- qpidproton proton
+ qpidproton proton proton-dump
PROPERTIES
COMPILE_FLAGS "-Wall -Werror -pedantic-errors -std=c99 -g -Iinclude -fPIC"
)
Added: qpid/proton/trunk/proton-c/src/proton-dump.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/proton-dump.c?rev=1356929&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/src/proton-dump.c (added)
+++ qpid/proton/trunk/proton-c/src/proton-dump.c Tue Jul 3 20:46:39 2012
@@ -0,0 +1,102 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <proton/buffer.h>
+#include <proton/codec.h>
+#include <proton/error.h>
+#include <proton/framing.h>
+#include "util.h"
+
+int dump(const char *file)
+{
+ FILE *in = fopen(file, "r");
+ if (!in) err(1, "%s", file);
+
+ pn_buffer_t *buf = pn_buffer(1024);
+ pn_data_t *data = pn_data(16);
+ bool header = false;
+
+ char bytes[1024];
+ size_t n;
+ while ((n = fread(bytes, 1, 1024, in))) {
+ int err = pn_buffer_append(buf, bytes, n);
+ if (err) return err;
+
+ while (true) {
+ pn_bytes_t available = pn_buffer_bytes(buf);
+ if (!available.size) break;
+
+ if (!header) {
+ if (available.size >= 8) {
+ pn_buffer_trim(buf, 8, 0);
+ available = pn_buffer_bytes(buf);
+ header = true;
+ } else {
+ break;
+ }
+ }
+
+ pn_frame_t frame;
+ size_t consumed = pn_read_frame(&frame, available.start, available.size);
+ if (consumed) {
+ size_t dsize = frame.size;
+ pn_data_clear(data);
+ err = pn_data_decode(data, frame.payload, &dsize);
+ if (err) {
+ fprintf(stderr, "Error decoding frame: %s\n", pn_code(err));
+ pn_fprint_data(stderr, frame.payload, frame.size);
+ fprintf(stderr, "\n");
+ return err;
+ } else {
+ pn_data_print(data);
+ printf("\n");
+ }
+ pn_buffer_trim(buf, consumed, 0);
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (ferror(in)) err(1, "%s", file);
+ if (pn_buffer_size(buf) > 0) {
+ fprintf(stderr, "Trailing data: ");
+ pn_bytes_t b = pn_buffer_bytes(buf);
+ pn_fprint_data(stderr, b.start, b.size);
+ fprintf(stderr, "\n");
+ }
+
+ fclose(in);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ for (int i = 1; i < argc; i++) {
+ int err = dump(argv[i]);
+ if (err) return err;
+ }
+
+ return 0;
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]