You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/11/25 21:01:09 UTC

[13/48] qpid-proton git commit: PROTON-1350 PROTON-1351: Introduce proton-c core library - Created new core proton library qpid-proton-core which only contains protocol processsing and no IO. - Rearranged source tree to separate core protocol code and

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/core/transport.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/transport.h b/proton-c/src/core/transport.h
new file mode 100644
index 0000000..66ebc51
--- /dev/null
+++ b/proton-c/src/core/transport.h
@@ -0,0 +1,31 @@
+#ifndef _PROTON_TRANSPORT_INTERNAL_H
+#define _PROTON_TRANSPORT_INTERNAL_H 1
+
+/*
+ *
+ * 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.
+ *
+ */
+
+void pn_delivery_map_init(pn_delivery_map_t *db, pn_sequence_t next);
+void pn_delivery_map_del(pn_delivery_map_t *db, pn_delivery_t *delivery);
+void pn_delivery_map_free(pn_delivery_map_t *db);
+void pn_unmap_handle(pn_session_t *ssn, pn_link_t *link);
+void pn_unmap_channel(pn_transport_t *transport, pn_session_t *ssn);
+
+#endif /* transport.h */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/core/types.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/types.c b/proton-c/src/core/types.c
new file mode 100644
index 0000000..dbd18d0
--- /dev/null
+++ b/proton-c/src/core/types.c
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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 <proton/types.h>
+
+pn_bytes_t pn_bytes(size_t size, const char *start)
+{
+  pn_bytes_t bytes = {size, start};
+  return bytes;
+}
+
+pn_rwbytes_t pn_rwbytes(size_t size, char *start)
+{
+  pn_rwbytes_t bytes = {size, start};
+  return bytes;
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/core/util.c
----------------------------------------------------------------------
diff --git a/proton-c/src/core/util.c b/proton-c/src/core/util.c
new file mode 100644
index 0000000..62eec9a
--- /dev/null
+++ b/proton-c/src/core/util.c
@@ -0,0 +1,165 @@
+/*
+ *
+ * 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 <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <proton/type_compat.h>
+#include <ctype.h>
+#include <string.h>
+#include <proton/error.h>
+#include <proton/types.h>
+#include "util.h"
+
+ssize_t pn_quote_data(char *dst, size_t capacity, const char *src, size_t size)
+{
+  int idx = 0;
+  for (unsigned i = 0; i < size; i++)
+  {
+    uint8_t c = src[i];
+    if (isprint(c)) {
+      if (idx < (int) (capacity - 1)) {
+        dst[idx++] = c;
+      } else {
+        if (idx > 0) {
+          dst[idx - 1] = '\0';
+        }
+        return PN_OVERFLOW;
+      }
+    } else {
+      if (idx < (int) (capacity - 4)) {
+        idx += sprintf(dst + idx, "\\x%.2x", c);
+      } else {
+        if (idx > 0) {
+          dst[idx - 1] = '\0';
+        }
+        return PN_OVERFLOW;
+      }
+    }
+  }
+
+  dst[idx] = '\0';
+  return idx;
+}
+
+int pn_quote(pn_string_t *dst, const char *src, size_t size)
+{
+  while (true) {
+    size_t str_size = pn_string_size(dst);
+    char *str = pn_string_buffer(dst) + str_size;
+    size_t capacity = pn_string_capacity(dst) - str_size;
+    ssize_t ssize = pn_quote_data(str, capacity, src, size);
+    if (ssize == PN_OVERFLOW) {
+      int err = pn_string_grow(dst, (str_size + capacity) ? 2*(str_size + capacity) : 16);
+      if (err) return err;
+    } else if (ssize >= 0) {
+      return pn_string_resize(dst, str_size + ssize);
+    } else {
+      return ssize;
+    }
+  }
+}
+
+void pn_fprint_data(FILE *stream, const char *bytes, size_t size)
+{
+  char buf[256];
+  ssize_t n = pn_quote_data(buf, 256, bytes, size);
+  if (n >= 0) {
+    fputs(buf, stream);
+  } else {
+    if (n == PN_OVERFLOW) {
+      fputs(buf, stream);
+      fputs("... (truncated)", stream);
+    }
+    else
+      fprintf(stderr, "pn_quote_data: %s\n", pn_code(n));
+  }
+}
+
+void pn_print_data(const char *bytes, size_t size)
+{
+  pn_fprint_data(stdout, bytes, size);
+}
+
+int pn_strcasecmp(const char *a, const char *b)
+{
+  int diff;
+  while (*b) {
+    char aa = *a++, bb = *b++;
+    diff = tolower(aa)-tolower(bb);
+    if ( diff!=0 ) return diff;
+  }
+  return *a;
+}
+
+int pn_strncasecmp(const char* a, const char* b, size_t len)
+{
+  int diff = 0;
+  while (*b && len > 0) {
+    char aa = *a++, bb = *b++;
+    diff = tolower(aa)-tolower(bb);
+    if ( diff!=0 ) return diff;
+    --len;
+  };
+  return len==0 ? diff : *a;
+}
+
+bool pn_env_bool(const char *name)
+{
+  char *v = getenv(name);
+  return v && (!pn_strcasecmp(v, "true") || !pn_strcasecmp(v, "1") ||
+               !pn_strcasecmp(v, "yes")  || !pn_strcasecmp(v, "on"));
+}
+
+char *pn_strdup(const char *src)
+{
+  if (!src) return NULL;
+  char *dest = (char *) malloc(strlen(src)+1);
+  if (!dest) return NULL;
+  return strcpy(dest, src);
+}
+
+char *pn_strndup(const char *src, size_t n)
+{
+  if (src) {
+    unsigned size = 0;
+    for (const char *c = src; size < n && *c; c++) {
+      size++;
+    }
+
+    char *dest = (char *) malloc(size + 1);
+    if (!dest) return NULL;
+    strncpy(dest, src, n);
+    dest[size] = '\0';
+    return dest;
+  } else {
+    return NULL;
+  }
+}
+
+// which timestamp will expire next, or zero if none set
+pn_timestamp_t pn_timestamp_min( pn_timestamp_t a, pn_timestamp_t b )
+{
+  if (a && b) return pn_min(a, b);
+  if (a) return a;
+  return b;
+}
+

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/core/util.h
----------------------------------------------------------------------
diff --git a/proton-c/src/core/util.h b/proton-c/src/core/util.h
new file mode 100644
index 0000000..b54f689
--- /dev/null
+++ b/proton-c/src/core/util.h
@@ -0,0 +1,123 @@
+#ifndef _PROTON_SRC_UTIL_H
+#define _PROTON_SRC_UTIL_H 1
+
+/*
+ *
+ * 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 <errno.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <proton/types.h>
+#include <proton/object.h>
+
+ssize_t pn_quote_data(char *dst, size_t capacity, const char *src, size_t size);
+int pn_quote(pn_string_t *dst, const char *src, size_t size);
+void pn_fprint_data(FILE *stream, const char *bytes, size_t size);
+void pn_print_data(const char *bytes, size_t size);
+bool pn_env_bool(const char *name);
+pn_timestamp_t pn_timestamp_min(pn_timestamp_t a, pn_timestamp_t b);
+
+char *pn_strdup(const char *src);
+char *pn_strndup(const char *src, size_t n);
+int pn_strcasecmp(const char* a, const char* b);
+int pn_strncasecmp(const char* a, const char* b, size_t len);
+
+#define DIE_IFR(EXPR, STRERR)                                           \
+  do {                                                                  \
+    int __code__ = (EXPR);                                              \
+    if (__code__) {                                                     \
+      fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__,       \
+              #EXPR, STRERR(__code__), __code__);                       \
+      exit(-1);                                                         \
+    }                                                                   \
+  } while (0)
+
+#define DIE_IFE(EXPR)                                                   \
+  do {                                                                  \
+    if ((EXPR) == -1) {                                                 \
+      int __code__ = errno;                                             \
+      fprintf(stderr, "%s:%d: %s: %s (%d)\n", __FILE__, __LINE__,       \
+              #EXPR, strerror(__code__), __code__);                     \
+      exit(-1);                                                         \
+    }                                                                   \
+  } while (0)
+
+
+#define LL_HEAD(ROOT, LIST) ((ROOT)-> LIST ## _head)
+#define LL_TAIL(ROOT, LIST) ((ROOT)-> LIST ## _tail)
+#define LL_ADD(ROOT, LIST, NODE)                              \
+  {                                                           \
+    (NODE)-> LIST ## _next = NULL;                            \
+    (NODE)-> LIST ## _prev = (ROOT)-> LIST ## _tail;          \
+    if (LL_TAIL(ROOT, LIST))                                  \
+      LL_TAIL(ROOT, LIST)-> LIST ## _next = (NODE);           \
+    LL_TAIL(ROOT, LIST) = (NODE);                             \
+    if (!LL_HEAD(ROOT, LIST)) LL_HEAD(ROOT, LIST) = (NODE);   \
+  }
+
+#define LL_POP(ROOT, LIST, TYPE)                              \
+  {                                                           \
+    if (LL_HEAD(ROOT, LIST)) {                                \
+      TYPE *_old = LL_HEAD(ROOT, LIST);                       \
+      LL_HEAD(ROOT, LIST) = LL_HEAD(ROOT, LIST)-> LIST ## _next; \
+      _old-> LIST ## _next = NULL;                            \
+      if (_old == LL_TAIL(ROOT, LIST)) {                      \
+        LL_TAIL(ROOT, LIST) = NULL;                           \
+      } else {                                                \
+        LL_HEAD(ROOT, LIST)-> LIST ## _prev = NULL;           \
+      }                                                       \
+    }                                                         \
+  }
+
+#define LL_REMOVE(ROOT, LIST, NODE)                                    \
+  {                                                                    \
+    if ((NODE)-> LIST ## _prev)                                        \
+      (NODE)-> LIST ## _prev-> LIST ## _next = (NODE)-> LIST ## _next; \
+    if ((NODE)-> LIST ## _next)                                        \
+      (NODE)-> LIST ## _next-> LIST ## _prev = (NODE)-> LIST ## _prev; \
+    if ((NODE) == LL_HEAD(ROOT, LIST))                                 \
+      LL_HEAD(ROOT, LIST) = (NODE)-> LIST ## _next;                    \
+    if ((NODE) == LL_TAIL(ROOT, LIST))                                 \
+      LL_TAIL(ROOT, LIST) = (NODE)-> LIST ## _prev;                    \
+  }
+
+#define pn_min(X,Y) ((X) > (Y) ? (Y) : (X))
+#define pn_max(X,Y) ((X) < (Y) ? (Y) : (X))
+
+#define PN_ENSURE(ARRAY, CAPACITY, COUNT, TYPE)                 \
+  while ((CAPACITY) < (COUNT)) {                                \
+    (CAPACITY) = (CAPACITY) ? 2 * (CAPACITY) : 16;              \
+    (ARRAY) = (TYPE *) realloc((ARRAY), (CAPACITY) * sizeof (TYPE));    \
+  }                                                             \
+
+#define PN_ENSUREZ(ARRAY, CAPACITY, COUNT, TYPE)           \
+  {                                                        \
+    size_t _old_capacity = (CAPACITY);                     \
+    PN_ENSURE(ARRAY, CAPACITY, COUNT, TYPE);               \
+    memset((ARRAY) + _old_capacity, 0,                     \
+           sizeof(TYPE)*((CAPACITY) - _old_capacity));     \
+  }
+
+#endif /* util.h */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/dispatch_actions.h
----------------------------------------------------------------------
diff --git a/proton-c/src/dispatch_actions.h b/proton-c/src/dispatch_actions.h
deleted file mode 100644
index bae8438..0000000
--- a/proton-c/src/dispatch_actions.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef _PROTON_DISPATCH_ACTIONS_H
-#define _PROTON_DISPATCH_ACTIONS_H 1
-
-/*
- *
- * 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 "dispatcher/dispatcher.h"
-
-#define AMQP_FRAME_TYPE (0)
-#define SASL_FRAME_TYPE (1)
-
-
-/* AMQP actions */
-int pn_do_open(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_begin(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_attach(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_transfer(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_flow(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_disposition(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_detach(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_end(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_close(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-
-/* SASL actions */
-int pn_do_init(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_mechanisms(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_challenge(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_response(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-int pn_do_outcome(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-
-#endif // _PROTON_DISPATCH_ACTIONS_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/dispatcher/dispatcher.c
----------------------------------------------------------------------
diff --git a/proton-c/src/dispatcher/dispatcher.c b/proton-c/src/dispatcher/dispatcher.c
deleted file mode 100644
index 0bd3f7b..0000000
--- a/proton-c/src/dispatcher/dispatcher.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- *
- * 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 "dispatcher.h"
-
-#include "framing/framing.h"
-#include "protocol.h"
-#include "engine/engine-internal.h"
-
-#include "dispatch_actions.h"
-
-int pni_bad_frame(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload) {
-  pn_transport_logf(transport, "Error dispatching frame: type: %d: Unknown performative", frame_type);
-  return PN_ERR;
-}
-
-int pni_bad_frame_type(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload) {
-    pn_transport_logf(transport, "Error dispatching frame: Unknown frame type: %d", frame_type);
-    return PN_ERR;
-}
-
-// We could use a table based approach here if we needed to dynamically
-// add new performatives
-static inline int pni_dispatch_action(pn_transport_t* transport, uint64_t lcode, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload)
-{
-  pn_action_t *action;
-  switch (frame_type) {
-  case AMQP_FRAME_TYPE:
-    /* Regular AMQP fames */
-    switch (lcode) {
-    case OPEN:            action = pn_do_open; break;
-    case BEGIN:           action = pn_do_begin; break;
-    case ATTACH:          action = pn_do_attach; break;
-    case FLOW:            action = pn_do_flow; break;
-    case TRANSFER:        action = pn_do_transfer; break;
-    case DISPOSITION:     action = pn_do_disposition; break;
-    case DETACH:          action = pn_do_detach; break;
-    case END:             action = pn_do_end; break;
-    case CLOSE:           action = pn_do_close; break;
-    default:              action = pni_bad_frame; break;
-    };
-    break;
-  case SASL_FRAME_TYPE:
-    /* SASL frames */
-    switch (lcode) {
-    case SASL_MECHANISMS: action = pn_do_mechanisms; break;
-    case SASL_INIT:       action = pn_do_init; break;
-    case SASL_CHALLENGE:  action = pn_do_challenge; break;
-    case SASL_RESPONSE:   action = pn_do_response; break;
-    case SASL_OUTCOME:    action = pn_do_outcome; break;
-    default:              action = pni_bad_frame; break;
-    };
-    break;
-  default:              action = pni_bad_frame_type; break;
-  };
-  return action(transport, frame_type, channel, args, payload);
-}
-
-static int pni_dispatch_frame(pn_transport_t * transport, pn_data_t *args, pn_frame_t frame)
-{
-  if (frame.size == 0) { // ignore null frames
-    if (transport->trace & PN_TRACE_FRM)
-      pn_transport_logf(transport, "%u <- (EMPTY FRAME)", frame.channel);
-    return 0;
-  }
-
-  ssize_t dsize = pn_data_decode(args, frame.payload, frame.size);
-  if (dsize < 0) {
-    pn_string_format(transport->scratch,
-                     "Error decoding frame: %s %s\n", pn_code(dsize),
-                     pn_error_text(pn_data_error(args)));
-    pn_quote(transport->scratch, frame.payload, frame.size);
-    pn_transport_log(transport, pn_string_get(transport->scratch));
-    return dsize;
-  }
-
-  uint8_t frame_type = frame.type;
-  uint16_t channel = frame.channel;
-  // XXX: assuming numeric -
-  // if we get a symbol we should map it to the numeric value and dispatch on that
-  uint64_t lcode;
-  bool scanned;
-  int e = pn_data_scan(args, "D?L.", &scanned, &lcode);
-  if (e) {
-    pn_transport_log(transport, "Scan error");
-    return e;
-  }
-  if (!scanned) {
-    pn_transport_log(transport, "Error dispatching frame");
-    return PN_ERR;
-  }
-  size_t payload_size = frame.size - dsize;
-  const char *payload_mem = payload_size ? frame.payload + dsize : NULL;
-  pn_bytes_t payload = {payload_size, payload_mem};
-
-  pn_do_trace(transport, channel, IN, args, payload_mem, payload_size);
-
-  int err = pni_dispatch_action(transport, lcode, frame_type, channel, args, &payload);
-
-  pn_data_clear(args);
-
-  return err;
-}
-
-ssize_t pn_dispatcher_input(pn_transport_t *transport, const char *bytes, size_t available, bool batch, bool *halt)
-{
-  size_t read = 0;
-
-  while (available && !*halt) {
-    pn_frame_t frame;
-
-    ssize_t n = pn_read_frame(&frame, bytes + read, available, transport->local_max_frame);
-    if (n > 0) {
-      read += n;
-      available -= n;
-      transport->input_frames_ct += 1;
-      int e = pni_dispatch_frame(transport, transport->args, frame);
-      if (e) return e;
-    } else if (n < 0) {
-      pn_do_error(transport, "amqp:connection:framing-error", "malformed frame");
-      return n;
-    } else {
-      break;
-    }
-
-    if (!batch) break;
-  }
-
-  return read;
-}
-
-ssize_t pn_dispatcher_output(pn_transport_t *transport, char *bytes, size_t size)
-{
-    int n = transport->available < size ? transport->available : size;
-    memmove(bytes, transport->output, n);
-    memmove(transport->output, transport->output + n, transport->available - n);
-    transport->available -= n;
-    // XXX: need to check for errors
-    return n;
-}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/dispatcher/dispatcher.h
----------------------------------------------------------------------
diff --git a/proton-c/src/dispatcher/dispatcher.h b/proton-c/src/dispatcher/dispatcher.h
deleted file mode 100644
index 29881b5..0000000
--- a/proton-c/src/dispatcher/dispatcher.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef _PROTON_DISPATCHER_H
-#define _PROTON_DISPATCHER_H 1
-
-/*
- *
- * 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.
- *
- */
-
-#ifndef __cplusplus
-#include <stdbool.h>
-#endif
-
-#include "proton/codec.h"
-#include "proton/types.h"
-
-typedef int (pn_action_t)(pn_transport_t *transport, uint8_t frame_type, uint16_t channel, pn_data_t *args, const pn_bytes_t *payload);
-
-ssize_t pn_dispatcher_input(pn_transport_t* transport, const char* bytes, size_t available, bool batch, bool* halt);
-ssize_t pn_dispatcher_output(pn_transport_t *transport, char *bytes, size_t size);
-
-#endif /* dispatcher.h */

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/encodings.h.py
----------------------------------------------------------------------
diff --git a/proton-c/src/encodings.h.py b/proton-c/src/encodings.h.py
new file mode 100644
index 0000000..9f08c6c
--- /dev/null
+++ b/proton-c/src/encodings.h.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+#
+# 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.
+#
+
+from __future__ import print_function
+import mllib, optparse, os, sys
+
+xml = os.path.join(os.path.dirname(__file__), "types.xml")
+doc = mllib.xml_parse(xml)
+
+print("/* generated from %s */" % xml)
+print("#ifndef _PROTON_ENCODINGS_H")
+print("#define _PROTON_ENCODINGS_H 1")
+print()
+print("#define PNE_DESCRIPTOR          (0x00)")
+
+for enc in doc.query["amqp/section/type/encoding"]:
+  name = enc["@name"] or enc.parent["@name"]
+  # XXX: a bit hacky
+  if name == "ieee-754":
+    name = enc.parent["@name"]
+  cname = "PNE_" + name.replace("-", "_").upper()
+  print("#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"]))
+
+print()
+print("#endif /* encodings.h */")

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/engine/connection_engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/connection_engine.c b/proton-c/src/engine/connection_engine.c
deleted file mode 100644
index 5d184a1..0000000
--- a/proton-c/src/engine/connection_engine.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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 "engine-internal.h"
-
-#include <proton/connection.h>
-#include <proton/connection_engine.h>
-#include <proton/transport.h>
-#include <string.h>
-
-int pn_connection_engine_init(pn_connection_engine_t* e) {
-    memset(e, 0, sizeof(*e));
-    e->connection = pn_connection();
-    e->transport = pn_transport();
-    e->collector = pn_collector();
-    if (!e->connection || !e->transport || !e->collector) {
-        pn_connection_engine_final(e);
-        return PN_OUT_OF_MEMORY;
-    }
-    pn_connection_collect(e->connection, e->collector);
-    return PN_OK;
-}
-
-void pn_connection_engine_final(pn_connection_engine_t* e) {
-    if (e->transport && e->connection) {
-        pn_transport_unbind(e->transport);
-        pn_decref(e->transport);
-    }
-    if (e->collector)
-        pn_collector_free(e->collector); /* Break cycle with connection */
-    if (e->connection)
-        pn_decref(e->connection);
-    memset(e, 0, sizeof(*e));
-}
-
-pn_rwbytes_t pn_connection_engine_read_buffer(pn_connection_engine_t* e) {
-    ssize_t cap = pn_transport_capacity(e->transport);
-    if (cap > 0)
-        return pn_rwbytes(cap, pn_transport_tail(e->transport));
-    else
-        return pn_rwbytes(0, 0);
-}
-
-void pn_connection_engine_read_done(pn_connection_engine_t* e, size_t n) {
-    if (n > 0)
-        pn_transport_process(e->transport, n);
-}
-
-void pn_connection_engine_read_close(pn_connection_engine_t* e) {
-    pn_transport_close_tail(e->transport);
-}
-
-pn_bytes_t pn_connection_engine_write_buffer(pn_connection_engine_t* e) {
-    ssize_t pending = pn_transport_pending(e->transport);
-    if (pending > 0)
-        return pn_bytes(pending, pn_transport_head(e->transport));
-    else
-        return pn_bytes(0, 0);
-}
-
-void pn_connection_engine_write_done(pn_connection_engine_t* e, size_t n) {
-    if (n > 0)
-        pn_transport_pop(e->transport, n);
-}
-
-void pn_connection_engine_write_close(pn_connection_engine_t* e){
-    pn_transport_close_head(e->transport);
-}
-
-void pn_connection_engine_disconnected(pn_connection_engine_t* e) {
-    pn_connection_engine_read_close(e);
-    pn_connection_engine_write_close(e);
-}
-
-static void log_event(pn_connection_engine_t *engine, pn_event_t* event) {
-    if (event && engine->transport->trace & PN_TRACE_EVT) {
-        pn_string_t *str = pn_string(NULL);
-        pn_inspect(event, str);
-        pn_transport_log(engine->transport, pn_string_get(str));
-        pn_free(str);
-    }
-}
-
-pn_event_t* pn_connection_engine_dispatch(pn_connection_engine_t* e) {
-    if (e->event) {             /* Already returned */
-        if (pn_event_type(e->event) == PN_CONNECTION_INIT)
-            pn_transport_bind(e->transport, e->connection);
-        pn_collector_pop(e->collector);
-    }
-    e->event = pn_collector_peek(e->collector);
-    log_event(e, e->event);
-    return e->event;
-}
-
-bool pn_connection_engine_finished(pn_connection_engine_t* e) {
-    return pn_transport_closed(e->transport) && (pn_collector_peek(e->collector) == NULL);
-}
-
-pn_connection_t* pn_connection_engine_connection(pn_connection_engine_t* e) {
-    return e->connection;
-}
-
-pn_transport_t* pn_connection_engine_transport(pn_connection_engine_t* e) {
-    return e->transport;
-}
-
-pn_condition_t* pn_connection_engine_condition(pn_connection_engine_t* e) {
-    return pn_transport_condition(e->transport);
-}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a5850716/proton-c/src/engine/engine-internal.h
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/engine-internal.h b/proton-c/src/engine/engine-internal.h
deleted file mode 100644
index 761a840..0000000
--- a/proton-c/src/engine/engine-internal.h
+++ /dev/null
@@ -1,374 +0,0 @@
-#ifndef _PROTON_ENGINE_INTERNAL_H
-#define _PROTON_ENGINE_INTERNAL_H 1
-
-/*
- *
- * 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 <proton/object.h>
-#include <proton/engine.h>
-#include <proton/types.h>
-#include "buffer.h"
-#include "dispatcher/dispatcher.h"
-#include "util.h"
-
-typedef enum pn_endpoint_type_t {CONNECTION, SESSION, SENDER, RECEIVER} pn_endpoint_type_t;
-
-typedef struct pn_endpoint_t pn_endpoint_t;
-
-struct pn_condition_t {
-  pn_string_t *name;
-  pn_string_t *description;
-  pn_data_t *info;
-};
-
-struct pn_endpoint_t {
-  pn_endpoint_type_t type;
-  pn_state_t state;
-  pn_error_t *error;
-  pn_condition_t condition;
-  pn_condition_t remote_condition;
-  pn_endpoint_t *endpoint_next;
-  pn_endpoint_t *endpoint_prev;
-  pn_endpoint_t *transport_next;
-  pn_endpoint_t *transport_prev;
-  int refcount; // when this hits zero we generate a final event
-  bool modified;
-  bool freed;
-  bool referenced;
-};
-
-typedef struct {
-  pn_sequence_t id;
-  bool sent;
-  bool init;
-} pn_delivery_state_t;
-
-typedef struct {
-  pn_sequence_t next;
-  pn_hash_t *deliveries;
-} pn_delivery_map_t;
-
-typedef struct {
-  // XXX: stop using negative numbers
-  uint32_t local_handle;
-  uint32_t remote_handle;
-  pn_sequence_t delivery_count;
-  pn_sequence_t link_credit;
-} pn_link_state_t;
-
-typedef struct {
-  // XXX: stop using negative numbers
-  uint16_t local_channel;
-  uint16_t remote_channel;
-  bool incoming_init;
-  pn_delivery_map_t incoming;
-  pn_delivery_map_t outgoing;
-  pn_sequence_t incoming_transfer_count;
-  pn_sequence_t incoming_window;
-  pn_sequence_t remote_incoming_window;
-  pn_sequence_t outgoing_transfer_count;
-  pn_sequence_t outgoing_window;
-  pn_hash_t *local_handles;
-  pn_hash_t *remote_handles;
-
-  uint64_t disp_code;
-  bool disp_settled;
-  bool disp_type;
-  pn_sequence_t disp_first;
-  pn_sequence_t disp_last;
-  bool disp;
-} pn_session_state_t;
-
-typedef struct pn_io_layer_t {
-  ssize_t (*process_input)(struct pn_transport_t *transport, unsigned int layer, const char *, size_t);
-  ssize_t (*process_output)(struct pn_transport_t *transport, unsigned int layer, char *, size_t);
-  void (*handle_error)(struct pn_transport_t* transport, unsigned int layer);
-  pn_timestamp_t (*process_tick)(struct pn_transport_t *transport, unsigned int layer, pn_timestamp_t);
-  size_t (*buffered_output)(struct pn_transport_t *transport);  // how much output is held
-} pn_io_layer_t;
-
-extern const pn_io_layer_t pni_passthru_layer;
-extern const pn_io_layer_t ssl_layer;
-extern const pn_io_layer_t sasl_header_layer;
-extern const pn_io_layer_t sasl_write_header_layer;
-
-// Bit flag defines for the protocol layers
-typedef uint8_t pn_io_layer_flags_t;
-#define LAYER_NONE     0
-#define LAYER_AMQP1    1
-#define LAYER_AMQPSASL 2
-#define LAYER_AMQPSSL  4
-#define LAYER_SSL      8
-
-typedef struct pni_sasl_t pni_sasl_t;
-typedef struct pni_ssl_t pni_ssl_t;
-
-struct pn_transport_t {
-  pn_tracer_t tracer;
-  pni_sasl_t *sasl;
-  pni_ssl_t *ssl;
-  pn_connection_t *connection;  // reference counted
-  char *remote_container;
-  char *remote_hostname;
-  pn_data_t *remote_offered_capabilities;
-  pn_data_t *remote_desired_capabilities;
-  pn_data_t *remote_properties;
-  pn_data_t *disp_data;
-  //#define PN_DEFAULT_MAX_FRAME_SIZE (16*1024)
-#define PN_DEFAULT_MAX_FRAME_SIZE (0)  /* for now, allow unlimited size */
-  uint32_t   local_max_frame;
-  uint32_t   remote_max_frame;
-  pn_condition_t remote_condition;
-  pn_condition_t condition;
-  pn_error_t *error;
-
-#define PN_IO_LAYER_CT 3
-  const pn_io_layer_t *io_layers[PN_IO_LAYER_CT];
-
-  /* dead remote detection */
-  pn_millis_t local_idle_timeout;
-  pn_millis_t remote_idle_timeout;
-  pn_timestamp_t dead_remote_deadline;
-  uint64_t last_bytes_input;
-
-  /* keepalive */
-  pn_timestamp_t keepalive_deadline;
-  uint64_t last_bytes_output;
-
-  pn_hash_t *local_channels;
-  pn_hash_t *remote_channels;
-
-
-  /* scratch area */
-  pn_string_t *scratch;
-  pn_data_t *args;
-  pn_data_t *output_args;
-  pn_buffer_t *frame;  // frame under construction
-  // Temporary
-  size_t capacity;
-  size_t available; /* number of raw bytes pending output */
-  char *output;
-
-  /* statistics */
-  uint64_t bytes_input;
-  uint64_t bytes_output;
-  uint64_t output_frames_ct;
-  uint64_t input_frames_ct;
-
-  /* output buffered for send */
-  size_t output_size;
-  size_t output_pending;
-  char *output_buf;
-
-  /* input from peer */
-  size_t input_size;
-  size_t input_pending;
-  char *input_buf;
-
-  pn_record_t *context;
-
-  pn_trace_t trace;
-
-  /*
-   * The maximum channel number can be constrained in several ways:
-   *   1. an unchangeable limit imposed by this library code
-   *   2. a limit imposed by the remote peer when the connection is opened,
-   *      which this app must honor
-   *   3. a limit imposed by this app, which may be raised and lowered
-   *      until the OPEN frame is sent.
-   * These constraints are all summed up in channel_max, below.
-   */
-  #define PN_IMPL_CHANNEL_MAX  32767
-  uint16_t local_channel_max;
-  uint16_t remote_channel_max;
-  uint16_t channel_max;
-
-  pn_io_layer_flags_t allowed_layers;
-  pn_io_layer_flags_t present_layers;
-
-  bool freed;
-  bool open_sent;
-  bool open_rcvd;
-  bool close_sent;
-  bool close_rcvd;
-  bool tail_closed;      // input stream closed by driver
-  bool head_closed;
-  bool done_processing; // if true, don't call pn_process again
-  bool posted_idle_timeout;
-  bool server;
-  bool halt;
-  bool auth_required;
-  bool authenticated;
-  bool encryption_required;
-
-  bool referenced;
-};
-
-struct pn_connection_t {
-  pn_endpoint_t endpoint;
-  pn_endpoint_t *endpoint_head;
-  pn_endpoint_t *endpoint_tail;
-  pn_endpoint_t *transport_head;  // reference counted
-  pn_endpoint_t *transport_tail;
-  pn_list_t *sessions;
-  pn_list_t *freed;
-  pn_transport_t *transport;
-  pn_delivery_t *work_head;
-  pn_delivery_t *work_tail;
-  pn_delivery_t *tpwork_head;  // reference counted
-  pn_delivery_t *tpwork_tail;
-  pn_string_t *container;
-  pn_string_t *hostname;
-  pn_string_t *auth_user;
-  pn_string_t *auth_password;
-  pn_data_t *offered_capabilities;
-  pn_data_t *desired_capabilities;
-  pn_data_t *properties;
-  pn_collector_t *collector;
-  pn_record_t *context;
-  pn_list_t *delivery_pool;
-};
-
-struct pn_session_t {
-  pn_endpoint_t endpoint;
-  pn_connection_t *connection;  // reference counted
-  pn_list_t *links;
-  pn_list_t *freed;
-  pn_record_t *context;
-  size_t incoming_capacity;
-  pn_sequence_t incoming_bytes;
-  pn_sequence_t outgoing_bytes;
-  pn_sequence_t incoming_deliveries;
-  pn_sequence_t outgoing_deliveries;
-  pn_sequence_t outgoing_window;
-  pn_session_state_t state;
-};
-
-struct pn_terminus_t {
-  pn_string_t *address;
-  pn_data_t *properties;
-  pn_data_t *capabilities;
-  pn_data_t *outcomes;
-  pn_data_t *filter;
-  pn_durability_t durability;
-  pn_expiry_policy_t expiry_policy;
-  pn_seconds_t timeout;
-  pn_terminus_type_t type;
-  pn_distribution_mode_t distribution_mode;
-  bool dynamic;
-};
-
-struct pn_link_t {
-  pn_endpoint_t endpoint;
-  pn_terminus_t source;
-  pn_terminus_t target;
-  pn_terminus_t remote_source;
-  pn_terminus_t remote_target;
-  pn_link_state_t state;
-  pn_string_t *name;
-  pn_session_t *session;  // reference counted
-  pn_delivery_t *unsettled_head;
-  pn_delivery_t *unsettled_tail;
-  pn_delivery_t *current;
-  pn_record_t *context;
-  size_t unsettled_count;
-  pn_sequence_t available;
-  pn_sequence_t credit;
-  pn_sequence_t queued;
-  int drained; // number of drained credits
-  uint8_t snd_settle_mode;
-  uint8_t rcv_settle_mode;
-  uint8_t remote_snd_settle_mode;
-  uint8_t remote_rcv_settle_mode;
-  bool drain_flag_mode; // receiver only
-  bool drain;
-  bool detached;
-};
-
-struct pn_disposition_t {
-  pn_condition_t condition;
-  uint64_t type;
-  pn_data_t *data;
-  pn_data_t *annotations;
-  uint64_t section_offset;
-  uint32_t section_number;
-  bool failed;
-  bool undeliverable;
-  bool settled;
-};
-
-struct pn_delivery_t {
-  pn_disposition_t local;
-  pn_disposition_t remote;
-  pn_link_t *link;  // reference counted
-  pn_buffer_t *tag;
-  pn_delivery_t *unsettled_next;
-  pn_delivery_t *unsettled_prev;
-  pn_delivery_t *work_next;
-  pn_delivery_t *work_prev;
-  pn_delivery_t *tpwork_next;
-  pn_delivery_t *tpwork_prev;
-  pn_delivery_state_t state;
-  pn_buffer_t *bytes;
-  pn_record_t *context;
-  bool updated;
-  bool settled; // tracks whether we're in the unsettled list or not
-  bool work;
-  bool tpwork;
-  bool done;
-  bool referenced;
-};
-
-#define PN_SET_LOCAL(OLD, NEW)                                          \
-  (OLD) = ((OLD) & PN_REMOTE_MASK) | (NEW)
-
-#define PN_SET_REMOTE(OLD, NEW)                                         \
-  (OLD) = ((OLD) & PN_LOCAL_MASK) | (NEW)
-
-void pn_link_dump(pn_link_t *link);
-
-void pn_dump(pn_connection_t *conn);
-void pn_transport_sasl_init(pn_transport_t *transport);
-
-void pn_condition_init(pn_condition_t *condition);
-void pn_condition_tini(pn_condition_t *condition);
-void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint, bool emit);
-void pn_real_settle(pn_delivery_t *delivery);  // will free delivery if link is freed
-void pn_clear_tpwork(pn_delivery_t *delivery);
-void pn_work_update(pn_connection_t *connection, pn_delivery_t *delivery);
-void pn_clear_modified(pn_connection_t *connection, pn_endpoint_t *endpoint);
-void pn_connection_bound(pn_connection_t *conn);
-void pn_connection_unbound(pn_connection_t *conn);
-int pn_do_error(pn_transport_t *transport, const char *condition, const char *fmt, ...);
-void pn_set_error_layer(pn_transport_t *transport);
-void pn_session_unbound(pn_session_t* ssn);
-void pn_link_unbound(pn_link_t* link);
-void pn_ep_incref(pn_endpoint_t *endpoint);
-void pn_ep_decref(pn_endpoint_t *endpoint);
-
-int pn_post_frame(pn_transport_t *transport, uint8_t type, uint16_t ch, const char *fmt, ...);
-
-typedef enum {IN, OUT} pn_dir_t;
-
-void pn_do_trace(pn_transport_t *transport, uint16_t ch, pn_dir_t dir,
-                 pn_data_t *args, const char *payload, size_t size);
-
-#endif /* engine-internal.h */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org