JNIEXPORT jstring JNICALL Java_org_zeromq_zebra_XrapTraffic__1_1route (JNIEnv *env, jclass c, jlong self) { char *route_ = (char *) xrap_traffic_route ((xrap_traffic_t *) (intptr_t) self); jstring return_string_ = (*env)->NewStringUTF (env, route_); return return_string_; }
static void store_xrap_offer (client_t *self) { service_t *service = self->server->xrap; assert (service); char *route = (char *) xrap_traffic_route (self->message); char *method = (char *) xrap_traffic_method (self->message); if (streq (method, "GET")) self->rc = ztrie_insert_route (service->get_routes, route, self, NULL); else if (streq (method, "POST")) self->rc = ztrie_insert_route (service->post_routes, route, self, NULL); else if (streq (method, "PUT")) self->rc = ztrie_insert_route (service->put_routes, route, self, NULL); else if (streq (method, "DELETE")) self->rc = ztrie_insert_route (service->delete_routes, route, self, NULL); if (self->rc != 0) xrap_traffic_set_status_code (self->message, XRAP_TRAFFIC_CONFLICT); }
/// // Get the route field const QString QmlXrapTraffic::route () { return QString (xrap_traffic_route (self)); };
void xrap_traffic_test (bool verbose) { printf (" * xrap_traffic:"); if (verbose) printf ("\n"); // @selftest // Simple create/destroy test xrap_traffic_t *self = xrap_traffic_new (); assert (self); xrap_traffic_destroy (&self); // Create pair of sockets we can send through // We must bind before connect if we wish to remain compatible with ZeroMQ < v4 zsock_t *output = zsock_new (ZMQ_DEALER); assert (output); int rc = zsock_bind (output, "inproc://selftest-xrap_traffic"); assert (rc == 0); zsock_t *input = zsock_new (ZMQ_ROUTER); assert (input); rc = zsock_connect (input, "inproc://selftest-xrap_traffic"); assert (rc == 0); // Encode/send/decode and verify each message type int instance; self = xrap_traffic_new (); xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_OPEN); xrap_traffic_set_address (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (streq (xrap_traffic_address (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PING); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PONG); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_CLOSE); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_SEND); xrap_traffic_set_timeout (self, 123); zmsg_t *xrap_send_content = zmsg_new (); xrap_traffic_set_content (self, &xrap_send_content); zmsg_addstr (xrap_traffic_content (self), "Captcha Diem"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_timeout (self) == 123); assert (zmsg_size (xrap_traffic_content (self)) == 1); char *content = zmsg_popstr (xrap_traffic_content (self)); assert (streq (content, "Captcha Diem")); zstr_free (&content); if (instance == 1) zmsg_destroy (&xrap_send_content); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_OFFER); xrap_traffic_set_route (self, "Life is short but Now lasts for ever"); xrap_traffic_set_method (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (streq (xrap_traffic_route (self), "Life is short but Now lasts for ever")); assert (streq (xrap_traffic_method (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_DELIVER); zuuid_t *xrap_deliver_sender = zuuid_new (); xrap_traffic_set_sender (self, xrap_deliver_sender); zmsg_t *xrap_deliver_content = zmsg_new (); xrap_traffic_set_content (self, &xrap_deliver_content); zmsg_addstr (xrap_traffic_content (self), "Captcha Diem"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (zuuid_eq (xrap_deliver_sender, zuuid_data (xrap_traffic_sender (self)))); if (instance == 1) zuuid_destroy (&xrap_deliver_sender); assert (zmsg_size (xrap_traffic_content (self)) == 1); char *content = zmsg_popstr (xrap_traffic_content (self)); assert (streq (content, "Captcha Diem")); zstr_free (&content); if (instance == 1) zmsg_destroy (&xrap_deliver_content); } xrap_traffic_set_id (self, XRAP_TRAFFIC_OK); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_FAIL); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_ERROR); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_destroy (&self); zsock_destroy (&input); zsock_destroy (&output); // @end printf ("OK\n"); }