static JSValueRef start_session_sync_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *session = NULL; gboolean result; GError *err = NULL; /* FIXME: old API required lightdm.login(username, session), but the username * is never actually used. At some point, deprecate the old usage. For now, * simply work around it. */ if (argumentCount == 1) { session = arg_to_string(context, arguments[0], exception); } else if (argumentCount == 2) { session = arg_to_string(context, arguments[1], exception); } result = lightdm_greeter_start_session_sync(GREETER, session, &err); g_free(session); if (err != NULL) { _mkexception(context, exception, err->message); g_error_free(err); } return JSValueMakeBoolean(context, result); }
static JSValueRef gettext_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *string = NULL; JSValueRef result; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } string = arg_to_string(context, arguments[0], exception); if (!string) { return JSValueMakeNull(context); } result = string_or_null(context, gettext(string)); g_free(string); return result; }
static JSValueRef set_language_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *language = NULL; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } language = arg_to_string(context, arguments[0], exception); if (!language) { return JSValueMakeNull(context); } lightdm_greeter_set_language(GREETER, language); g_free(language); return JSValueMakeNull(context); }
static bool set_layout_cb(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception) { gchar *layout; const GList *layouts, *link; layout = arg_to_string(context, value, exception); if (!layout) { return false; } layouts = lightdm_get_layouts(); for (link = layouts; link; link = link->next) { LightDMLayout *currlayout = link->data; if (!( g_strcmp0(lightdm_layout_get_name(currlayout), layout))) { g_object_ref(currlayout); lightdm_set_layout(currlayout); break; } } g_free(layout); return true; }
static JSValueRef get_hint_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *hint_name = NULL; JSValueRef result; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } hint_name = arg_to_string(context, arguments[0], exception); if (!hint_name) { return JSValueMakeNull(context); } result = string_or_null(context, lightdm_greeter_get_hint(GREETER, hint_name)); g_free(hint_name); return result; }
static JSValueRef get_dirlist_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { JSObjectRef array; guint n_entries = 0; JSValueRef *args = NULL; GDir *dir; gchar *path, *fullpath; const gchar *dirent; GError *err = NULL; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } path = arg_to_string(context, arguments[0], exception); if (!path) { return JSValueMakeNull(context); } dir = g_dir_open (path, 0, &err); if (err) { _mkexception(context, exception, err->message); g_error_free(err); return JSValueMakeNull(context); } /* * Create the lis of the directory entries */ while ((dirent = g_dir_read_name (dir)) != NULL) { n_entries++; args = g_realloc (args, sizeof (JSValueRef) * (n_entries + 1)); fullpath = g_build_filename (path, dirent, NULL); /* Give theme developer full pathname */ args[(n_entries - 1)] = string_or_null (context, fullpath); g_free (fullpath); } g_dir_close (dir); array = JSObjectMakeArray (context, n_entries, args, exception); g_free (args); if (array == NULL) { return JSValueMakeNull (context); } else { return array; } }
/* * Gets a key's value from config file. * * Returns value as a string. */ static JSValueRef get_conf_str_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *section, *key, *value; GError *err = NULL; JSValueRef result; if (argumentCount != 2) { return mkexception(context, exception, ARGNOTSUPPLIED); } section = arg_to_string(context, arguments[0], exception); if (!section) { return JSValueMakeNull(context); } key = arg_to_string(context, arguments[1], exception); if (!key) { return JSValueMakeNull(context); } value = g_key_file_get_string(keyfile, section, key, &err); if (err) { _mkexception(context, exception, err->message); g_error_free(err); return JSValueMakeNull(context); } result = string_or_null(context, value); g_free(value); return result; }
static JSValueRef ngettext_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *string = NULL, *plural_string = NULL; unsigned int n = 0; JSValueRef result; if (argumentCount != 3) { return mkexception(context, exception, ARGNOTSUPPLIED); } string = arg_to_string(context, arguments[0], exception); if (!string) { return JSValueMakeNull(context); } plural_string = arg_to_string(context, arguments[1], exception); if (!plural_string) { return JSValueMakeNull(context); } n = JSValueToNumber(context, arguments[2], exception); result = string_or_null(context, ngettext(string, plural_string, n)); g_free(string); g_free(plural_string); return result; }
static JSValueRef authenticate_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *name = NULL; if (argumentCount > 0) { name = arg_to_string(context, arguments[0], exception); } lightdm_greeter_authenticate(GREETER, name); g_free(name); return JSValueMakeNull(context); }
static void dump_parser_output (void) { int i, j; for (i = 0; i < parser_output.nb_instrs; i++) { printf ("%04d: %s ", i, parser_output.instrs[i]->opcode); for (j = 0; j < parser_output.instrs[i]->nb_args; j++) { printf ("%s", arg_to_string (parser_output.instrs[i]->args[j])); if (j != parser_output.instrs[i]->nb_args - 1) printf (", "); } printf ("\n"); } for (i = 0; i < parser_output.nb_labels; i++) printf ("@%04d: %s\n", parser_output.labels[i]->position, parser_output.labels[i]->text); }
static JSValueRef txt2html_cb(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) { gchar *txt; JSValueRef result; if (argumentCount != 1) { return mkexception(context, exception, ARGNOTSUPPLIED); } txt = arg_to_string(context, arguments[0], exception); if (!txt) { return JSValueMakeNull(context); } /* Replace & with & */ txt = g_strreplace (txt, "&", "&"); /* Replace " with " */ txt = g_strreplace (txt, "\"", """); /* Replace < with < */ txt = g_strreplace (txt, "<", "<"); /* Replace > with > */ txt = g_strreplace (txt, ">", ">"); /* Replace newlines with <br> */ txt = g_strreplace (txt, "\n", "<br>"); result = string_or_null (context, txt); g_free (txt); return result; }
static void sigh(int s) { if (!quiet) cout("%scatched signal: %s when testing format: \"%s\" with arg: %s%s\n", C_CRASH, strsignal(s), current_format, arg_to_string(current_arg), C_CLEAR); if (stop_to_first_error) exit(0); if (sig_counter >= 500 && !quiet) cout("%sreceived too many crash signals, aborting test ...\n%s", C_CRASH, C_CLEAR), exit(-1); sig_counter++; g_current_test_index++; longjmp(jmp_next_test, 1); }