[Freeswitch-branches] [commit] r7339 - freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey_openssl

Freeswitch SVN anthonyl at freeswitch.org
Thu Jan 24 00:00:34 EST 2008


Author: anthonyl
Date: Thu Jan 24 00:00:34 2008
New Revision: 7339

Added:
   freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey_openssl/mod_spidermonkey_openssl.c

Log:
basic outline of what this will look like, part of me really things this is unneeded bloat, but I do have a creative use or two for this.. oh well


Added: freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey_openssl/mod_spidermonkey_openssl.c
==============================================================================
--- (empty file)
+++ freeswitch/branches/anthonyl/spidermonkey-stuff/src/mod/languages/mod_spidermonkey_openssl/mod_spidermonkey_openssl.c	Thu Jan 24 00:00:34 2008
@@ -0,0 +1,181 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony LaMantia <anthony at petabit.net>
+ *
+ *
+ * mod_spidermonkey_openssl.c -- Experimental OpenSSL extension to Spidermonkey
+ *
+ */
+#include "mod_spidermonkey.h"
+enum hash_flags {
+    HASH_FUNCTION_SHA1 = 1,
+    HASH_FUNCTION_MD5  = 2,
+    HASH_FUNCTION_MD4  = 3,
+};
+enum cipher_flags {
+    CIPHER_FUNCTION_AES = 1,
+    CIPHER_FUNCTION_DSA = 2,
+    CIPHER_FUNCTION_RSA = 3,
+    CIPHER_FUNCTION_RC4 = 4,
+};
+struct _hash_functions {
+    char *name;
+    unsigned char flag;
+    void *ptr;
+} hash_functions[] = {
+    {"SHA1", HASH_FUNCTION_SHA1, NULL},
+    {"MD5",  HASH_FUNCTION_MD5,  NULL},
+    {"MD4",  HASH_FUNCTION_MD4,  NULL}
+};
+struct _cipher_functions {
+    char *name;
+    unsigned char flag;
+    void *ptr;
+} hash_functions[] = {
+    {"AES", CIPHER_FUNCTION_AES, NULL},
+    {"DSA", CIPHER_FUNCTION_DSA, NULL},
+    {"RSA", CIPHER_FUNCTION_RSA, NULL},
+    {"RC4", CIPHER_FUNCTION_RC4, NULL},
+};
+static const char modname[] = "Crypto";
+struct openssl_pvt {
+    unsigned int hash_flag;
+    unsigned int cipher_flag;
+    char         *pvt1;
+    char         *pvt2;
+    JSContext    *js_ctx;
+	JSObject     *js_obj;
+	JSFunction   *js_function;
+	JSObject     *js_user_data;
+	jsrefcount   js_saveDepth;
+	jsval        js_ret;	
+
+};
+/* Skel Object */
+/*********************************************************************************/
+static JSBool crypto_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    struct openssl_pvt *obj_pvt = NULL;
+	obj_pvt = malloc(sizeof(struct openssl_pvt));
+	switch_assert(obj_pvt);
+	memset(obj_pvt, 0, sizeof(struct openssl_pvt));
+	obj_pvt->js_cx  = cx;
+	obj_pvt->js_obj = obj;
+	JS_SetPrivate(cx, obj, obj_pvt);
+	return JS_TRUE;
+}
+static void crypto_destroy(JSContext * cx, JSObject * obj)
+{
+	struct openssl_pvt *obj_pvt = JS_GetPrivate(cx, obj);
+	switch_safe_free(obj_pvt);
+	JS_SetPrivate(cx, obj, NULL);
+}
+static JSBool crypto_set_hashfunc(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+	return JS_FALSE;
+}
+static JSBool crypto_set_cipherfunc(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    return JS_FALSE;
+}
+static JSBool crypto_set_cipherkey(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    return JS_FALSE;
+}
+static JSBool crypto_set_hashseed(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    return JS_FALSE;
+}
+static JSBool crypto_hash(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    return JS_FALSE;
+}
+static JSBool crypto_encrypt(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+    return JS_FALSE;
+}
+enum crypto_tinyid {
+	CRYPTO_NAME
+};
+static JSFunctionSpec crypto_methods[] = {
+	{"setHashFunc",   crypto_set_hashfunc, 1},
+    {"setHashSeed",   crypto_set_hashseed, 1},
+    {"setCipherFunc", crypto_set_cipherfunc, 1},
+    {"setCipherKey",  crypto_set_cipherkey,  1},
+    {"Hash",          crypto_hash, 1},
+    {"Encrypt",       crypto_encrypt,  1},
+	{0}
+};
+
+static JSPropertySpec crypto_props[] = {
+	{"name", CRYPTO_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
+	{0}
+};
+
+static JSBool crypto_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
+{
+	JSBool res = JS_TRUE;
+
+	return res;
+}
+
+JSClass skel_class = {
+	modname, JSCLASS_HAS_PRIVATE,
+	JS_PropertyStub, JS_PropertyStub, crypto_getProperty, DEFAULT_SET_PROPERTY,
+	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, crypto_destroy, NULL, NULL, NULL,
+	crypto_construct
+};
+
+
+switch_status_t spidermonkey_load(JSContext * cx, JSObject * obj)
+{
+	JS_InitClass(cx, obj, NULL, &crypto_class, crypto_construct, 3, crypto_props, crypto_methods, crypto_props, crypto_methods);
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
+const sm_module_interface_t crypto_module_interface = {
+	/*.name = */ modname,
+	/*.spidermonkey_load */ spidermonkey_load,
+	/*.next */ NULL
+};
+
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
+{
+	*module_interface = &crypto_module_interface;
+	return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:nil
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */



More information about the Freeswitch-branches mailing list