Browse Source

cleanup code formatting

sisyphus
Dustin Falgout 9 years ago
parent
commit
a019b8f356
  1. 3
      .gitmodules
  2. 282
      src/lightdm-webkit2-greeter-ext.c

3
.gitmodules vendored

@ -1,6 +1,3 @@
[submodule "themes/antergos"]
path = themes/antergos
url = http://github.com/antergos/lightdm-webkit-theme-antergos.git
[submodule "themes/lightdm-webkit-theme-antergos"]
path = themes/lightdm-webkit-theme-antergos
url = http://github.com/antergos/lightdm-webkit-theme-antergos.git

282
src/lightdm-webkit2-greeter-ext.c

@ -1,10 +1,13 @@
/*
* lightdm-webkit2-greeter-ext.c
*
* Copyright © 2014-2015 Antergos Developers <dev@antergos.com>
* Copyright © 2014-2016 Antergos Developers <dev@antergos.com>
*
* Contributed Code:
* Copyright © 2016 Scott Balneaves <sbalneav@ltsp.org>
*
* Based on code from lightdm-webkit-greeter:
* Copyright © 2010-2015 Robert Ancell <robert.ancell@canonical.com>
* Copyright © 2010-2014 Robert Ancell <robert.ancell@canonical.com>
*
* This file is part of lightdm-webkit2-greeter.
*
@ -52,49 +55,54 @@ static JSClassRef
lightdm_layout_class,
lightdm_session_class;
static JSValueRef
string_or_null(JSContextRef context, const gchar *str) {
JSValueRef result;
JSStringRef string;
if (str == NULL)
return JSValueMakeNull (context);
if (str == NULL) {
return JSValueMakeNull(context);
}
string = JSStringCreateWithUTF8CString (str);
result = JSValueMakeString (context, string);
JSStringRelease (string);
string = JSStringCreateWithUTF8CString(str);
result = JSValueMakeString(context, string);
JSStringRelease(string);
return result;
}
static JSValueRef
mkexception (JSContextRef context, JSValueRef * exception, const gchar * str)
{
JSStringRef string = JSStringCreateWithUTF8CString (str);
JSValueRef exceptionString = JSValueMakeString (context, string);
JSStringRelease (string);
*exception = JSValueToObject (context, exceptionString, NULL);
return JSValueMakeNull (context);
mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) {
JSStringRef string = JSStringCreateWithUTF8CString(str);
JSValueRef exceptionString = JSValueMakeString(context, string);
JSStringRelease(string);
*exception = JSValueToObject(context, exceptionString, NULL);
return JSValueMakeNull(context);
}
static char *
escape (const gchar *text)
{
escape(const gchar *text) {
size_t len;
size_t i, j;
int count = 0;
gchar *escaped;
len = strlen (text);
len = strlen(text);
for (i = 0; i < len; i++)
if (text[i] == '\'')
for (i = 0; i < len; i++) {
if (text[i] == '\'') {
count++;
}
}
if (count == 0)
return g_strdup (text);
if (count == 0) {
return g_strdup(text);
}
escaped = g_malloc (len + count + 1);
escaped = g_malloc(len + count + 1);
j = 0;
for (i = 0; i <= len; i++) {
@ -109,6 +117,7 @@ escape (const gchar *text)
return escaped;
}
static JSValueRef
get_user_name_cb(JSContextRef context,
JSObjectRef thisObject,
@ -148,6 +157,7 @@ get_user_home_directory_cb(JSContextRef context,
return string_or_null(context, lightdm_user_get_home_directory(user));
}
static JSValueRef
get_user_image_cb(JSContextRef context,
JSObjectRef thisObject,
@ -364,6 +374,7 @@ get_language_cb(JSContextRef context,
return string_or_null(context, lightdm_language_get_name((LightDMLanguage *) lightdm_get_language()));
}
static JSValueRef
get_layouts_cb(JSContextRef context,
JSObjectRef thisObject,
@ -420,22 +431,21 @@ set_layout_cb(JSContextRef context,
layout_arg = JSValueToStringCopy(context, value, NULL);
layout_size = JSStringGetMaximumUTF8CStringSize(layout_arg);
layout = g_malloc (layout_size);
layout = g_malloc(layout_size);
JSStringGetUTF8CString(layout_arg, layout, layout_size);
JSStringRelease(layout_arg);
layouts = lightdm_get_layouts ();
for (link = layouts; link; link = link->next)
{
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);
if (!( g_strcmp0(lightdm_layout_get_name(currlayout), layout))) {
g_object_ref(currlayout);
lightdm_set_layout(currlayout);
break;
}
}
g_free (layout);
g_free(layout);
return true;
}
@ -504,8 +514,9 @@ cancel_autologin_cb(JSContextRef context,
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_greeter_cancel_autologin(greeter);
return JSValueMakeNull(context);
@ -524,68 +535,74 @@ authenticate_cb(JSContextRef context,
size_t name_size;
gchar *name;
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString ))
return mkexception (context, exception, "Username argument not supplied");
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return mkexception(context, exception, "Username argument not supplied");
}
name_arg = JSValueToStringCopy(context, arguments[0], NULL);
name_size = JSStringGetMaximumUTF8CStringSize(name_arg);
name = g_malloc (name_size);
name = g_malloc(name_size);
JSStringGetUTF8CString(name_arg, name, name_size);
JSStringRelease(name_arg);
if (*name == '\0')
if (*name == '\0') {
lightdm_greeter_authenticate(greeter, NULL);
else
} else {
lightdm_greeter_authenticate(greeter, name);
}
g_free (name);
g_free(name);
return JSValueMakeNull(context);
}
static JSValueRef
authenticate_as_guest_cb (JSContextRef context,
authenticate_as_guest_cb(JSContextRef context,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_greeter_authenticate_as_guest (greeter);
lightdm_greeter_authenticate_as_guest(greeter);
return JSValueMakeNull (context);
return JSValueMakeNull(context);
}
static JSValueRef
get_hint_cb (JSContextRef context,
get_hint_cb(JSContextRef context,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
JSStringRef hint_arg;
size_t hint_size;
gchar *hint_name;
JSStringRef hint;
JSValueRef result;
if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString))
return mkexception (context, exception, "Hint argument not supplied");
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return mkexception(context, exception, "Hint argument not supplied");
}
hint_arg = JSValueToStringCopy (context, arguments[0], NULL);
hint_size = JSStringGetMaximumUTF8CStringSize (hint_arg);
hint_name = g_malloc (hint_size);
JSStringGetUTF8CString (hint_arg, hint_name, hint_size);
JSStringRelease (hint_arg);
hint_arg = JSValueToStringCopy(context, arguments[0], NULL);
hint_size = JSStringGetMaximumUTF8CStringSize(hint_arg);
hint_name = g_malloc(hint_size);
JSStringGetUTF8CString(hint_arg, hint_name, hint_size);
JSStringRelease(hint_arg);
hint = JSStringCreateWithUTF8CString (lightdm_greeter_get_hint (greeter, hint_name));
g_free (hint_name);
result = JSValueMakeString (context, hint);
JSStringRelease (hint);
hint = JSStringCreateWithUTF8CString(lightdm_greeter_get_hint(greeter, hint_name));
g_free(hint_name);
result = JSValueMakeString(context, hint);
JSStringRelease(hint);
return result;
}
@ -603,18 +620,19 @@ respond_cb(JSContextRef context,
size_t response_size;
gchar *response;
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString ))
return mkexception (context, exception, "Response not supplied");
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return mkexception(context, exception, "Response not supplied");
}
response_arg = JSValueToStringCopy(context, arguments[0], NULL);
response_size = JSStringGetMaximumUTF8CStringSize(response_arg);
response = g_malloc (response_size);
response = g_malloc(response_size);
JSStringGetUTF8CString(response_arg, response, response_size);
JSStringRelease(response_arg);
lightdm_greeter_respond(greeter, response);
g_free (response);
g_free(response);
return JSValueMakeNull(context);
}
@ -628,8 +646,9 @@ cancel_authentication_cb(JSContextRef context,
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_greeter_cancel_authentication(greeter);
return JSValueMakeNull(context);
@ -645,60 +664,67 @@ get_authentication_user_cb(JSContextRef context,
return string_or_null(context, lightdm_greeter_get_authentication_user(greeter));
}
static JSValueRef
get_has_guest_account_cb (JSContextRef context,
get_has_guest_account_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return JSValueMakeBoolean (context, lightdm_greeter_get_has_guest_account_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return JSValueMakeBoolean(context, lightdm_greeter_get_has_guest_account_hint(greeter));
}
static JSValueRef
get_hide_users_cb (JSContextRef context,
get_hide_users_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return JSValueMakeBoolean (context, lightdm_greeter_get_hide_users_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return JSValueMakeBoolean(context, lightdm_greeter_get_hide_users_hint(greeter));
}
static JSValueRef
get_select_user_cb (JSContextRef context,
get_select_user_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return string_or_null (context, lightdm_greeter_get_select_user_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return string_or_null(context, lightdm_greeter_get_select_user_hint(greeter));
}
static JSValueRef
get_select_guest_cb (JSContextRef context,
get_select_guest_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return JSValueMakeBoolean (context, lightdm_greeter_get_select_guest_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return JSValueMakeBoolean(context, lightdm_greeter_get_select_guest_hint(greeter));
}
static JSValueRef
get_autologin_user_cb (JSContextRef context,
get_autologin_user_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return string_or_null (context, lightdm_greeter_get_autologin_user_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return string_or_null(context, lightdm_greeter_get_autologin_user_hint(greeter));
}
static JSValueRef
get_autologin_guest_cb (JSContextRef context,
get_autologin_guest_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef * exception) {
LightDMGreeter *greeter = JSObjectGetPrivate (thisObject);
return JSValueMakeBoolean (context, lightdm_greeter_get_autologin_guest_hint (greeter));
JSValueRef *exception) {
LightDMGreeter *greeter = JSObjectGetPrivate(thisObject);
return JSValueMakeBoolean(context, lightdm_greeter_get_autologin_guest_hint(greeter));
}
static JSValueRef
get_is_authenticated_cb(JSContextRef context,
JSObjectRef thisObject,
@ -708,6 +734,7 @@ get_is_authenticated_cb(JSContextRef context,
return JSValueMakeBoolean(context, lightdm_greeter_get_is_authenticated(greeter));
}
static JSValueRef
get_in_authentication_cb(JSContextRef context,
JSObjectRef thisObject,
@ -717,6 +744,7 @@ get_in_authentication_cb(JSContextRef context,
return JSValueMakeBoolean(context, lightdm_greeter_get_in_authentication(greeter));
}
static JSValueRef
get_can_suspend_cb(JSContextRef context,
JSObjectRef thisObject,
@ -733,8 +761,9 @@ suspend_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_suspend(NULL);
return JSValueMakeNull(context);
@ -757,8 +786,9 @@ hibernate_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_hibernate(NULL);
return JSValueMakeNull(context);
@ -781,8 +811,9 @@ restart_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_restart(NULL);
return JSValueMakeNull(context);
@ -805,8 +836,9 @@ shutdown_cb(JSContextRef context,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef *exception) {
if (argumentCount != 0)
return mkexception (context, exception, "Argument count not zero");
if (argumentCount != 0) {
return mkexception(context, exception, "Argument count not zero");
}
lightdm_shutdown(NULL);
return JSValueMakeNull(context);
@ -826,20 +858,22 @@ start_session_sync_cb(JSContextRef context,
size_t username_size, session_size;
gchar *username, *session = NULL;
if (!((argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString) ||
(argumentCount == 2 && JSValueGetType (context, arguments[0]) == kJSTypeString && JSValueGetType (context, arguments[1]) == kJSTypeString)))
return mkexception (context, exception, "Username or Session incorrect");
if (!(( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString ) ||
( argumentCount == 2 && JSValueGetType(context, arguments[0]) == kJSTypeString
&& JSValueGetType(context, arguments[1]) == kJSTypeString ))) {
return mkexception(context, exception, "Username or Session incorrect");
}
arg = JSValueToStringCopy(context, arguments[0], NULL);
username_size = JSStringGetMaximumUTF8CStringSize(arg);
username = g_malloc (username_size);
username = g_malloc(username_size);
JSStringGetUTF8CString(arg, username, username_size);
JSStringRelease(arg);
if (argumentCount > 1) {
arg = JSValueToStringCopy(context, arguments[1], NULL);
session_size = JSStringGetMaximumUTF8CStringSize(arg);
session = g_malloc (session_size);
session = g_malloc(session_size);
JSStringGetUTF8CString(arg, session, session_size);
JSStringRelease(arg);
}
@ -866,18 +900,19 @@ set_language_cb(JSContextRef context,
size_t language_size;
gchar *language;
if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString))
return mkexception (context, exception, "Language not supplied");
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return mkexception(context, exception, "Language not supplied");
}
arg = JSValueToStringCopy(context, arguments[0], NULL);
language_size = JSStringGetMaximumUTF8CStringSize(arg);
language = g_malloc (language_size);
language = g_malloc(language_size);
JSStringGetUTF8CString(arg, language, language_size);
JSStringRelease(arg);
lightdm_greeter_set_language(greeter, language);
g_free (language);
g_free(language);
return JSValueMakeNull(context);
}
@ -895,19 +930,20 @@ gettext_cb(JSContextRef context,
gchar *string;
JSValueRef result;
if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString))
return mkexception (context, exception, "Argument not supplied");
if (!( argumentCount == 1 && JSValueGetType(context, arguments[0]) == kJSTypeString )) {
return mkexception(context, exception, "Argument not supplied");
}
string_arg = JSValueToStringCopy(context, arguments[0], NULL);
string_size = JSStringGetMaximumUTF8CStringSize(string_arg);
string = g_malloc (string_size);
string = g_malloc(string_size);
JSStringGetUTF8CString(string_arg, string, string_size);
JSStringRelease(string_arg);
text = JSStringCreateWithUTF8CString(gettext(string));
g_free (string);
g_free(string);
result = JSValueMakeString(context, text);
JSStringRelease (text);
JSStringRelease(text);
return result;
}
@ -927,28 +963,29 @@ ngettext_cb(JSContextRef context,
unsigned int n;
JSValueRef result;
if (argumentCount != 3)
return mkexception (context, exception, "Needs 3 arguments");
if (argumentCount != 3) {
return mkexception(context, exception, "Needs 3 arguments");
}
string_arg = JSValueToStringCopy(context, arguments[0], NULL);
string_size = JSStringGetMaximumUTF8CStringSize(string_arg);
string = g_malloc (string_size);
string = g_malloc(string_size);
JSStringGetUTF8CString(string_arg, string, string_size);
JSStringRelease(string_arg);
plural_string_arg = JSValueToStringCopy(context, arguments[1], NULL);
plural_string_size = JSStringGetMaximumUTF8CStringSize(plural_string_arg);
plural_string = g_malloc (plural_string_size);
plural_string = g_malloc(plural_string_size);
JSStringGetUTF8CString(plural_string_arg, string, plural_string_size);
JSStringRelease(plural_string_arg);
n = JSValueToNumber(context, arguments[2], NULL);
text = JSStringCreateWithUTF8CString(ngettext(string, plural_string, n));
g_free (string);
g_free (plural_string);
g_free(string);
g_free(plural_string);
result = JSValueMakeString(context, text);
JSStringRelease (text);
JSStringRelease(text);
return result;
}
@ -1184,8 +1221,8 @@ show_prompt_cb(LightDMGreeter *greeter,
break;
}
etext = escape (text);
string = g_strdup_printf ("show_prompt('%s', '%s')", etext, ct);
etext = escape(text);
string = g_strdup_printf("show_prompt('%s', '%s')", etext, ct);
command = JSStringCreateWithUTF8CString(string);
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);
@ -1225,8 +1262,8 @@ show_message_cb(LightDMGreeter *greeter,
break;
}
etext = escape (text);
string = g_strdup_printf ("show_prompt('%s', '%s')", etext, mt);
etext = escape(text);
string = g_strdup_printf("show_prompt('%s', '%s')", etext, mt);
command = JSStringCreateWithUTF8CString(string);
JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL);
@ -1258,6 +1295,7 @@ authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extensio
}
}
static void
autologin_timer_expired_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) {

Loading…
Cancel
Save