qdr_terminus_t *qdr_terminus(pn_terminus_t *pn) { qdr_terminus_t *term = new_qdr_terminus_t(); ZERO(term); term->properties = pn_data(0); term->filter = pn_data(0); term->outcomes = pn_data(0); term->capabilities = pn_data(0); if (pn) { const char *addr = pn_terminus_get_address(pn); if (addr && *addr) term->address = qdr_field(addr); term->durability = pn_terminus_get_durability(pn); term->expiry_policy = pn_terminus_get_expiry_policy(pn); term->timeout = pn_terminus_get_timeout(pn); term->dynamic = pn_terminus_is_dynamic(pn); term->distribution_mode = pn_terminus_get_distribution_mode(pn); pn_data_copy(term->properties, pn_terminus_properties(pn)); pn_data_copy(term->filter, pn_terminus_filter(pn)); pn_data_copy(term->outcomes, pn_terminus_outcomes(pn)); pn_data_copy(term->capabilities, pn_terminus_capabilities(pn)); } return term; }
pn_dispatcher_t *pn_dispatcher(uint8_t frame_type, pn_transport_t *transport) { pn_dispatcher_t *disp = (pn_dispatcher_t *) calloc(sizeof(pn_dispatcher_t), 1); disp->frame_type = frame_type; disp->transport = transport; disp->trace = (pn_env_bool("PN_TRACE_RAW") ? PN_TRACE_RAW : PN_TRACE_OFF) | (pn_env_bool("PN_TRACE_FRM") ? PN_TRACE_FRM : PN_TRACE_OFF) | (pn_env_bool("PN_TRACE_DRV") ? PN_TRACE_DRV : PN_TRACE_OFF); disp->input = pn_buffer(1024); disp->fragment = 0; disp->channel = 0; disp->code = 0; disp->args = pn_data(16); disp->payload = NULL; disp->size = 0; disp->output_args = pn_data(16); disp->frame = pn_buffer( 4*1024 ); // XXX disp->capacity = 4*1024; disp->output = (char *) malloc(disp->capacity); disp->available = 0; disp->halt = false; disp->batch = true; disp->scratch = pn_string(NULL); return disp; }
int pn_message_encode(pn_message_t *msg, char *bytes, size_t *size) { if (!msg || !bytes || !size || !*size) return PN_ARG_ERR; if (!msg->data) { msg->data = pn_data(64); } if (!msg->body) { msg->body = pn_data(64); } int err = pn_data_clear(msg->data); if (err) return err; err = pn_data_fill(msg->data, "DL[oBIoI]", HEADER, msg->durable, msg->priority, msg->ttl, msg->first_acquirer, msg->delivery_count); if (err) return err; err = pn_data_fill(msg->data, "DL[nzSSSnssLLSiS]", PROPERTIES, pn_buffer_bytes(msg->user_id), pn_buffer_str(msg->address), pn_buffer_str(msg->subject), pn_buffer_str(msg->reply_to), pn_buffer_str(msg->content_type), pn_buffer_str(msg->content_encoding), msg->expiry_time, msg->creation_time, pn_buffer_str(msg->group_id), msg->group_sequence, pn_buffer_str(msg->reply_to_group_id)); if (err) return err; size_t remaining = *size; size_t encoded = remaining; err = pn_data_encode(msg->data, bytes, &encoded); if (err) return err; bytes += encoded; remaining -= encoded; encoded = remaining; err = pn_data_encode(msg->body, bytes, &encoded); if (err) return err; bytes += encoded; remaining -= encoded; *size -= remaining; return 0; }
int pn_message_load_amqp(pn_message_t *msg, const char *data, size_t size) { if (!msg) return PN_ARG_ERR; if (!msg->body) { msg->body = pn_data(64); } pn_parser_t *parser = pn_message_parser(msg); while (true) { pn_data_clear(msg->body); pn_atoms_t atoms = pn_data_available(msg->body); int err = pn_parser_parse(parser, data, &atoms); if (err == PN_OVERFLOW) { err = pn_data_grow(msg->body); if (err) return err; continue; } else if (err) { return err; } else { return pn_data_resize(msg->body, atoms.size); } } }
int pn_message_load_text(pn_message_t *msg, const char *data, size_t size) { if (!msg) return PN_ARG_ERR; if (!msg->body) { msg->body = pn_data(64); } int err = pn_data_fill(msg->body, "DLS", AMQP_VALUE, data); if (err) return err; return pn_data_intern(msg->body); }
int pn_message_load_data(pn_message_t *msg, const char *data, size_t size) { if (!msg) return PN_ARG_ERR; if (!msg->body) { msg->body = pn_data(64); } int err = pn_data_fill(msg->body, "DLz", DATA, size, data); if (err) return err; return pn_data_intern(msg->body); }
int buffer(int argc, char **argv) { pn_buffer_t *buf = pn_buffer(16); pn_buffer_append(buf, "abcd", 4); pn_buffer_print(buf); printf("\n"); pn_buffer_prepend(buf, "012", 3); pn_buffer_print(buf); printf("\n"); pn_buffer_prepend(buf, "z", 1); pn_buffer_print(buf); printf("\n"); pn_buffer_append(buf, "efg", 3); pn_buffer_print(buf); printf("\n"); pn_buffer_append(buf, "hijklm", 6); pn_buffer_print(buf); printf("\n"); pn_buffer_defrag(buf); pn_buffer_print(buf); printf("\n"); pn_buffer_trim(buf, 1, 1); pn_buffer_print(buf); printf("\n"); pn_buffer_trim(buf, 4, 0); pn_buffer_print(buf); printf("\n"); pn_buffer_clear(buf); pn_buffer_print(buf); printf("\n"); pn_buffer_free(buf); pn_data_t *data = pn_data(16); int err = pn_data_fill(data, "Ds[iSi]", "desc", 1, "two", 3); if (err) { printf("%s\n", pn_code(err)); } pn_data_print(data); printf("\n"); pn_bytes_t str; err = pn_data_scan(data, "D.[.S.]", &str); if (err) { printf("%s\n", pn_code(err)); } else { printf("%.*s\n", (int) str.size, str.start); } pn_data_clear(data); pn_data_fill(data, "DL[SIonn?DL[S]?DL[S]nnI]", ATTACH, "asdf", 1, true, true, SOURCE, "queue", true, TARGET, "queue", 0); pn_data_print(data); printf("\n"); pn_data_free(data); return 0; }
qdr_error_t *qdr_error_from_pn(pn_condition_t *pn) { if (!pn) return 0; qdr_error_t *error = new_qdr_error_t(); ZERO(error); const char *name = pn_condition_get_name(pn); if (name && *name) error->name = qdr_field(name); const char *desc = pn_condition_get_description(pn); if (desc && *desc) error->description = qdr_field(desc); error->info = pn_data(0); return error; }
data data::create() { return internal::take_ownership(pn_data(0)).get(); }
int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size) { if (!msg || !bytes || !size) return PN_ARG_ERR; if (!msg->data) { msg->data = pn_data(64); } if (!msg->body) { msg->body = pn_data(64); } pn_data_clear(msg->body); while (size) { size_t copy = size; pn_data_clear(msg->data); int err = pn_data_decode(msg->data, (char *) bytes, ©); if (err) return err; size -= copy; bytes += copy; bool scanned; uint64_t desc; err = pn_data_scan(msg->data, "D?L.", &scanned, &desc); if (err) return err; if (!scanned){ desc = 0; } switch (desc) { case HEADER: pn_data_scan(msg->data, "D.[oBIoI]", &msg->durable, &msg->priority, &msg->ttl, &msg->first_acquirer, &msg->delivery_count); break; case PROPERTIES: { pn_bytes_t user_id, address, subject, reply_to, ctype, cencoding, group_id, reply_to_group_id; err = pn_data_scan(msg->data, "D.[.zSSS.ssLLSiS]", &user_id, &address, &subject, &reply_to, &ctype, &cencoding, &msg->expiry_time, &msg->creation_time, &group_id, &msg->group_sequence, &reply_to_group_id); if (err) return err; err = pn_buffer_set_bytes(&msg->user_id, user_id); if (err) return err; err = pn_buffer_set_strn(&msg->address, address.start, address.size); if (err) return err; err = pn_buffer_set_strn(&msg->subject, subject.start, subject.size); if (err) return err; err = pn_buffer_set_strn(&msg->reply_to, reply_to.start, reply_to.size); if (err) return err; err = pn_buffer_set_strn(&msg->content_type, ctype.start, ctype.size); if (err) return err; err = pn_buffer_set_strn(&msg->content_encoding, cencoding.start, cencoding.size); if (err) return err; err = pn_buffer_set_strn(&msg->group_id, group_id.start, group_id.size); if (err) return err; err = pn_buffer_set_strn(&msg->reply_to_group_id, reply_to_group_id.start, reply_to_group_id.size); if (err) return err; } break; case DELIVERY_ANNOTATIONS: case MESSAGE_ANNOTATIONS: break; default: { pn_data_t *data = msg->body; msg->body = msg->data; msg->data = data; err = pn_data_intern(msg->body); if (err) return err; } break; } } return pn_data_clear(msg->data); }