pn_sasl_t *pn_sasl(pn_transport_t *transport) { if (!transport->sasl) { pni_sasl_t *sasl = (pni_sasl_t *) malloc(sizeof(pni_sasl_t)); const char *sasl_config_path = getenv("PN_SASL_CONFIG_PATH"); sasl->impl_context = NULL; sasl->client = !transport->server; sasl->selected_mechanism = NULL; sasl->included_mechanisms = NULL; sasl->username = NULL; sasl->password = NULL; sasl->config_name = NULL; sasl->config_dir = sasl_config_path ? pn_strdup(sasl_config_path) : NULL; sasl->remote_fqdn = NULL; sasl->external_auth = NULL; sasl->external_ssf = 0; sasl->outcome = PN_SASL_NONE; sasl->impl_context = NULL; sasl->decoded_buffer = pn_buffer(0); sasl->encoded_buffer = pn_buffer(0); sasl->bytes_out.size = 0; sasl->bytes_out.start = NULL; sasl->desired_state = SASL_NONE; sasl->last_state = SASL_NONE; sasl->allow_insecure_mechs = false; transport->sasl = sasl; } // The actual external pn_sasl_t pointer is a pointer to its enclosing pn_transport_t return (pn_sasl_t *)transport; }
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; }
void process_flow(ldp_connection_t *conn, pn_event_t *event) { fprintf(stderr, "flow event %s\n", pn_event_type_name(pn_event_type(event))); pn_link_t *sender = pn_event_link(event); pn_message_t *message = pn_message(); pn_message_set_address(message, "amqp://foo/bar"); pn_data_t *body = pn_message_body(message); char *msgtext = "hello world!"; pn_data_put_string(body, pn_bytes(strlen(msgtext), msgtext)); pn_buffer_t *buffer = pn_buffer(1000); char *encoded = pn_buffer_bytes(buffer).start; size_t size = pn_buffer_capacity(buffer); int err = pn_message_encode(message, encoded, &size); if (err) { fprintf(stderr, "trouble encoding message\n"); } else { char tag[8]; static uint64_t next_tag; *((uint64_t*)tag) = ++next_tag; pn_delivery_t *d = pn_delivery(sender, pn_dtag(tag, 8)); pn_link_send(sender, encoded, size); pn_link_advance(sender); } pn_buffer_free(buffer); pn_message_free(message); }
static int pn_buffer_set_bytes(pn_buffer_t **buf, pn_bytes_t bytes) { if (!*buf) { *buf = pn_buffer(64); } int err = pn_buffer_clear(*buf); if (err) return err; return pn_buffer_append(*buf, bytes.start, bytes.size); }
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; }
static int pn_buffer_set_strn(pn_buffer_t **buf, const char *str, size_t size) { if (!*buf) { *buf = pn_buffer(64); } int err = pn_buffer_clear(*buf); if (err) return err; err = pn_buffer_append(*buf, str, size); if (err) return err; if (str && str[size-1]) { return pn_buffer_append(*buf, "\0", 1); } else { return 0; } }
pni_entry_t *pni_store_put(pni_store_t *store, const char *address) { assert(store); static pn_class_t clazz = PN_CLASS(pni_entry); if (!address) address = ""; pni_stream_t *stream = pni_stream_put(store, address); if (!stream) return NULL; pni_entry_t *entry = (pni_entry_t *) pn_new(sizeof(pni_entry_t), &clazz); if (!entry) return NULL; entry->stream = stream; entry->free = false; entry->stream_next = NULL; entry->stream_prev = NULL; entry->store_next = NULL; entry->store_prev = NULL; entry->delivery = NULL; entry->bytes = pn_buffer(64); entry->status = PN_STATUS_UNKNOWN; LL_ADD(stream, stream, entry); LL_ADD(store, store, entry); store->size++; return entry; }