http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/core/transport.h ---------------------------------------------------------------------- diff --git a/proton-c/src/core/transport.h b/proton-c/src/core/transport.h deleted file mode 100644 index 66ebc51..0000000 --- a/proton-c/src/core/transport.h +++ /dev/null @@ -1,31 +0,0 @@ -#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-j/blob/2f85988e/proton-c/src/core/types.c ---------------------------------------------------------------------- diff --git a/proton-c/src/core/types.c b/proton-c/src/core/types.c deleted file mode 100644 index dbd18d0..0000000 --- a/proton-c/src/core/types.c +++ /dev/null @@ -1,34 +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 <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-j/blob/2f85988e/proton-c/src/core/util.c ---------------------------------------------------------------------- diff --git a/proton-c/src/core/util.c b/proton-c/src/core/util.c deleted file mode 100644 index 62eec9a..0000000 --- a/proton-c/src/core/util.c +++ /dev/null @@ -1,165 +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 <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-j/blob/2f85988e/proton-c/src/core/util.h ---------------------------------------------------------------------- diff --git a/proton-c/src/core/util.h b/proton-c/src/core/util.h deleted file mode 100644 index b54f689..0000000 --- a/proton-c/src/core/util.h +++ /dev/null @@ -1,123 +0,0 @@ -#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-j/blob/2f85988e/proton-c/src/encodings.h.py ---------------------------------------------------------------------- diff --git a/proton-c/src/encodings.h.py b/proton-c/src/encodings.h.py deleted file mode 100644 index 9f08c6c..0000000 --- a/proton-c/src/encodings.h.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/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-j/blob/2f85988e/proton-c/src/extra/parser.c ---------------------------------------------------------------------- diff --git a/proton-c/src/extra/parser.c b/proton-c/src/extra/parser.c deleted file mode 100644 index 36fb4fb..0000000 --- a/proton-c/src/extra/parser.c +++ /dev/null @@ -1,423 +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 <proton/parser.h> - -#include "platform/platform.h" -#include "scanner.h" - -#include <proton/error.h> - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -struct pn_parser_t { - pn_scanner_t *scanner; - char *atoms; - size_t size; - size_t capacity; - int error_code; -}; - -pn_parser_t *pn_parser() -{ - pn_parser_t *parser = (pn_parser_t *) malloc(sizeof(pn_parser_t)); - if (parser != NULL) { - parser->scanner = pn_scanner(); - parser->atoms = NULL; - parser->size = 0; - parser->capacity = 0; - } - return parser; -} - -static void pni_parser_ensure(pn_parser_t *parser, size_t size) -{ - while (parser->capacity - parser->size < size) { - parser->capacity = parser->capacity ? 2 * parser->capacity : 1024; - parser->atoms = (char *) realloc(parser->atoms, parser->capacity); - } -} - -int pn_parser_err(pn_parser_t *parser, int code, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - int err = pn_scanner_verr(parser->scanner, code, fmt, ap); - va_end(ap); - return err; -} - -int pn_parser_errno(pn_parser_t *parser) -{ - return pn_scanner_errno(parser->scanner); -} - -const char *pn_parser_error(pn_parser_t *parser) -{ - return pn_scanner_error(parser->scanner); -} - -void pn_parser_free(pn_parser_t *parser) -{ - if (parser) { - pn_scanner_free(parser->scanner); - free(parser->atoms); - free(parser); - } -} - -static int pni_parser_shift(pn_parser_t *parser) -{ - return pn_scanner_shift(parser->scanner); -} - -static pn_token_t pni_parser_token(pn_parser_t *parser) -{ - return pn_scanner_token(parser->scanner); -} - -static int pni_parser_value(pn_parser_t *parser, pn_data_t *data); - -static int pni_parser_descriptor(pn_parser_t *parser, pn_data_t *data) -{ - if (pni_parser_token(parser).type == PN_TOK_AT) { - int err = pni_parser_shift(parser); - if (err) return err; - - err = pn_data_put_described(data); - if (err) return pn_parser_err(parser, err, "error writing described"); - pn_data_enter(data); - for (int i = 0; i < 2; i++) { - err = pni_parser_value(parser, data); - if (err) return err; - } - pn_data_exit(data); - return 0; - } else { - return pn_parser_err(parser, PN_ERR, "expecting '@'"); - } -} - -static int pni_parser_map(pn_parser_t *parser, pn_data_t *data) -{ - if (pni_parser_token(parser).type == PN_TOK_LBRACE) { - int err = pni_parser_shift(parser); - if (err) return err; - - err = pn_data_put_map(data); - if (err) return pn_parser_err(parser, err, "error writing map"); - - pn_data_enter(data); - - if (pni_parser_token(parser).type != PN_TOK_RBRACE) { - while (true) { - err = pni_parser_value(parser, data); - if (err) return err; - - if (pni_parser_token(parser).type == PN_TOK_EQUAL) { - err = pni_parser_shift(parser); - if (err) return err; - } else { - return pn_parser_err(parser, PN_ERR, "expecting '='"); - } - - err = pni_parser_value(parser, data); - if (err) return err; - - if (pni_parser_token(parser).type == PN_TOK_COMMA) { - err = pni_parser_shift(parser); - if (err) return err; - } else { - break; - } - } - } - - pn_data_exit(data); - - if (pni_parser_token(parser).type == PN_TOK_RBRACE) { - return pni_parser_shift(parser); - } else { - return pn_parser_err(parser, PN_ERR, "expecting '}'"); - } - } else { - return pn_parser_err(parser, PN_ERR, "expecting '{'"); - } -} - -static int pni_parser_list(pn_parser_t *parser, pn_data_t *data) -{ - int err; - - if (pni_parser_token(parser).type == PN_TOK_LBRACKET) { - err = pni_parser_shift(parser); - if (err) return err; - - err = pn_data_put_list(data); - if (err) return pn_parser_err(parser, err, "error writing list"); - - pn_data_enter(data); - - if (pni_parser_token(parser).type != PN_TOK_RBRACKET) { - while (true) { - err = pni_parser_value(parser, data); - if (err) return err; - - if (pni_parser_token(parser).type == PN_TOK_COMMA) { - err = pni_parser_shift(parser); - if (err) return err; - } else { - break; - } - } - } - - pn_data_exit(data); - - if (pni_parser_token(parser).type == PN_TOK_RBRACKET) { - return pni_parser_shift(parser); - } else { - return pn_parser_err(parser, PN_ERR, "expecting ']'"); - } - } else { - return pn_parser_err(parser, PN_ERR, "expecting '['"); - } -} - -static void pni_parser_append_tok(pn_parser_t *parser, char *dst, int *idx) -{ - memcpy(dst + *idx, pni_parser_token(parser).start, pni_parser_token(parser).size); - *idx += pni_parser_token(parser).size; -} - -static int pni_parser_number(pn_parser_t *parser, pn_data_t *data) -{ - bool dbl = false; - char number[1024]; - int idx = 0; - int err; - - bool negate = false; - - if (pni_parser_token(parser).type == PN_TOK_NEG || pni_parser_token(parser).type == PN_TOK_POS) { - if (pni_parser_token(parser).type == PN_TOK_NEG) - negate = !negate; - err = pni_parser_shift(parser); - if (err) return err; - } - - if (pni_parser_token(parser).type == PN_TOK_FLOAT || pni_parser_token(parser).type == PN_TOK_INT) { - dbl = pni_parser_token(parser).type == PN_TOK_FLOAT; - pni_parser_append_tok(parser, number, &idx); - err = pni_parser_shift(parser); - if (err) return err; - } else { - return pn_parser_err(parser, PN_ERR, "expecting FLOAT or INT"); - } - - number[idx] = '\0'; - - if (dbl) { - double value = atof(number); - if (negate) { - value = -value; - } - err = pn_data_put_double(data, value); - if (err) return pn_parser_err(parser, err, "error writing double"); - } else { - int64_t value = pn_i_atoll(number); - if (negate) { - value = -value; - } - err = pn_data_put_long(data, value); - if (err) return pn_parser_err(parser, err, "error writing long"); - } - - return 0; -} - -static int pni_parser_unquote(pn_parser_t *parser, char *dst, const char *src, size_t *n) -{ - size_t idx = 0; - bool escape = false; - int start, end; - if (src[0] != '"') { - if (src[1] == '"') { - start = 2; - end = *n - 1; - } else { - start = 1; - end = *n; - } - } else { - start = 1; - end = *n - 1; - } - for (int i = start; i < end; i++) - { - char c = src[i]; - if (escape) { - switch (c) { - case '"': - case '\\': - case '/': - dst[idx++] = c; - escape = false; - break; - case 'b': - dst[idx++] = '\b'; - break; - case 'f': - dst[idx++] = '\f'; - break; - case 'n': - dst[idx++] = '\n'; - break; - case 'r': - dst[idx++] = '\r'; - break; - case 't': - dst[idx++] = '\t'; - break; - case 'x': - { - char n1 = toupper(src[i+1]); - char n2 = n1 ? toupper(src[i+2]) : 0; - if (!n2) { - return pn_parser_err(parser, PN_ERR, "truncated escape code"); - } - int d1 = isdigit(n1) ? n1 - '0' : n1 - 'A' + 10; - int d2 = isdigit(n2) ? n2 - '0' : n2 - 'A' + 10; - dst[idx++] = d1*16 + d2; - i += 2; - } - break; - // XXX: need to handle unicode escapes: 'u' - default: - return pn_parser_err(parser, PN_ERR, "unrecognized escape code"); - } - escape = false; - } else { - switch (c) - { - case '\\': - escape = true; - break; - default: - dst[idx++] = c; - break; - } - } - } - dst[idx++] = '\0'; - *n = idx; - return 0; -} - -static int pni_parser_value(pn_parser_t *parser, pn_data_t *data) -{ - int err; - size_t n; - char *dst; - - pn_token_t tok = pni_parser_token(parser); - - switch (tok.type) - { - case PN_TOK_AT: - return pni_parser_descriptor(parser, data); - case PN_TOK_LBRACE: - return pni_parser_map(parser, data); - case PN_TOK_LBRACKET: - return pni_parser_list(parser, data); - case PN_TOK_BINARY: - case PN_TOK_SYMBOL: - case PN_TOK_STRING: - n = tok.size; - pni_parser_ensure(parser, n); - dst = parser->atoms + parser->size; - err = pni_parser_unquote(parser, dst, tok.start, &n); - if (err) return err; - parser->size += n; - switch (tok.type) { - case PN_TOK_BINARY: - err = pn_data_put_binary(data, pn_bytes(n - 1, dst)); - break; - case PN_TOK_STRING: - err = pn_data_put_string(data, pn_bytes(n - 1, dst)); - break; - case PN_TOK_SYMBOL: - err = pn_data_put_symbol(data, pn_bytes(n - 1, dst)); - break; - default: - return pn_parser_err(parser, PN_ERR, "internal error"); - } - if (err) return pn_parser_err(parser, err, "error writing string/binary/symbol"); - return pni_parser_shift(parser); - case PN_TOK_POS: - case PN_TOK_NEG: - case PN_TOK_FLOAT: - case PN_TOK_INT: - return pni_parser_number(parser, data); - case PN_TOK_TRUE: - err = pn_data_put_bool(data, true); - if (err) return pn_parser_err(parser, err, "error writing boolean"); - return pni_parser_shift(parser); - case PN_TOK_FALSE: - err = pn_data_put_bool(data, false); - if (err) return pn_parser_err(parser, err, "error writing boolean"); - return pni_parser_shift(parser); - case PN_TOK_NULL: - err = pn_data_put_null(data); - if (err) return pn_parser_err(parser, err, "error writing null"); - return pni_parser_shift(parser); - default: - return pn_parser_err(parser, PN_ERR, "expecting one of '[', '{', STRING, " - "SYMBOL, BINARY, true, false, null, NUMBER"); - } -} - -static int pni_parser_parse_r(pn_parser_t *parser, pn_data_t *data) -{ - while (true) { - int err; - switch (pni_parser_token(parser).type) - { - case PN_TOK_EOS: - return 0; - case PN_TOK_ERR: - return PN_ERR; - default: - err = pni_parser_value(parser, data); - if (err) return err; - } - } -} - -int pn_parser_parse(pn_parser_t *parser, const char *str, pn_data_t *data) -{ - int err = pn_scanner_start(parser->scanner, str); - if (err) return err; - parser->size = 0; - return pni_parser_parse_r(parser, data); -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/extra/scanner.c ---------------------------------------------------------------------- diff --git a/proton-c/src/extra/scanner.c b/proton-c/src/extra/scanner.c deleted file mode 100644 index beb7322..0000000 --- a/proton-c/src/extra/scanner.c +++ /dev/null @@ -1,399 +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 "scanner.h" - -#include "platform/platform.h" - -#include <proton/error.h> -#ifndef __cplusplus -#include <stdbool.h> -#endif -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#define ERROR_SIZE (1024) - -struct pn_scanner_t { - const char *input; - const char *position; - pn_token_t token; - char *atoms; - size_t size; - size_t capacity; - pn_error_t *error; -}; - -static const char *pni_token_type(pn_token_type_t type) -{ - switch (type) - { - case PN_TOK_LBRACE: return "LBRACE"; - case PN_TOK_RBRACE: return "RBRACE"; - case PN_TOK_LBRACKET: return "LBRACKET"; - case PN_TOK_RBRACKET: return "RBRACKET"; - case PN_TOK_EQUAL: return "EQUAL"; - case PN_TOK_COMMA: return "COMMA"; - case PN_TOK_POS: return "POS"; - case PN_TOK_NEG: return "NEG"; - case PN_TOK_DOT: return "DOT"; - case PN_TOK_AT: return "AT"; - case PN_TOK_DOLLAR: return "DOLLAR"; - case PN_TOK_BINARY: return "BINARY"; - case PN_TOK_STRING: return "STRING"; - case PN_TOK_SYMBOL: return "SYMBOL"; - case PN_TOK_ID: return "ID"; - case PN_TOK_FLOAT: return "FLOAT"; - case PN_TOK_INT: return "INT"; - case PN_TOK_TRUE: return "TRUE"; - case PN_TOK_FALSE: return "FALSE"; - case PN_TOK_NULL: return "NULL"; - case PN_TOK_EOS: return "EOS"; - case PN_TOK_ERR: return "ERR"; - default: return "<UNKNOWN>"; - } -} - -pn_scanner_t *pn_scanner() -{ - pn_scanner_t *scanner = (pn_scanner_t *) malloc(sizeof(pn_scanner_t)); - if (scanner) { - scanner->input = NULL; - scanner->error = pn_error(); - } - return scanner; -} - -void pn_scanner_free(pn_scanner_t *scanner) -{ - if (scanner) { - pn_error_free(scanner->error); - free(scanner); - } -} - -pn_token_t pn_scanner_token(pn_scanner_t *scanner) -{ - if (scanner) { - return scanner->token; - } else { - pn_token_t tok = {PN_TOK_ERR, 0, (size_t)0}; - return tok; - } -} - -void pn_scanner_line_info(pn_scanner_t *scanner, int *line, int *col) -{ - *line = 1; - *col = 0; - - for (const char *c = scanner->input; *c && c <= scanner->token.start; c++) { - if (*c == '\n') { - *line += 1; - *col = -1; - } else { - *col += 1; - } - } -} - -int pn_scanner_err(pn_scanner_t *scanner, int code, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - int err = pn_scanner_verr(scanner, code, fmt, ap); - va_end(ap); - return err; -} - -int pn_scanner_verr(pn_scanner_t *scanner, int code, const char *fmt, va_list ap) -{ - char error[ERROR_SIZE]; - - int line, col; - pn_scanner_line_info(scanner, &line, &col); - int size = scanner->token.size; - int ln = pni_snprintf(error, ERROR_SIZE, - "input line %i column %i %s:'%.*s': ", line, col, - pni_token_type(scanner->token.type), - size, scanner->token.start); - if (ln >= ERROR_SIZE) { - return pn_scanner_err(scanner, code, "error info truncated"); - } else if (ln < 0) { - error[0] = '\0'; - } - - int n = pni_snprintf(error + ln, ERROR_SIZE - ln, fmt, ap); - - if (n >= ERROR_SIZE - ln) { - return pn_scanner_err(scanner, code, "error info truncated"); - } else if (n < 0) { - error[0] = '\0'; - } - - return pn_error_set(scanner->error, code, error); -} - -int pn_scanner_errno(pn_scanner_t *scanner) -{ - return pn_error_code(scanner->error); -} - -const char *pn_scanner_error(pn_scanner_t *scanner) -{ - return pn_error_text(scanner->error); -} - -static void pni_scanner_emit(pn_scanner_t *scanner, pn_token_type_t type, const char *start, size_t size) -{ - scanner->token.type = type; - scanner->token.start = start; - scanner->token.size = size; -} - -static int pni_scanner_quoted(pn_scanner_t *scanner, const char *str, int start, - pn_token_type_t type) -{ - bool escape = false; - - for (int i = start; true; i++) { - char c = str[i]; - if (escape) { - escape = false; - } else { - switch (c) { - case '\0': - case '"': - pni_scanner_emit(scanner, c ? type : PN_TOK_ERR, - str, c ? i + 1 : i); - return c ? 0 : pn_scanner_err(scanner, PN_ERR, "missmatched quote"); - case '\\': - escape = true; - break; - } - } - } -} - -static int pni_scanner_binary(pn_scanner_t *scanner, const char *str) -{ - return pni_scanner_quoted(scanner, str, 2, PN_TOK_BINARY); -} - -static int pni_scanner_string(pn_scanner_t *scanner, const char *str) -{ - return pni_scanner_quoted(scanner, str, 1, PN_TOK_STRING); -} - -static int pni_scanner_alpha_end(pn_scanner_t *scanner, const char *str, int start) -{ - for (int i = start; true; i++) { - char c = str[i]; - if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) { - return i; - } - } -} - -static int pni_scanner_alpha(pn_scanner_t *scanner, const char *str) -{ - int n = pni_scanner_alpha_end(scanner, str, 0); - pn_token_type_t type; - if (!strncmp(str, "true", n)) { - type = PN_TOK_TRUE; - } else if (!strncmp(str, "false", n)) { - type = PN_TOK_FALSE; - } else if (!strncmp(str, "null", n)) { - type = PN_TOK_NULL; - } else { - type = PN_TOK_ID; - } - - pni_scanner_emit(scanner, type, str, n); - return 0; -} - -static int pni_scanner_symbol(pn_scanner_t *scanner, const char *str) -{ - char c = str[1]; - - if (c == '"') { - return pni_scanner_quoted(scanner, str, 2, PN_TOK_SYMBOL); - } else { - int n = pni_scanner_alpha_end(scanner, str, 1); - pni_scanner_emit(scanner, PN_TOK_SYMBOL, str, n); - return 0; - } -} - -static int pni_scanner_number(pn_scanner_t *scanner, const char *str) -{ - bool dot = false; - bool exp = false; - - int i = 0; - - if (str[i] == '+' || str[i] == '-') { - i++; - } - - for ( ; true; i++) { - char c = str[i]; - switch (c) { - case '0': case '1': case '2': case '3': case '4': case '5': case '6': - case '7': case '8': case '9': - continue; - case '.': - if (dot) { - pni_scanner_emit(scanner, PN_TOK_FLOAT, str, i); - return 0; - } else { - dot = true; - } - continue; - case 'e': - case 'E': - if (exp) { - pni_scanner_emit(scanner, PN_TOK_FLOAT, str, i); - return 0; - } else { - dot = true; - exp = true; - if (str[i+1] == '+' || str[i+1] == '-') { - i++; - } - continue; - } - default: - if (dot || exp) { - pni_scanner_emit(scanner, PN_TOK_FLOAT, str, i); - return 0; - } else { - pni_scanner_emit(scanner, PN_TOK_INT, str, i); - return 0; - } - } - } -} - -static int pni_scanner_single(pn_scanner_t *scanner, const char *str, pn_token_type_t type) -{ - pni_scanner_emit(scanner, type, str, 1); - return 0; -} - -int pn_scanner_start(pn_scanner_t *scanner, const char *input) -{ - if (!scanner || !input) return PN_ARG_ERR; - scanner->input = input; - scanner->position = input; - return pn_scanner_scan(scanner); -} - -int pn_scanner_scan(pn_scanner_t *scanner) -{ - const char *str = scanner->position; - char n; - - for (char c; true; str++) { - c = *str; - switch (c) - { - case '{': - return pni_scanner_single(scanner, str, PN_TOK_LBRACE); - case '}': - return pni_scanner_single(scanner, str, PN_TOK_RBRACE); - case'[': - return pni_scanner_single(scanner, str, PN_TOK_LBRACKET); - case ']': - return pni_scanner_single(scanner, str, PN_TOK_RBRACKET); - case '=': - return pni_scanner_single(scanner, str, PN_TOK_EQUAL); - case ',': - return pni_scanner_single(scanner, str, PN_TOK_COMMA); - case '.': - n = *(str+1); - if ((n >= '0' && n <= '9')) { - return pni_scanner_number(scanner, str); - } else { - return pni_scanner_single(scanner, str, PN_TOK_DOT); - } - case '@': - return pni_scanner_single(scanner, str, PN_TOK_AT); - case '$': - return pni_scanner_single(scanner, str, PN_TOK_DOLLAR); - case '-': - n = *(str+1); - if ((n >= '0' && n <= '9') || n == '.') { - return pni_scanner_number(scanner, str); - } else { - return pni_scanner_single(scanner, str, PN_TOK_NEG); - } - case '+': - n = *(str+1); - if ((n >= '0' && n <= '9') || n == '.') { - return pni_scanner_number(scanner, str); - } else { - return pni_scanner_single(scanner, str, PN_TOK_POS); - } - case ' ': case '\t': case '\r': case '\v': case '\f': case '\n': - break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': - case '7': case '8': case '9': - return pni_scanner_number(scanner, str); - case ':': - return pni_scanner_symbol(scanner, str); - case '"': - return pni_scanner_string(scanner, str); - case 'b': - if (str[1] == '"') { - return pni_scanner_binary(scanner, str); - } - case 'a': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': - case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': - case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': - case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - return pni_scanner_alpha(scanner, str); - case '\0': - pni_scanner_emit(scanner, PN_TOK_EOS, str, 0); - return PN_EOS; - default: - pni_scanner_emit(scanner, PN_TOK_ERR, str, 1); - return pn_scanner_err(scanner, PN_ERR, "illegal character"); - } - } -} - -int pn_scanner_shift(pn_scanner_t *scanner) -{ - scanner->position = scanner->token.start + scanner->token.size; - int err = pn_scanner_scan(scanner); - if (err == PN_EOS) { - return 0; - } else { - return err; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/extra/scanner.h ---------------------------------------------------------------------- diff --git a/proton-c/src/extra/scanner.h b/proton-c/src/extra/scanner.h deleted file mode 100644 index 218babe..0000000 --- a/proton-c/src/extra/scanner.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef PROTON_SCANNER_H -#define PROTON_SCANNER_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/import_export.h> -#include <stddef.h> -#include <stdarg.h> - -typedef enum { - PN_TOK_LBRACE, - PN_TOK_RBRACE, - PN_TOK_LBRACKET, - PN_TOK_RBRACKET, - PN_TOK_EQUAL, - PN_TOK_COMMA, - PN_TOK_POS, - PN_TOK_NEG, - PN_TOK_DOT, - PN_TOK_AT, - PN_TOK_DOLLAR, - PN_TOK_BINARY, - PN_TOK_STRING, - PN_TOK_SYMBOL, - PN_TOK_ID, - PN_TOK_FLOAT, - PN_TOK_INT, - PN_TOK_TRUE, - PN_TOK_FALSE, - PN_TOK_NULL, - PN_TOK_EOS, - PN_TOK_ERR -} pn_token_type_t; - -typedef struct pn_scanner_t pn_scanner_t; - -typedef struct { - pn_token_type_t type; - const char *start; - size_t size; -} pn_token_t; - -PN_EXTERN pn_scanner_t *pn_scanner(void); -PN_EXTERN void pn_scanner_free(pn_scanner_t *scanner); -PN_EXTERN pn_token_t pn_scanner_token(pn_scanner_t *scanner); -PN_EXTERN int pn_scanner_err(pn_scanner_t *scanner, int code, const char *fmt, ...); -PN_EXTERN int pn_scanner_verr(pn_scanner_t *scanner, int code, const char *fmt, va_list ap); -PN_EXTERN void pn_scanner_line_info(pn_scanner_t *scanner, int *line, int *col); -PN_EXTERN int pn_scanner_errno(pn_scanner_t *scanner); -PN_EXTERN const char *pn_scanner_error(pn_scanner_t *scanner); -PN_EXTERN int pn_scanner_start(pn_scanner_t *scanner, const char *input); -PN_EXTERN int pn_scanner_scan(pn_scanner_t *scanner); -PN_EXTERN int pn_scanner_shift(pn_scanner_t *scanner); - -#endif /* scanner.h */ http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/extra/url.c ---------------------------------------------------------------------- diff --git a/proton-c/src/extra/url.c b/proton-c/src/extra/url.c deleted file mode 100644 index c1ce628..0000000 --- a/proton-c/src/extra/url.c +++ /dev/null @@ -1,272 +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 "proton/url.h" -#include "proton/object.h" - -#include "core/util.h" - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - - -/** URL-encode src and append to dst. */ -static void pni_urlencode(pn_string_t *dst, const char* src) { - static const char *bad = "@:/"; - - if (!src) return; - const char *i = src; - const char *j = strpbrk(i, bad); - while (j) { - pn_string_addf(dst, "%.*s", (int)(j-i), i); - pn_string_addf(dst, "%%%02X", (int)*j); - i = j + 1; - j = strpbrk(i, bad); - } - pn_string_addf(dst, "%s", i); -} - -// Low level url parser -static void pni_urldecode(const char *src, char *dst) -{ - const char *in = src; - char *out = dst; - while (*in != '\0') - { - if ('%' == *in) - { - if ((in[1] != '\0') && (in[2] != '\0')) - { - char esc[3]; - esc[0] = in[1]; - esc[1] = in[2]; - esc[2] = '\0'; - unsigned long d = strtoul(esc, NULL, 16); - *out = (char)d; - in += 3; - out++; - } - else - { - *out = *in; - in++; - out++; - } - } - else - { - *out = *in; - in++; - out++; - } - } - *out = '\0'; -} - -void pni_parse_url(char *url, char **scheme, char **user, char **pass, char **host, char **port, char **path) -{ - if (!url) return; - - char *slash = strchr(url, '/'); - - if (slash && slash>url) { - char *scheme_end = strstr(slash-1, "://"); - - if (scheme_end && scheme_end<slash) { - *scheme_end = '\0'; - *scheme = url; - url = scheme_end + 3; - slash = strchr(url, '/'); - } - } - - if (slash) { - *slash = '\0'; - *path = slash + 1; - } - - char *at = strchr(url, '@'); - if (at) { - *at = '\0'; - char *up = url; - *user = up; - url = at + 1; - char *colon = strchr(up, ':'); - if (colon) { - *colon = '\0'; - *pass = colon + 1; - } - } - - *host = url; - char *open = (*url == '[') ? url : 0; - if (open) { - char *close = strchr(open, ']'); - if (close) { - *host = open + 1; - *close = '\0'; - url = close + 1; - } - } - - char *colon = strchr(url, ':'); - if (colon) { - *colon = '\0'; - *port = colon + 1; - } - - if (*user) pni_urldecode(*user, *user); - if (*pass) pni_urldecode(*pass, *pass); -} - -struct pn_url_t { - char *scheme; - char *username; - char *password; - char *host; - char *port; - char *path; - pn_string_t *str; -}; - -/** Internal use only, returns the pn_string_t. Public function is pn_url_str() */ -static pn_string_t *pn_url_string(pn_url_t* url) -{ - pn_url_str(url); /* Make sure str is up to date */ - return url->str; -} - -static void pn_url_finalize(void *object) -{ - pn_url_t *url = (pn_url_t *) object; - pn_url_clear(url); - pn_free(url->str); -} - -static uintptr_t pn_url_hashcode(void *object) -{ - pn_url_t *url = (pn_url_t *) object; - return pn_hashcode(pn_url_string(url)); -} - -static intptr_t pn_url_compare(void *oa, void *ob) -{ - pn_url_t *a = (pn_url_t *) oa; - pn_url_t *b = (pn_url_t *) ob; - return pn_compare(pn_url_string(a), pn_url_string(b)); -} - - -static int pn_url_inspect(void *obj, pn_string_t *dst) -{ - pn_url_t *url = (pn_url_t *) obj; - int err = 0; - err = pn_string_addf(dst, "Url("); if (err) return err; - err = pn_inspect(pn_url_string(url), dst); if (err) return err; - return pn_string_addf(dst, ")"); -} - -#define pn_url_initialize NULL - - -pn_url_t *pn_url() { - static const pn_class_t clazz = PN_CLASS(pn_url); - pn_url_t *url = (pn_url_t*) pn_class_new(&clazz, sizeof(pn_url_t)); - if (!url) return NULL; - memset(url, 0, sizeof(*url)); - url->str = pn_string(NULL); - return url; -} - -/** Parse a string URL as a pn_url_t. - *@param[in] url A URL string. - *@return The parsed pn_url_t or NULL if url is not a valid URL string. - */ -pn_url_t *pn_url_parse(const char *str) { - if (!str || !*str) /* Empty string or NULL is illegal. */ - return NULL; - - pn_url_t *url = pn_url(); - char *str2 = pn_strdup(str); - pni_parse_url(str2, &url->scheme, &url->username, &url->password, &url->host, &url->port, &url->path); - url->scheme = pn_strdup(url->scheme); - url->username = pn_strdup(url->username); - url->password = pn_strdup(url->password); - url->host = (url->host && !*url->host) ? NULL : pn_strdup(url->host); - url->port = pn_strdup(url->port); - url->path = pn_strdup(url->path); - - free(str2); - return url; -} - -/** Free a URL */ -void pn_url_free(pn_url_t *url) { pn_free(url); } - -/** Clear the contents of the URL. */ -void pn_url_clear(pn_url_t *url) { - pn_url_set_scheme(url, NULL); - pn_url_set_username(url, NULL); - pn_url_set_password(url, NULL); - pn_url_set_host(url, NULL); - pn_url_set_port(url, NULL); - pn_url_set_path(url, NULL); - pn_string_clear(url->str); -} - -/** Return the string form of a URL. */ -const char *pn_url_str(pn_url_t *url) { - if (pn_string_get(url->str) == NULL) { - pn_string_set(url->str, ""); - if (url->scheme) pn_string_addf(url->str, "%s://", url->scheme); - if (url->username) pni_urlencode(url->str, url->username); - if (url->password) { - pn_string_addf(url->str, ":"); - pni_urlencode(url->str, url->password); - } - if (url->username || url->password) pn_string_addf(url->str, "@"); - if (url->host) { - if (strchr(url->host, ':')) pn_string_addf(url->str, "[%s]", url->host); - else pn_string_addf(url->str, "%s", url->host); - } - if (url->port) pn_string_addf(url->str, ":%s", url->port); - if (url->path) pn_string_addf(url->str, "/%s", url->path); - } - return pn_string_get(url->str); -} - -const char *pn_url_get_scheme(pn_url_t *url) { return url->scheme; } -const char *pn_url_get_username(pn_url_t *url) { return url->username; } -const char *pn_url_get_password(pn_url_t *url) { return url->password; } -const char *pn_url_get_host(pn_url_t *url) { return url->host; } -const char *pn_url_get_port(pn_url_t *url) { return url->port; } -const char *pn_url_get_path(pn_url_t *url) { return url->path; } - -#define SET(part) free(url->part); url->part = pn_strdup(part); pn_string_clear(url->str) -void pn_url_set_scheme(pn_url_t *url, const char *scheme) { SET(scheme); } -void pn_url_set_username(pn_url_t *url, const char *username) { SET(username); } -void pn_url_set_password(pn_url_t *url, const char *password) { SET(password); } -void pn_url_set_host(pn_url_t *url, const char *host) { SET(host); } -void pn_url_set_port(pn_url_t *url, const char *port) { SET(port); } -void pn_url_set_path(pn_url_t *url, const char *path) { SET(path); } - - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/handlers/flowcontroller.c ---------------------------------------------------------------------- diff --git a/proton-c/src/handlers/flowcontroller.c b/proton-c/src/handlers/flowcontroller.c deleted file mode 100644 index d7cc3b9..0000000 --- a/proton-c/src/handlers/flowcontroller.c +++ /dev/null @@ -1,71 +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 <proton/link.h> -#include <proton/handlers.h> -#include <assert.h> - -typedef struct { - int window; - int drained; -} pni_flowcontroller_t; - -pni_flowcontroller_t *pni_flowcontroller(pn_handler_t *handler) { - return (pni_flowcontroller_t *) pn_handler_mem(handler); -} - -static void pni_topup(pn_link_t *link, int window) { - int delta = window - pn_link_credit(link); - pn_link_flow(link, delta); -} - -static void pn_flowcontroller_dispatch(pn_handler_t *handler, pn_event_t *event, pn_event_type_t type) { - pni_flowcontroller_t *fc = pni_flowcontroller(handler); - int window = fc->window; - pn_link_t *link = pn_event_link(event); - - switch (pn_event_type(event)) { - case PN_LINK_LOCAL_OPEN: - case PN_LINK_REMOTE_OPEN: - case PN_LINK_FLOW: - case PN_DELIVERY: - if (pn_link_is_receiver(link)) { - fc->drained += pn_link_drained(link); - if (!fc->drained) { - pni_topup(link, window); - } - } - break; - default: - break; - } -} - -pn_flowcontroller_t *pn_flowcontroller(int window) { - // XXX: a window of 1 doesn't work because we won't necessarily get - // notified when the one allowed delivery is settled - assert(window > 1); - pn_flowcontroller_t *handler = pn_handler_new(pn_flowcontroller_dispatch, sizeof(pni_flowcontroller_t), NULL); - pni_flowcontroller_t *fc = pni_flowcontroller(handler); - fc->window = window; - fc->drained = 0; - return handler; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/handlers/handshaker.c ---------------------------------------------------------------------- diff --git a/proton-c/src/handlers/handshaker.c b/proton-c/src/handlers/handshaker.c deleted file mode 100644 index ea406c1..0000000 --- a/proton-c/src/handlers/handshaker.c +++ /dev/null @@ -1,103 +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 <proton/connection.h> -#include <proton/session.h> -#include <proton/link.h> -#include <proton/handlers.h> -#include <assert.h> - -typedef struct { - pn_map_t *handlers; -} pni_handshaker_t; - -pni_handshaker_t *pni_handshaker(pn_handler_t *handler) { - return (pni_handshaker_t *) pn_handler_mem(handler); -} - -static void pn_handshaker_finalize(pn_handler_t *handler) { - pni_handshaker_t *handshaker = pni_handshaker(handler); - pn_free(handshaker->handlers); -} - -static void pn_handshaker_dispatch(pn_handler_t *handler, pn_event_t *event, pn_event_type_t type) { - switch (type) { - case PN_CONNECTION_REMOTE_OPEN: - { - pn_connection_t *conn = pn_event_connection(event); - if (pn_connection_state(conn) & PN_LOCAL_UNINIT) { - pn_connection_open(conn); - } - } - break; - case PN_SESSION_REMOTE_OPEN: - { - pn_session_t *ssn = pn_event_session(event); - if (pn_session_state(ssn) & PN_LOCAL_UNINIT) { - pn_session_open(ssn); - } - } - break; - case PN_LINK_REMOTE_OPEN: - { - pn_link_t *link = pn_event_link(event); - if (pn_link_state(link) & PN_LOCAL_UNINIT) { - pn_terminus_copy(pn_link_source(link), pn_link_remote_source(link)); - pn_terminus_copy(pn_link_target(link), pn_link_remote_target(link)); - pn_link_open(link); - } - } - break; - case PN_CONNECTION_REMOTE_CLOSE: - { - pn_connection_t *conn = pn_event_connection(event); - if (!(pn_connection_state(conn) & PN_LOCAL_CLOSED)) { - pn_connection_close(conn); - } - } - break; - case PN_SESSION_REMOTE_CLOSE: - { - pn_session_t *ssn = pn_event_session(event); - if (!(pn_session_state(ssn) & PN_LOCAL_CLOSED)) { - pn_session_close(ssn); - } - } - break; - case PN_LINK_REMOTE_CLOSE: - { - pn_link_t *link = pn_event_link(event); - if (!(pn_link_state(link) & PN_LOCAL_CLOSED)) { - pn_link_close(link); - } - } - break; - default: - break; - } -} - -pn_handshaker_t *pn_handshaker(void) { - pn_handler_t *handler = pn_handler_new(pn_handshaker_dispatch, sizeof(pni_handshaker_t), pn_handshaker_finalize); - pni_handshaker_t *handshaker = pni_handshaker(handler); - handshaker->handlers = NULL; - return handler; -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/handlers/iohandler.c ---------------------------------------------------------------------- diff --git a/proton-c/src/handlers/iohandler.c b/proton-c/src/handlers/iohandler.c deleted file mode 100644 index db18c0c..0000000 --- a/proton-c/src/handlers/iohandler.c +++ /dev/null @@ -1,115 +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 "reactor/io.h" -#include "reactor/reactor.h" -#include "reactor/selector.h" - -#include <proton/handlers.h> -#include <proton/transport.h> -#include <assert.h> - -static const char pni_selector_handle = 0; - -#define PN_SELECTOR ((pn_handle_t) &pni_selector_handle) - -void pni_handle_quiesced(pn_reactor_t *reactor, pn_selector_t *selector) { - // check if we are still quiesced, other handlers of - // PN_REACTOR_QUIESCED could have produced more events to process - if (!pn_reactor_quiesced(reactor)) { return; } - pn_selector_select(selector, pn_reactor_get_timeout(reactor)); - pn_selectable_t *sel; - int events; - pn_reactor_mark(reactor); - while ((sel = pn_selector_next(selector, &events))) { - if (events & PN_READABLE) { - pn_selectable_readable(sel); - } - if (events & PN_WRITABLE) { - pn_selectable_writable(sel); - } - if (events & PN_EXPIRED) { - pn_selectable_expired(sel); - } - if (events & PN_ERROR) { - pn_selectable_error(sel); - } - } - pn_reactor_yield(reactor); -} - -void pni_handle_transport(pn_reactor_t *reactor, pn_event_t *event); -void pni_handle_open(pn_reactor_t *reactor, pn_event_t *event); -void pni_handle_bound(pn_reactor_t *reactor, pn_event_t *event); - -static void pn_iodispatch(pn_iohandler_t *handler, pn_event_t *event, pn_event_type_t type) { - pn_reactor_t *reactor = pn_event_reactor(event); - pn_record_t *record = pn_reactor_attachments(reactor); - pn_selector_t *selector = (pn_selector_t *) pn_record_get(record, PN_SELECTOR); - if (!selector) { - selector = pn_io_selector(pni_reactor_io(reactor)); - pn_record_def(record, PN_SELECTOR, PN_OBJECT); - pn_record_set(record, PN_SELECTOR, selector); - pn_decref(selector); - } - switch (type) { - case PN_SELECTABLE_INIT: - { - pn_selectable_t *sel = (pn_selectable_t *) pn_event_context(event); - pn_selector_add(selector, sel); - } - break; - case PN_SELECTABLE_UPDATED: - { - pn_selectable_t *sel = (pn_selectable_t *) pn_event_context(event); - pn_selector_update(selector, sel); - } - break; - case PN_SELECTABLE_FINAL: - { - pn_selectable_t *sel = (pn_selectable_t *) pn_event_context(event); - pn_selector_remove(selector, sel); - pn_selectable_release(sel); - } - break; - case PN_CONNECTION_LOCAL_OPEN: - pni_handle_open(reactor, event); - break; - case PN_CONNECTION_BOUND: - pni_handle_bound(reactor, event); - break; - case PN_TRANSPORT: - pni_handle_transport(reactor, event); - break; - case PN_TRANSPORT_CLOSED: - pn_transport_unbind(pn_event_transport(event)); - break; - case PN_REACTOR_QUIESCED: - pni_handle_quiesced(reactor, selector); - break; - default: - break; - } -} - -pn_iohandler_t *pn_iohandler(void) { - return pn_handler(pn_iodispatch); -} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/libqpid-proton-core.pc.in ---------------------------------------------------------------------- diff --git a/proton-c/src/libqpid-proton-core.pc.in b/proton-c/src/libqpid-proton-core.pc.in deleted file mode 100644 index ff99108..0000000 --- a/proton-c/src/libqpid-proton-core.pc.in +++ /dev/null @@ -1,30 +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. - */ - -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ -libdir=@LIBDIR@ -includedir=@INCLUDEDIR@ - -Name: Proton Core -Description: Qpid Proton C core protocol library -Version: @PN_VERSION@ -URL: http://qpid.apache.org/proton/ -Libs: -L${libdir} -lqpid-proton-core -Cflags: -I${includedir} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/libqpid-proton.pc.in ---------------------------------------------------------------------- diff --git a/proton-c/src/libqpid-proton.pc.in b/proton-c/src/libqpid-proton.pc.in deleted file mode 100644 index a045c3f..0000000 --- a/proton-c/src/libqpid-proton.pc.in +++ /dev/null @@ -1,30 +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. - */ - -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ -libdir=@LIBDIR@ -includedir=@INCLUDEDIR@ - -Name: Proton -Description: Qpid Proton C library -Version: @PN_VERSION@ -URL: http://qpid.apache.org/proton/ -Libs: -L${libdir} -lqpid-proton -Cflags: -I${includedir} http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/proton-c/src/messaging.xml ---------------------------------------------------------------------- diff --git a/proton-c/src/messaging.xml b/proton-c/src/messaging.xml deleted file mode 100644 index 01c34e7..0000000 --- a/proton-c/src/messaging.xml +++ /dev/null @@ -1,168 +0,0 @@ -<?xml version="1.0"?> - -<!-- -Copyright Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit -Suisse, Deutsche Boerse, Envoy Technologies Inc., Goldman Sachs, HCL -Technologies Ltd, IIT Software GmbH, iMatix Corporation, INETCO Systems Limited, -Informatica Corporation, JPMorgan Chase & Co., Kaazing Corporation, N.A, -Microsoft Corporation, my-Channels, Novell, Progress Software, Red Hat Inc., -Software AG, Solace Systems Inc., StormMQ Ltd., Tervela Inc., TWIST Process -Innovations Ltd, VMware, Inc., and WS02 Inc. 2006-2011. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. -3. The name of the author may not be used to endorse or promote products -derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---> - -<amqp name="messaging" xmlns="http://www.amqp.org/schema/amqp.xsd"> - <section name="message-format"> - <type name="header" class="composite" source="list" provides="section"> - <descriptor name="amqp:header:list" code="0x00000000:0x00000070"/> - <field name="durable" type="boolean"/> - <field name="priority" type="ubyte"/> - <field name="ttl" type="milliseconds"/> - <field name="first-acquirer" type="boolean"/> - <field name="delivery-count" type="uint"/> - </type> - <type name="delivery-annotations" class="restricted" source="annotations" provides="section"> - <descriptor name="amqp:delivery-annotations:map" code="0x00000000:0x00000071"/> - </type> - <type name="message-annotations" class="restricted" source="annotations" provides="section"> - <descriptor name="amqp:message-annotations:map" code="0x00000000:0x00000072"/> - </type> - <type name="properties" class="composite" source="list" provides="section"> - <descriptor name="amqp:properties:list" code="0x00000000:0x00000073"/> - <field name="message-id" type="*" requires="message-id"/> - <field name="user-id" type="binary"/> - <field name="to" type="*" requires="address"/> - <field name="subject" type="string"/> - <field name="reply-to" type="*" requires="address"/> - <field name="correlation-id" type="*" requires="message-id"/> - <field name="content-type" type="symbol"/> - <field name="content-encoding" type="symbol"/> - <field name="absolute-expiry-time" type="timestamp"/> - <field name="creation-time" type="timestamp"/> - <field name="group-id" type="string"/> - <field name="group-sequence" type="sequence-no"/> - <field name="reply-to-group-id" type="string"/> - </type> - <type name="application-properties" class="restricted" source="map" provides="section"> - <descriptor name="amqp:application-properties:map" code="0x00000000:0x00000074"/> - </type> - <type name="data" class="restricted" source="binary" provides="section"> - <descriptor name="amqp:data:binary" code="0x00000000:0x00000075"/> - </type> - <type name="amqp-sequence" class="restricted" source="list" provides="section"> - <descriptor name="amqp:amqp-sequence:list" code="0x00000000:0x00000076"/> - </type> - <type name="amqp-value" class="restricted" source="*" provides="section"> - <descriptor name="amqp:amqp-value:*" code="0x00000000:0x00000077"/> - </type> - <type name="footer" class="restricted" source="annotations" provides="section"> - <descriptor name="amqp:footer:map" code="0x00000000:0x00000078"/> - </type> - <type name="annotations" class="restricted" source="map"/> - <type name="message-id-ulong" class="restricted" source="ulong" provides="message-id"/> - <type name="message-id-uuid" class="restricted" source="uuid" provides="message-id"/> - <type name="message-id-binary" class="restricted" source="binary" provides="message-id"/> - <type name="message-id-string" class="restricted" source="string" provides="message-id"/> - <type name="address-string" class="restricted" source="string" provides="address"/> - <definition name="MESSAGE-FORMAT" value="0"/> - </section> - <section name="delivery-state"> - <type name="received" class="composite" source="list" provides="delivery-state"> - <descriptor name="amqp:received:list" code="0x00000000:0x00000023"/> - <field name="section-number" type="uint" mandatory="true"/> - <field name="section-offset" type="ulong" mandatory="true"/> - </type> - <type name="accepted" class="composite" source="list" provides="delivery-state, outcome"> - <descriptor name="amqp:accepted:list" code="0x00000000:0x00000024"/> - </type> - <type name="rejected" class="composite" source="list" provides="delivery-state, outcome"> - <descriptor name="amqp:rejected:list" code="0x00000000:0x00000025"/> - <field name="error" type="error"/> - </type> - <type name="released" class="composite" source="list" provides="delivery-state, outcome"> - <descriptor name="amqp:released:list" code="0x00000000:0x00000026"/> - </type> - <type name="modified" class="composite" source="list" provides="delivery-state, outcome"> - <descriptor name="amqp:modified:list" code="0x00000000:0x00000027"/> - <field name="delivery-failed" type="boolean"/> - <field name="undeliverable-here" type="boolean"/> - <field name="message-annotations" type="fields"/> - </type> - </section> - <section name="addressing"> - <type name="source" class="composite" source="list" provides="source"> - <descriptor name="amqp:source:list" code="0x00000000:0x00000028"/> - <field name="address" type="*" requires="address"/> - <field name="durable" type="terminus-durability" default="none"/> - <field name="expiry-policy" type="terminus-expiry-policy" default="session-end"/> - <field name="timeout" type="seconds" default="0"/> - <field name="dynamic" type="boolean" default="false"/> - <field name="dynamic-node-properties" type="node-properties"/> - <field name="distribution-mode" type="symbol" requires="distribution-mode"/> - <field name="filter" type="filter-set"/> - <field name="default-outcome" type="*" requires="outcome"/> - <field name="outcomes" type="symbol" multiple="true"/> - <field name="capabilities" type="symbol" multiple="true"/> - </type> - <type name="target" class="composite" source="list" provides="target"> - <descriptor name="amqp:target:list" code="0x00000000:0x00000029"/> - <field name="address" type="*" requires="address"/> - <field name="durable" type="terminus-durability" default="none"/> - <field name="expiry-policy" type="terminus-expiry-policy" default="session-end"/> - <field name="timeout" type="seconds" default="0"/> - <field name="dynamic" type="boolean" default="false"/> - <field name="dynamic-node-properties" type="node-properties"/> - <field name="capabilities" type="symbol" multiple="true"/> - </type> - <type name="terminus-durability" class="restricted" source="uint"> - <choice name="none" value="0"/> - <choice name="configuration" value="1"/> - <choice name="unsettled-state" value="2"/> - </type> - <type name="terminus-expiry-policy" class="restricted" source="symbol"> - <choice name="link-detach" value="link-detach"/> - <choice name="session-end" value="session-end"/> - <choice name="connection-close" value="connection-close"/> - <choice name="never" value="never"/> - </type> - <type name="std-dist-mode" class="restricted" source="symbol" provides="distribution-mode"> - <choice name="move" value="move"/> - <choice name="copy" value="copy"/> - </type> - <type name="filter-set" class="restricted" source="map"/> - <type name="node-properties" class="restricted" source="fields"/> - <type name="delete-on-close" class="composite" source="list" provides="lifetime-policy"> - <descriptor name="amqp:delete-on-close:list" code="0x00000000:0x0000002b"/> - </type> - <type name="delete-on-no-links" class="composite" source="list" provides="lifetime-policy"> - <descriptor name="amqp:delete-on-no-links:list" code="0x00000000:0x0000002c"/> - </type> - <type name="delete-on-no-messages" class="composite" source="list" provides="lifetime-policy"> - <descriptor name="amqp:delete-on-no-messages:list" code="0x00000000:0x0000002d"/> - </type> - <type name="delete-on-no-links-or-messages" class="composite" source="list" provides="lifetime-policy"> - <descriptor name="amqp:delete-on-no-links-or-messages:list" code="0x00000000:0x0000002e"/> - </type> - </section> -</amqp> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
