static app_action_t http_error(string_t *dst, const char *error_string, const char *info) { static const char delim[] = ": "; int content_length = sizeof(roflash_html_header) - 1 + sizeof(roflash_html_p1) - 1 + strlen(error_string) + sizeof(roflash_html_p2) - 1 + sizeof(roflash_html_eol) - 1 + sizeof(roflash_html_footer) - 1; if(info) content_length += sizeof(delim) - 1 + strlen(info) + sizeof(roflash_html_eol) - 1; string_append_cstr_flash(dst, roflash_http_header_pre); string_append_cstr(dst, error_string); string_append_cstr_flash(dst, roflash_http_eol); string_format_flash_ptr(dst, roflash_http_header_error, content_length); string_append_cstr_flash(dst, roflash_html_header); string_append_cstr_flash(dst, roflash_html_p1); string_append_cstr(dst, error_string); if(info) { string_append_cstr(dst, delim); string_append_cstr(dst, info); string_append_cstr_flash(dst, roflash_html_eol); } string_append_cstr_flash(dst, roflash_html_eol); string_append_cstr_flash(dst, roflash_html_p2); string_append_cstr_flash(dst, roflash_html_footer); return(app_action_error); }
VALUE array_inspect(const CallFrame* here, VALUE self, VALUE it) { ObjectPtr<Array> array = self; if (array == NULL) { throw_exception_with_description("Array#inspect called for object that doesn't derive from Array."); } ObjectPtr<String> result = create_string_constant("@("); for (size_t i = 0; i < array->size(); ++i) { Value val = (*array)[i]; string_append(result, value_inspect(val)); if (i != array->size() - 1) { string_append_cstr(result, ", "); } } string_append_cstr(result, ")"); return result; }
/** * Append specific string to destination string. */ void string_append(string_t* pstr_dest, const string_t* cpstr_src) { string_append_cstr(pstr_dest, string_c_str(cpstr_src)); }
/* produces the egoent of the stinger vertex ID given in JSON form */ string_t * egonet_to_json(stinger_t * S, int64_t vtx) { string_t vertices, edges; string_init_from_cstr(&vertices, "\"vertices\" : [ \n"); string_init_from_cstr(&edges, "\"edges\" : [ \n"); char vtx_str[1UL<<20UL]; FILE * vtx_file = fmemopen(vtx_str, sizeof(vtx_str), "w"); char edge_str[1UL<<20UL]; int edge_added = 0; stinger_vertex_to_json_with_type_strings(stinger_vertices_get(S), stinger_vtype_names_get(S), stinger_physmap_get(S), vtx, vtx_file, 2); fflush(vtx_file); string_append_cstr(&vertices, vtx_str); fseek(vtx_file, 0, SEEK_SET); int_hm_seq_t * neighbors = int_hm_seq_new(stinger_outdegree_get(S, vtx) + stinger_indegree_get(S, vtx)); int64_t which = 1; STINGER_FORALL_EDGES_OF_VTX_BEGIN(S, vtx) { int64_t source = int_hm_seq_get(neighbors, STINGER_EDGE_DEST); if(INT_HT_SEQ_EMPTY == source) { source = which++; int_hm_seq_insert(neighbors, STINGER_EDGE_DEST, source); fprintf(vtx_file, ",\n"); stinger_vertex_to_json_with_type_strings(stinger_vertices_get(S), stinger_vtype_names_get(S), stinger_physmap_get(S), STINGER_EDGE_DEST, vtx_file, 2); fputc('\0',vtx_file); fflush(vtx_file); string_append_cstr(&vertices, vtx_str); fseek(vtx_file, 0, SEEK_SET); } char * etype = stinger_etype_names_lookup_name(S, STINGER_EDGE_TYPE); const char prepend_str [] = ",\n"; if (STINGER_IS_OUT_EDGE) { if(!edge_added) { edge_added = 1; if(etype) { sprintf(edge_str, "{ \"type\" : \"%s\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", etype, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, (long int) 0, source); } else { sprintf(edge_str, "{ \"type\" : \"%ld\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", STINGER_EDGE_TYPE, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, (long int) 0, source); } } else { if(etype) { sprintf(edge_str, ",\n{ \"type\" : \"%s\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", etype, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, (long int) 0, source); } else { sprintf(edge_str, ",\n{ \"type\" : \"%ld\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", STINGER_EDGE_TYPE, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, (long int) 0, source); } } string_append_cstr(&edges, edge_str); } uint64_t dest = STINGER_EDGE_DEST; STINGER_FORALL_OUT_EDGES_OF_VTX_BEGIN(S, dest) { int64_t target = int_hm_seq_get(neighbors, STINGER_EDGE_DEST); if(INT_HT_SEQ_EMPTY != target) { char * etype = stinger_etype_names_lookup_name(S, STINGER_EDGE_TYPE); if(etype) { sprintf(edge_str, ",\n{ \"type\" : \"%s\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", etype, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, source, target); } else { sprintf(edge_str, ",\n{ \"type\" : \"%ld\", \"src\" : %ld, \"dest\" : %ld, \"weight\" : %ld, \"time1\" : %ld, \"time2\" : %ld, \"source\" : %ld, \"target\": %ld }", STINGER_EDGE_TYPE, STINGER_EDGE_SOURCE, STINGER_EDGE_DEST, STINGER_EDGE_WEIGHT, STINGER_EDGE_TIME_FIRST, STINGER_EDGE_TIME_RECENT, source, target); } string_append_cstr(&edges, edge_str); } } STINGER_FORALL_OUT_EDGES_OF_VTX_END();