void asp_resmsg(int argc, char **argv) { char *p; if ((p = js_string(webcgi_safeget("resmsg", (argc > 0) ? argv[0] : ""))) == NULL) return; web_printf("\nresmsg='%s';\n", p); free(p); }
JSObject* ThreadProfile::ToJSObject(JSContext *aCx) { JS::RootedValue val(aCx); std::stringstream ss; JSStreamWriter b(ss); StreamJSObject(b); NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str())); JS_ParseJSON(aCx, static_cast<const jschar*>(js_string.get()), js_string.Length(), &val); return &val.toObject(); }
JSObject* ThreadProfile::ToJSObject(JSContext *aCx) { JS::RootedValue val(aCx); std::stringstream ss; { // Define a scope to prevent a moving GC during ~JSStreamWriter from // trashing the return value. JSStreamWriter b(ss); StreamJSObject(b); NS_ConvertUTF8toUTF16 js_string(nsDependentCString(ss.str().c_str())); JS_ParseJSON(aCx, static_cast<const char16_t*>(js_string.get()), js_string.Length(), &val); } return &val.toObject(); }
JSValue::operator JSString() const { HAL_JSVALUE_LOCK_GUARD; JSValueRef exception { nullptr }; JSStringRef js_string_ref = JSValueToStringCopy(static_cast<JSContextRef>(js_context__), js_value_ref__, &exception); if (exception) { // If this assert fails then we need to JSStringRelease // js_string_ref. assert(!js_string_ref); detail::ThrowRuntimeError("JSValue", JSValue(js_context__, exception)); } assert(js_string_ref); JSString js_string(js_string_ref); JSStringRelease(js_string_ref); return js_string; }
enum dtype js_datatype(const json_value* root) { const json_value* type = js_by_name(root, "type"); if(type == NULL) { ERR(jsdd, "No 'type' in json; don't know data type"); assert(false); return GARBAGE; } const char* str = js_string(type); if(strcasecmp(str, "float32") == 0) { return FLOAT32; } else if(strcasecmp(str, "float64") == 0) { return FLOAT64; } else if(strcasecmp(str, "byte") == 0 || strcasecmp(str, "char") == 0) { return BYTE; } assert(false); return GARBAGE; }
static void js_obj (JSContextRef ctx, JSObjectRef object, JsonObject * obj) { JSPropertyNameArrayRef props; gsize nprops, i; props = JSObjectCopyPropertyNames (ctx, object); nprops = JSPropertyNameArrayGetCount (props); for (i = 0; i < nprops; i++) { JSStringRef prop = JSPropertyNameArrayGetNameAtIndex (props, i); JSValueRef value; JsonNode *node; gchar *p; p = js_string (prop); g_message("Getting obj property %s\n",p); value = JSObjectGetProperty (ctx, object, prop, NULL); js_value (ctx, value, &node); g_message("Got obj property %s\n",p); debug_print_json_node ( "js_obj(): ", node ); g_message("obj=%p\n",obj); json_object_set_member (obj, p, node); g_free (p); JSStringRelease (prop); } g_message("Done get properties\n"); JSPropertyNameArrayRelease (props); }
static void js_value (JSContextRef ctx, JSValueRef value, JsonNode ** v) { switch (JSValueGetType (ctx, value)) { case kJSTypeUndefined: case kJSTypeNull: *v = json_node_new (JSON_NODE_NULL); break; case kJSTypeBoolean: *v = json_node_new (JSON_NODE_VALUE); json_node_set_boolean (*v, JSValueToBoolean (ctx, value) == true ? TRUE : FALSE); break; case kJSTypeNumber: *v = json_node_new (JSON_NODE_VALUE); json_node_set_double (*v, (gdouble) JSValueToNumber (ctx, value, NULL)); break; case kJSTypeString: { JSStringRef string; gchar *str; string = JSValueToStringCopy (ctx, value, NULL); str = js_string (string); JSStringRelease (string); *v = json_node_new (JSON_NODE_VALUE); json_node_set_string (*v, str); g_free (str); break; } case kJSTypeObject: { *v = json_node_new (JSON_NODE_OBJECT); JsonObject *o = json_object_new (); js_obj (ctx, JSValueToObject (ctx, value, NULL), o); json_node_take_object (*v, o); break; } } /* FIXME: array?!? integer?!? -> probably arrays are considered instances of Array() Javascript object ?! see http://developer.apple.com/library/mac/#documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/JSValueRef_h/index.html%23//apple_ref/c/func/JSValueGetType */ debug_print_json_node ( "js_value(): ", *v ); }
void asp_devlist(int argc, char **argv) { char *p; FILE *f; char buf[1024]; char comma; // must be here for easier call via update.cgi. arg is ignored asp_arplist(0, NULL); asp_wlnoise(0, NULL); // p = js_string(nvram_safe_get("dhcpd_static")); web_printf("dhcpd_static = '%s'.split('>');\n", p ? p : ""); free(p); // web_puts("wldev = ["); comma = ' '; foreach_wif(1, &comma, get_wl_clients); web_puts("];\n"); // unsigned long expires; char mac[32]; char ip[32]; char hostname[256]; char *host; web_puts("dhcpd_lease = ["); #ifdef TCONFIG_VLAN if ((nvram_match("lan_proto", "dhcp")) || (nvram_match("lan1_proto", "dhcp")) || (nvram_match("lan2_proto", "dhcp")) || (nvram_match("lan3_proto", "dhcp")) ) { #else if (nvram_match("lan_proto", "dhcp")) { #endif f_write("/var/tmp/dhcp/leases.!", NULL, 0, 0, 0666); // dump the leases to a file if (killall("dnsmasq", SIGUSR2) == 0) { // helper in dnsmasq will remove this when it's done f_wait_notexists("/var/tmp/dhcp/leases.!", 5); } if ((f = fopen("/var/tmp/dhcp/leases", "r")) != NULL) { comma = ' '; while (fgets(buf, sizeof(buf), f)) { if (sscanf(buf, "%lu %17s %15s %255s", &expires, mac, ip, hostname) != 4) continue; host = js_string((hostname[0] == '*') ? "" : hostname); web_printf("%c['%s','%s','%s','%s']", comma, (host ? host : ""), ip, mac, ((expires == 0) ? "non-expiring" : reltime(buf, expires))); free(host); comma = ','; } fclose(f); } unlink("/var/tmp/dhcp/leases"); } web_puts("];"); }