char *js_get_message(jsval v) { jsval messages, msg, rval; uint32_t messages_len; char *c_str; int i; struct string_buffer sb = STRING_BUFFER_INITIALIZER; if (!JS_GetProperty(js_context, JSVAL_TO_OBJECT(v), "messages", &messages)) { return NULL; } switch(JS_TypeOfValue(js_context, messages)) { case JSTYPE_STRING: c_str = JS_EncodeString(js_context, JSVAL_TO_STRING(messages)); return c_str; case JSTYPE_OBJECT: if (!JS_GetArrayLength(js_context, JSVAL_TO_OBJECT(messages), &messages_len)) { return NULL; } for (i = 0; i < (int) messages_len; i++) { if (!JS_GetElement(js_context, JSVAL_TO_OBJECT(messages), i, &msg)) { goto out_err; } c_str = JS_EncodeString(js_context, JSVAL_TO_STRING(msg)); if (string_buffer_append_string(&sb, c_str)) goto out_err; if (i < (int) messages_len - 1) { if (string_buffer_append_char(&sb, '\n')) goto out_err; } free(c_str); } return sb.s; default: break; } out_err: free(c_str); string_buffer_cleanup(&sb); return NULL; }
hcerr_t xml_cleanup(xml_parser *formal_parser){ simple_xml_parser *parser = (simple_xml_parser*) formal_parser; if (parser == NULL) return HCERR_OK; if (parser->buffer_list.string_buffer != NULL) { string_buffer_cleanup(parser->buffer_list.string_buffer); parser->buffer_list.string_buffer = NULL; } if (parser->attribute_names != NULL) { deallocator(parser->attribute_names); parser->attribute_names = NULL; } if (parser->attribute_values != NULL) { deallocator(parser->attribute_values); parser->attribute_values = NULL; } deallocator(parser); parser = NULL; formal_parser = NULL; return HCERR_OK; }