static void flow_send_do(struct sol_flow_node *flow, struct flow_static_data *fsd, uint16_t src_idx, uint16_t source_out_port_idx, struct sol_flow_packet *packet) { struct flow_static_type *type = (struct flow_static_type *)flow->type; const struct sol_flow_static_conn_spec *spec; unsigned int i; bool is_error_packet, dispatched; is_error_packet = sol_flow_packet_get_type(packet) == SOL_FLOW_PACKET_TYPE_ERROR; dispatched = false; for (i = type->node_infos[src_idx].first_conn_idx, spec = type->conn_specs + i; spec->src == src_idx; spec++, i++) { const struct sol_flow_port_type_in *dst_port_type; struct sol_flow_node *dst; struct conn_info *ci; if (spec->src_port != source_out_port_idx) continue; dst = fsd->nodes[spec->dst]; dst_port_type = sol_flow_node_type_get_port_in(dst->type, spec->dst_port); ci = &type->conn_infos[i]; dispatch_process(dst, spec->dst_port, ci->in_conn_id, dst_port_type, packet); dispatched = true; } if (type->ports_out_count > 0) { const struct sol_flow_static_port_spec *pspec; uint16_t exported_out; for (pspec = type->exported_out_specs, exported_out = 0; pspec->node < UINT16_MAX; pspec++, exported_out++) { if (pspec->node == src_idx && pspec->port == source_out_port_idx) { /* Export the packet. Note that ownership of packet * will pass to the send() function. */ sol_flow_send_packet(flow, exported_out, packet); return; } } } if (is_error_packet && !dispatched) { const char *msg; int code; if (sol_flow_packet_get_error(packet, &code, &msg) == 0) { SOL_WRN("Error packet \'%d (%s)\' sent from \'%s (%p)\' was not handled", code, msg, flow->id, flow); } } sol_flow_packet_del(packet); }
static void inspector_show_packet_value(const struct sol_flow_packet *packet) { const struct sol_flow_packet_type *type = sol_flow_packet_get_type(packet); if (type == SOL_FLOW_PACKET_TYPE_EMPTY) { fputs("<empty>", stdout); return; } else if (type == SOL_FLOW_PACKET_TYPE_ANY) { fputs("<any>", stdout); return; } else if (type == SOL_FLOW_PACKET_TYPE_ERROR) { int code; const char *msg; if (sol_flow_packet_get_error(packet, &code, &msg) == 0) { fprintf(stdout, "<error:%d \"%s\">", code, msg ? msg : ""); return; } } else if (type == SOL_FLOW_PACKET_TYPE_BOOL) { bool v; if (sol_flow_packet_get_bool(packet, &v) == 0) { fprintf(stdout, "<%s>", v ? "true" : "false"); return; } } else if (type == SOL_FLOW_PACKET_TYPE_BYTE) { unsigned char v; if (sol_flow_packet_get_byte(packet, &v) == 0) { fprintf(stdout, "<%#x>", v); return; } } else if (type == SOL_FLOW_PACKET_TYPE_IRANGE) { struct sol_irange v; if (sol_flow_packet_get_irange(packet, &v) == 0) { fprintf(stdout, "<val:%d|min:%d|max:%d|step:%d>", v.val, v.min, v.max, v.step); return; } } else if (type == SOL_FLOW_PACKET_TYPE_DRANGE) { struct sol_drange v; if (sol_flow_packet_get_drange(packet, &v) == 0) { fprintf(stdout, "<val:%g|min:%g|max:%g|step:%g>", v.val, v.min, v.max, v.step); return; } } else if (type == SOL_FLOW_PACKET_TYPE_STRING) { const char *v; if (sol_flow_packet_get_string(packet, &v) == 0) { fprintf(stdout, "<\"%s\">", v); return; } } else if (type == SOL_FLOW_PACKET_TYPE_BLOB) { struct sol_blob *v; if (sol_flow_packet_get_blob(packet, &v) == 0) { fprintf(stdout, "<mem=%p|size=%zd|refcnt=%hu|type=%p|parent=%p>", v->mem, v->size, v->refcnt, v->type, v->parent); return; } } else if (type == SOL_FLOW_PACKET_TYPE_JSON_OBJECT) { struct sol_blob *v; if (sol_flow_packet_get_json_object(packet, &v) == 0) { fprintf(stdout, "<%.*s>", SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(v))); return; } } else if (type == SOL_FLOW_PACKET_TYPE_JSON_ARRAY) { struct sol_blob *v; if (sol_flow_packet_get_json_array(packet, &v) == 0) { fprintf(stdout, "<%.*s>", SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(v))); return; } } else if (type == SOL_FLOW_PACKET_TYPE_RGB) { struct sol_rgb v; if (sol_flow_packet_get_rgb(packet, &v) == 0) { fprintf(stdout, "<red=%u|green=%u|blue=%u" "|red_max=%u|green_max=%u|blue_max=%u>", v.red, v.green, v.blue, v.red_max, v.green_max, v.blue_max); return; } } else if (type == SOL_FLOW_PACKET_TYPE_DIRECTION_VECTOR) { struct sol_direction_vector v; if (sol_flow_packet_get_direction_vector(packet, &v) == 0) { fprintf(stdout, "<x=%g|y=%g|z=%g|min=%g|max=%g>", v.x, v.y, v.z, v.min, v.max); return; } } else if (type == SOL_FLOW_PACKET_TYPE_LOCATION) { struct sol_location v; if (sol_flow_packet_get_location(packet, &v) == 0) { fprintf(stdout, "<lat=%g|lon=%g|alt=%g>", v.lat, v.lon, v.alt); return; } } else if (type == SOL_FLOW_PACKET_TYPE_TIMESTAMP) { struct timespec v; if (sol_flow_packet_get_timestamp(packet, &v) == 0) { struct tm cur_time; char buf[32]; tzset(); if (gmtime_r(&v.tv_sec, &cur_time)) { if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &cur_time) > 0) { fprintf(stdout, "<%s>", buf); return; } } } } else if (type == SOL_FLOW_PACKET_TYPE_HTTP_RESPONSE) { int code; const char *url, *content_type; const struct sol_blob *content; struct sol_vector headers, cookies; if (sol_flow_packet_get_http_response(packet, &code, &url, &content_type, &content, &cookies, &headers) == 0) { fprintf(stdout, "<response_code:%d|content type:%s|url:%s|", code, content_type, url); fprintf(stdout, "|cookies: {"); inpector_print_key_value_array(&cookies); fprintf(stdout, "}|headers:{"); inpector_print_key_value_array(&headers); fprintf(stdout, "}|content:{mem=%p|size=%zd|refcnt=%hu|type=%p|parent=%p}>", content->mem, content->size, content->refcnt, content->type, content->parent); } return; } fputs("<?>", stdout); }