diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2010-12-10 18:07:01 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-12-10 18:07:01 +0100 |
commit | 872e54dd993b184b782c44b9c2d53bff0d38a924 (patch) | |
tree | 4a0fc363516e9542fbe4e9f7af2dba79495094f8 /src | |
parent | 907300506b6fadad21363df1a1ef0b01f4906e52 (diff) | |
download | pacrunner-872e54dd993b184b782c44b9c2d53bff0d38a924.tar.gz |
js: Initial javascript engine driver framework implementation
Diffstat (limited to 'src')
-rw-r--r-- | src/js.c | 96 | ||||
-rw-r--r-- | src/js.h | 30 | ||||
-rw-r--r-- | src/pacrunner.h | 5 |
3 files changed, 131 insertions, 0 deletions
diff --git a/src/js.c b/src/js.c new file mode 100644 index 0000000..22dd9dc --- /dev/null +++ b/src/js.c @@ -0,0 +1,96 @@ +/* + * + * PACrunner - Proxy configuration daemon + * + * Copyright (C) 2010 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <errno.h> + +#include "pacrunner.h" +#include "js.h" + +static GSList *js_driver_list = NULL; + +static gint compare_priority(gconstpointer a, gconstpointer b) +{ + const struct pacrunner_js_driver *driver1 = a; + const struct pacrunner_js_driver *driver2 = b; + + return driver2->priority - driver1->priority; +} + +int pacrunner_js_driver_register(struct pacrunner_js_driver *driver) +{ + DBG("driver %p name %s", driver, driver->name); + + js_driver_list = g_slist_insert_sorted(js_driver_list, driver, + compare_priority); + + return 0; +} + +void pacrunner_js_driver_unregister(struct pacrunner_js_driver *driver) +{ + DBG("driver %p name %s", driver, driver->name); + + js_driver_list = g_slist_remove(js_driver_list, driver); +} + +int __pacrunner_js_set_proxy(struct pacrunner_proxy *proxy) +{ + GSList *list; + + for (list = js_driver_list; list; list = list->next) { + struct pacrunner_js_driver *driver = list->data; + + if (driver->set_proxy) + return driver->set_proxy(proxy); + } + + return -ENXIO; +} + +char *__pacrunner_js_execute(const char *url, const char *host) +{ + GSList *list; + + for (list = js_driver_list; list; list = list->next) { + struct pacrunner_js_driver *driver = list->data; + + if (driver->execute) + return driver->execute(url, host); + } + + return NULL; +} + +int __pacrunner_js_init(void) +{ + DBG(""); + + return 0; +} + +void __pacrunner_js_cleanup(void) +{ + DBG(""); +} diff --git a/src/js.h b/src/js.h new file mode 100644 index 0000000..3519047 --- /dev/null +++ b/src/js.h @@ -0,0 +1,30 @@ +/* + * + * PACrunner - Proxy configuration daemon + * + * Copyright (C) 2010 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +struct pacrunner_js_driver { + const char *name; + int priority; + int (*set_proxy) (struct pacrunner_proxy *proxy); + char *(*execute)(const char *url, const char *host); +}; + +int pacrunner_js_driver_register(struct pacrunner_js_driver *driver); +void pacrunner_js_driver_unregister(struct pacrunner_js_driver *driver); diff --git a/src/pacrunner.h b/src/pacrunner.h index 2ec772e..8cf62f4 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -98,3 +98,8 @@ int __pacrunner_mozjs_init(void); void __pacrunner_mozjs_cleanup(void); int __pacrunner_mozjs_set_proxy(struct pacrunner_proxy *proxy); char *__pacrunner_mozjs_execute(const char *url, const char *host); + +int __pacrunner_js_init(void); +void __pacrunner_js_cleanup(void); +int __pacrunner_js_set_proxy(struct pacrunner_proxy *proxy); +char *__pacrunner_js_execute(const char *url, const char *host); |