This has the potential to be amazing. As you stated previously, it's rife with possible security and other issues, and I have all sorts of alarms going off in my head warning me away from ever actually trying something like this, but I'm good at ignoring those. Being able to eval arbitrary programs in line... I guess if Apache can use other languages semi-natively, SQL servers should be able to as well.

If you aren't aware of it, some of the techniques used by SWIG ( http://swig.sourceforge.net/ ) may be relevant to your efforts in calling the non native code (although SWIG can get a bit messy at times in their actual implementation).

Planet Drizzle wrote:


  Stewart Smith: A MD5 stored procedure for Drizzle… in C
  
<http://www.flamingspork.com/blog/2010/03/17/a-md5-stored-procedure-for-drizzle-in-c/>

So, just in case that wasn’t evil enough <http://www.flamingspork.com/blog/2010/03/17/stored-proceduresfunctions-for-drizzle/> for you… perhaps you have something you want to know the MD5 checksum of. So, you could just do this:

drizzle> select md5('Hello World!');
+----------------------------------+
| md5('Hello World!')              |
+----------------------------------+
| ed076287532e86365e841e92bfc50d8c |
+----------------------------------+
1 row in set (0 sec)

But that is *soooo boring*.

Since we have the SSL libs already loaded into Drizzle <http://drizzle.org>, and using my very evil libtcc plugin <https://code.launchpad.net/%7Estewart-flamingspork/drizzle/drizzle-libtcc-function>… we could just implement it in C. We can even use malloc!

|drizzle> SELECT LIBTCC("#include <string.h>\n#include <stdlib.h>\n#include <openssl/md5.h>\nint foo(char* s) { char *a = malloc(100); MD5_CTX context; unsigned char digest[16]; MD5_Init(&context); strcpy(a,\"Hello World!\"); MD5_Update(&context, a, strlen(a)); MD5_Final(digest, &context); snprintf(s, 33, \"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\", digest[0], digest[1], digest[2], digest[3],digest[4], digest[5], digest[6], digest[7],digest[8], digest[9], digest[10], digest[11],digest[12], digest[13], digest[14], digest[15]); free(a); return 32; }") AS RESULT;
|

+----------------------------------+
| RESULT                           |
+----------------------------------+
| ed076287532e86365e841e92bfc50d8c |
+----------------------------------+
1 row in set (0.01 sec)
Currently the parameter is static in the C version due to me not having… well.. done a good job implementing the calling of C code.

URL: http://www.flamingspork.com/blog/2010/03/17/a-md5-stored-procedure-for-drizzle-in-c/

------------------------------------------------------------------------

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp


--
Erik Jacobson
Server Administrator
Themis Media ( http://www.themis-media.com/ )
The Escapist ( http://www.escapistmagazine.com/ )
( Vim, Tabs, BSD Braces, Debian, and Perl )

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to