v8js_class.cc 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2013 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. +----------------------------------------------------------------------+
  12. */
  13. #ifdef HAVE_CONFIG_H
  14. #include "config.h"
  15. #endif
  16. extern "C" {
  17. #include "php.h"
  18. #include "ext/date/php_date.h"
  19. #include "ext/standard/php_string.h"
  20. #include "zend_interfaces.h"
  21. #include "zend_closures.h"
  22. #include "ext/spl/spl_exceptions.h"
  23. #include "zend_exceptions.h"
  24. }
  25. #include "php_v8js_macros.h"
  26. #include "v8js_v8.h"
  27. #include "v8js_debug.h"
  28. #include "v8js_exceptions.h"
  29. #include "v8js_v8object_class.h"
  30. #include "v8js_timer.h"
  31. #include <functional>
  32. #define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
  33. /* {{{ Class Entries */
  34. static zend_class_entry *php_ce_v8js;
  35. /* }}} */
  36. /* {{{ Object Handlers */
  37. static zend_object_handlers v8js_object_handlers;
  38. /* }}} */
  39. typedef struct _v8js_script {
  40. char *name;
  41. v8::Isolate *isolate;
  42. v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
  43. } v8js_script;
  44. static void v8js_script_free(v8js_script *res, bool dispose_persistent);
  45. int le_v8js_script;
  46. /* {{{ Extension container */
  47. struct v8js_jsext {
  48. zend_bool auto_enable;
  49. HashTable *deps_ht;
  50. const char **deps;
  51. int deps_count;
  52. char *name;
  53. char *source;
  54. };
  55. /* }}} */
  56. #if PHP_V8_API_VERSION >= 4004010
  57. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  58. public:
  59. virtual void* Allocate(size_t length) {
  60. void* data = AllocateUninitialized(length);
  61. return data == NULL ? data : memset(data, 0, length);
  62. }
  63. virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  64. virtual void Free(void* data, size_t) { free(data); }
  65. };
  66. #endif
  67. static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
  68. {
  69. v8js_ctx *c = (v8js_ctx *) object;
  70. zend_object_std_dtor(&c->std TSRMLS_CC);
  71. if (c->pending_exception) {
  72. zval_ptr_dtor(&c->pending_exception);
  73. }
  74. if (c->module_loader) {
  75. zval_ptr_dtor(&c->module_loader);
  76. }
  77. /* Delete PHP global object from JavaScript */
  78. if (!c->context.IsEmpty()) {
  79. v8::Locker locker(c->isolate);
  80. v8::Isolate::Scope isolate_scope(c->isolate);
  81. v8::HandleScope handle_scope(c->isolate);
  82. v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(c->isolate, c->context);
  83. v8::Context::Scope context_scope(v8_context);
  84. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(c->isolate, c->object_name);
  85. V8JS_GLOBAL(c->isolate)->Delete(object_name_js);
  86. }
  87. c->object_name.Reset();
  88. c->object_name.~Persistent();
  89. c->global_template.Reset();
  90. c->global_template.~Persistent();
  91. /* Clear persistent handles in template cache */
  92. for (std::map<const char *,v8js_tmpl_t>::iterator it = c->template_cache.begin();
  93. it != c->template_cache.end(); ++it) {
  94. it->second.Reset();
  95. }
  96. c->template_cache.~map();
  97. /* Clear contexts */
  98. for (std::vector<v8js_accessor_ctx*>::iterator it = c->accessor_list.begin();
  99. it != c->accessor_list.end(); ++it) {
  100. v8js_accessor_ctx_dtor(*it TSRMLS_CC);
  101. }
  102. c->accessor_list.~vector();
  103. /* Clear global object, dispose context */
  104. if (!c->context.IsEmpty()) {
  105. c->context.Reset();
  106. }
  107. c->context.~Persistent();
  108. /* Dispose yet undisposed weak refs */
  109. for (std::map<zval *, v8js_persistent_obj_t>::iterator it = c->weak_objects.begin();
  110. it != c->weak_objects.end(); ++it) {
  111. zval *value = it->first;
  112. zval_ptr_dtor(&value);
  113. c->isolate->AdjustAmountOfExternalAllocatedMemory(-1024);
  114. it->second.Reset();
  115. }
  116. c->weak_objects.~map();
  117. for (std::map<v8js_tmpl_t *, v8js_persistent_obj_t>::iterator it = c->weak_closures.begin();
  118. it != c->weak_closures.end(); ++it) {
  119. v8js_tmpl_t *persist_tpl_ = it->first;
  120. persist_tpl_->Reset();
  121. delete persist_tpl_;
  122. it->second.Reset();
  123. }
  124. c->weak_closures.~map();
  125. for (std::list<v8js_v8object *>::iterator it = c->v8js_v8objects.begin();
  126. it != c->v8js_v8objects.end(); it ++) {
  127. (*it)->v8obj.Reset();
  128. (*it)->ctx = NULL;
  129. }
  130. c->v8js_v8objects.~list();
  131. /* Clear persistent handles in module cache */
  132. for (std::map<char *, v8js_persistent_obj_t>::iterator it = c->modules_loaded.begin();
  133. it != c->modules_loaded.end(); ++it) {
  134. efree(it->first);
  135. it->second.Reset();
  136. }
  137. c->modules_loaded.~map();
  138. if(c->isolate) {
  139. /* c->isolate is initialized by V8Js::__construct, but __wakeup calls
  140. * are not fully constructed and hence this would cause a NPE. */
  141. c->isolate->Dispose();
  142. }
  143. if(c->tz != NULL) {
  144. free(c->tz);
  145. }
  146. c->modules_stack.~vector();
  147. c->modules_base.~vector();
  148. efree(object);
  149. }
  150. /* }}} */
  151. static zend_object_value v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
  152. {
  153. zend_object_value retval;
  154. v8js_ctx *c;
  155. c = (v8js_ctx *) ecalloc(1, sizeof(*c));
  156. zend_object_std_init(&c->std, ce TSRMLS_CC);
  157. TSRMLS_SET_CTX(c->zts_ctx);
  158. #if PHP_VERSION_ID >= 50400
  159. object_properties_init(&c->std, ce);
  160. #else
  161. zval *tmp;
  162. zend_hash_copy(c->std.properties, &ce->default_properties,
  163. (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
  164. #endif
  165. new(&c->object_name) v8::Persistent<v8::String>();
  166. new(&c->context) v8::Persistent<v8::Context>();
  167. new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
  168. new(&c->modules_stack) std::vector<char*>();
  169. new(&c->modules_base) std::vector<char*>();
  170. new(&c->modules_loaded) std::map<char *, v8js_persistent_obj_t, cmp_str>;
  171. new(&c->template_cache) std::map<const char *,v8js_tmpl_t>();
  172. new(&c->accessor_list) std::vector<v8js_accessor_ctx *>();
  173. new(&c->weak_closures) std::map<v8js_tmpl_t *, v8js_persistent_obj_t>();
  174. new(&c->weak_objects) std::map<zval *, v8js_persistent_obj_t>();
  175. new(&c->v8js_v8objects) std::list<v8js_v8object *>();
  176. retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) v8js_free_storage, NULL TSRMLS_CC);
  177. retval.handlers = &v8js_object_handlers;
  178. return retval;
  179. }
  180. /* }}} */
  181. static void v8js_free_ext_strarr(const char **arr, int count) /* {{{ */
  182. {
  183. int i;
  184. if (arr) {
  185. for (i = 0; i < count; i++) {
  186. if (arr[i]) {
  187. free((void *) arr[i]);
  188. }
  189. }
  190. free(arr);
  191. }
  192. }
  193. /* }}} */
  194. static void v8js_jsext_dtor(v8js_jsext *jsext) /* {{{ */
  195. {
  196. if (jsext->deps_ht) {
  197. zend_hash_destroy(jsext->deps_ht);
  198. free(jsext->deps_ht);
  199. }
  200. if (jsext->deps) {
  201. v8js_free_ext_strarr(jsext->deps, jsext->deps_count);
  202. }
  203. free(jsext->name);
  204. free(jsext->source);
  205. }
  206. /* }}} */
  207. static int v8js_create_ext_strarr(const char ***retval, int count, HashTable *ht) /* {{{ */
  208. {
  209. const char **exts = NULL;
  210. HashPosition pos;
  211. zval **tmp;
  212. int i = 0;
  213. exts = (const char **) calloc(1, count * sizeof(char *));
  214. zend_hash_internal_pointer_reset_ex(ht, &pos);
  215. while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &pos) == SUCCESS) {
  216. if (Z_TYPE_PP(tmp) == IS_STRING) {
  217. exts[i++] = zend_strndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
  218. } else {
  219. v8js_free_ext_strarr(exts, i);
  220. return FAILURE;
  221. }
  222. zend_hash_move_forward_ex(ht, &pos);
  223. }
  224. *retval = exts;
  225. return SUCCESS;
  226. }
  227. /* }}} */
  228. static void v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */
  229. {
  230. v8::Isolate *isolate = v8::Isolate::GetCurrent();
  231. if (isolate) {
  232. isolate->Exit();
  233. }
  234. if (location) {
  235. zend_error(E_ERROR, "%s %s", location, message);
  236. } else {
  237. zend_error(E_ERROR, "%s", message);
  238. }
  239. }
  240. /* }}} */
  241. /* {{{ proto void V8Js::__construct([string object_name [, array variables [, array extensions [, bool report_uncaught_exceptions]]])
  242. __construct for V8Js */
  243. static PHP_METHOD(V8Js, __construct)
  244. {
  245. char *object_name = NULL, *class_name = NULL;
  246. int object_name_len = 0, free = 0;
  247. zend_uint class_name_len = 0;
  248. zend_bool report_uncaught = 1;
  249. zval *vars_arr = NULL, *exts_arr = NULL;
  250. const char **exts = NULL;
  251. int exts_count = 0;
  252. v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  253. if (!c->context.IsEmpty()) {
  254. /* called __construct() twice, bail out */
  255. return;
  256. }
  257. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|saab", &object_name, &object_name_len, &vars_arr, &exts_arr, &report_uncaught) == FAILURE) {
  258. return;
  259. }
  260. /* Initialize V8 */
  261. v8js_v8_init(TSRMLS_C);
  262. /* Throw PHP exception if uncaught exceptions exist */
  263. c->report_uncaught = report_uncaught;
  264. c->pending_exception = NULL;
  265. c->in_execution = 0;
  266. #if PHP_V8_API_VERSION >= 4004044
  267. static ArrayBufferAllocator array_buffer_allocator;
  268. static v8::Isolate::CreateParams create_params;
  269. create_params.array_buffer_allocator = &array_buffer_allocator;
  270. c->isolate = v8::Isolate::New(create_params);
  271. #else
  272. c->isolate = v8::Isolate::New();
  273. #endif
  274. c->isolate->SetData(0, c);
  275. c->time_limit = 0;
  276. c->time_limit_hit = false;
  277. c->memory_limit = 0;
  278. c->memory_limit_hit = false;
  279. c->module_loader = NULL;
  280. /* Include extensions used by this context */
  281. /* Note: Extensions registered with auto_enable do not need to be added separately like this. */
  282. if (exts_arr)
  283. {
  284. exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr));
  285. if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) {
  286. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid extensions array passed");
  287. return;
  288. }
  289. }
  290. /* Declare configuration for extensions */
  291. v8::ExtensionConfiguration extension_conf(exts_count, exts);
  292. // Isolate execution
  293. v8::Isolate *isolate = c->isolate;
  294. v8::Locker locker(isolate);
  295. v8::Isolate::Scope isolate_scope(isolate);
  296. /* Handle scope */
  297. v8::HandleScope handle_scope(isolate);
  298. /* Redirect fatal errors to PHP error handler */
  299. // This needs to be done within the context isolate
  300. v8::V8::SetFatalErrorHandler(v8js_fatal_error_handler);
  301. /* Create global template for global object */
  302. // Now we are using multiple isolates this needs to be created for every context
  303. v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
  304. tpl->SetClassName(V8JS_SYM("V8Js"));
  305. c->global_template.Reset(isolate, tpl);
  306. /* Register builtin methods */
  307. v8js_register_methods(tpl->InstanceTemplate(), c);
  308. /* Create context */
  309. v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
  310. if (exts) {
  311. v8js_free_ext_strarr(exts, exts_count);
  312. }
  313. /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
  314. if (context.IsEmpty()) {
  315. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create V8 context. Check that registered extensions do not have errors.");
  316. ZVAL_NULL(getThis());
  317. return;
  318. }
  319. context->SetAlignedPointerInEmbedderData(1, c);
  320. c->context.Reset(isolate, context);
  321. /* Enter context */
  322. v8::Context::Scope context_scope(context);
  323. /* Create the PHP container object's function template */
  324. v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
  325. /* Set class name for PHP object */
  326. #if PHP_VERSION_ID >= 50400
  327. free = !zend_get_object_classname(getThis(), const_cast<const char**>(&class_name), &class_name_len TSRMLS_CC);
  328. #else
  329. free = !zend_get_object_classname(getThis(), &class_name, &class_name_len TSRMLS_CC);
  330. #endif
  331. php_obj_t->SetClassName(V8JS_SYML(class_name, class_name_len));
  332. if (free) {
  333. efree(class_name);
  334. }
  335. /* Register Get accessor for passed variables */
  336. if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
  337. v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
  338. }
  339. /* Set name for the PHP JS object */
  340. v8::Local<v8::String> object_name_js = (object_name_len) ? V8JS_SYML(object_name, object_name_len) : V8JS_SYM("PHP");
  341. c->object_name.Reset(isolate, object_name_js);
  342. /* Add the PHP object into global object */
  343. v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance();
  344. V8JS_GLOBAL(isolate)->ForceSet(object_name_js, php_obj, v8::ReadOnly);
  345. /* Export public property values */
  346. HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
  347. HashPosition pos;
  348. zval **value;
  349. ulong index;
  350. char *member;
  351. uint member_len;
  352. for(zend_hash_internal_pointer_reset_ex(properties, &pos);
  353. zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS;
  354. zend_hash_move_forward_ex(properties, &pos)) {
  355. if(zend_hash_get_current_key_ex(properties, &member, &member_len, &index, 0, &pos) != HASH_KEY_IS_STRING) {
  356. continue;
  357. }
  358. zval zmember;
  359. INIT_ZVAL(zmember);
  360. ZVAL_STRING(&zmember, member, 0);
  361. zend_property_info *property_info = zend_get_property_info(c->std.ce, &zmember, 1 TSRMLS_CC);
  362. if(property_info && property_info->flags & ZEND_ACC_PUBLIC) {
  363. /* Write value to PHP JS object */
  364. php_obj->ForceSet(V8JS_SYML(member, member_len - 1), zval_to_v8js(*value, isolate TSRMLS_CC), v8::ReadOnly);
  365. }
  366. }
  367. }
  368. /* }}} */
  369. /* {{{ proto V8JS::__sleep()
  370. */
  371. PHP_METHOD(V8Js, __sleep)
  372. {
  373. zend_throw_exception(php_ce_v8js_exception,
  374. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  375. RETURN_FALSE;
  376. }
  377. /* }}} */
  378. /* {{{ proto V8JS::__wakeup()
  379. */
  380. PHP_METHOD(V8Js, __wakeup)
  381. {
  382. zend_throw_exception(php_ce_v8js_exception,
  383. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  384. RETURN_FALSE;
  385. }
  386. /* }}} */
  387. static void v8js_compile_script(zval *this_ptr, const char *str, int str_len, const char *identifier, int identifier_len, v8js_script **ret TSRMLS_DC)
  388. {
  389. v8js_script *res = NULL;
  390. V8JS_BEGIN_CTX(c, this_ptr)
  391. /* Catch JS exceptions */
  392. v8::TryCatch try_catch;
  393. /* Set script identifier */
  394. v8::Local<v8::String> sname = identifier_len ? V8JS_SYML(identifier, identifier_len) : V8JS_SYM("V8Js::compileString()");
  395. /* Compiles a string context independently. TODO: Add a php function which calls this and returns the result as resource which can be executed later. */
  396. v8::Local<v8::String> source = V8JS_STRL(str, str_len);
  397. v8::Local<v8::Script> script = v8::Script::Compile(source, sname);
  398. /* Compile errors? */
  399. if (script.IsEmpty()) {
  400. v8js_throw_script_exception(&try_catch TSRMLS_CC);
  401. return;
  402. }
  403. res = (v8js_script *)emalloc(sizeof(v8js_script));
  404. res->script = new v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>>(c->isolate, script);
  405. v8::String::Utf8Value _sname(sname);
  406. res->name = estrndup(ToCString(_sname), _sname.length());
  407. res->isolate = c->isolate;
  408. *ret = res;
  409. return;
  410. }
  411. static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value TSRMLS_DC)
  412. {
  413. v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  414. if (res->isolate != c->isolate) {
  415. zend_error(E_WARNING, "Script resource from wrong V8Js object passed");
  416. ZVAL_BOOL(*return_value, 0);
  417. return;
  418. }
  419. if (!c->in_execution && time_limit == 0) {
  420. time_limit = c->time_limit;
  421. }
  422. if (!c->in_execution && memory_limit == 0) {
  423. memory_limit = c->memory_limit;
  424. }
  425. std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [res](v8::Isolate *isolate) {
  426. v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
  427. return script->Run();
  428. };
  429. v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call TSRMLS_CC);
  430. }
  431. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  432. */
  433. static PHP_METHOD(V8Js, executeString)
  434. {
  435. char *str = NULL, *identifier = NULL, *tz = NULL;
  436. int str_len = 0, identifier_len = 0;
  437. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  438. v8js_script *res = NULL;
  439. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slll", &str, &str_len, &identifier, &identifier_len, &flags, &time_limit, &memory_limit) == FAILURE) {
  440. return;
  441. }
  442. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  443. if (!res) {
  444. RETURN_FALSE;
  445. }
  446. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  447. v8js_script_free(res, true);
  448. efree(res);
  449. }
  450. /* }}} */
  451. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  452. */
  453. static PHP_METHOD(V8Js, compileString)
  454. {
  455. char *str = NULL, *identifier = NULL;
  456. int str_len = 0, identifier_len = 0;
  457. v8js_script *res = NULL;
  458. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &identifier, &identifier_len) == FAILURE) {
  459. return;
  460. }
  461. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  462. if (res) {
  463. ZEND_REGISTER_RESOURCE(return_value, res, le_v8js_script);
  464. }
  465. return;
  466. }
  467. /* }}} */
  468. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  469. */
  470. static PHP_METHOD(V8Js, executeScript)
  471. {
  472. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  473. zval *zscript;
  474. v8js_script *res;
  475. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  476. return;
  477. }
  478. ZEND_FETCH_RESOURCE(res, v8js_script*, &zscript, -1, PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script);
  479. ZEND_VERIFY_RESOURCE(res);
  480. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  481. }
  482. /* }}} */
  483. /* {{{ proto mixed V8Js::checkString(string script)
  484. */
  485. static PHP_METHOD(V8Js, checkString)
  486. {
  487. char *str = NULL;
  488. int str_len = 0;
  489. const char *identifier = "V8Js::checkString()";
  490. int identifier_len = 19;
  491. v8js_script *res = NULL;
  492. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
  493. return;
  494. }
  495. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  496. if (!res) {
  497. RETURN_FALSE;
  498. }
  499. v8js_script_free(res, true);
  500. efree(res);
  501. RETURN_TRUE;
  502. }
  503. /* }}} */
  504. /* {{{ proto mixed V8Js::getPendingException()
  505. */
  506. static PHP_METHOD(V8Js, getPendingException)
  507. {
  508. v8js_ctx *c;
  509. if (zend_parse_parameters_none() == FAILURE) {
  510. return;
  511. }
  512. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  513. if (c->pending_exception) {
  514. RETURN_ZVAL(c->pending_exception, 1, 0);
  515. }
  516. }
  517. /* }}} */
  518. /* {{{ proto void V8Js::clearPendingException()
  519. */
  520. static PHP_METHOD(V8Js, clearPendingException)
  521. {
  522. v8js_ctx *c;
  523. if (zend_parse_parameters_none() == FAILURE) {
  524. return;
  525. }
  526. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  527. if (c->pending_exception) {
  528. zval_ptr_dtor(&c->pending_exception);
  529. c->pending_exception = NULL;
  530. }
  531. }
  532. /* }}} */
  533. /* {{{ proto void V8Js::setModuleLoader(string module)
  534. */
  535. static PHP_METHOD(V8Js, setModuleLoader)
  536. {
  537. v8js_ctx *c;
  538. zval *callable;
  539. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  540. return;
  541. }
  542. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  543. c->module_loader = callable;
  544. Z_ADDREF_P(c->module_loader);
  545. }
  546. /* }}} */
  547. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  548. */
  549. static PHP_METHOD(V8Js, setTimeLimit)
  550. {
  551. v8js_ctx *c;
  552. long time_limit = 0;
  553. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &time_limit) == FAILURE) {
  554. return;
  555. }
  556. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  557. c->time_limit = time_limit;
  558. V8JSG(timer_mutex).lock();
  559. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  560. it != V8JSG(timer_stack).end(); it ++) {
  561. if((*it)->ctx == c && !(*it)->killed) {
  562. (*it)->time_limit = time_limit;
  563. // Calculate the time point when the time limit is exceeded
  564. std::chrono::milliseconds duration(time_limit);
  565. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  566. (*it)->time_point = from + duration;
  567. }
  568. }
  569. V8JSG(timer_mutex).unlock();
  570. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  571. /* If timer thread is not started already and we now impose a time limit
  572. * finally install the timer. */
  573. V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
  574. }
  575. }
  576. /* }}} */
  577. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  578. */
  579. static PHP_METHOD(V8Js, setMemoryLimit)
  580. {
  581. v8js_ctx *c;
  582. long memory_limit = 0;
  583. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &memory_limit) == FAILURE) {
  584. return;
  585. }
  586. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  587. c->memory_limit = memory_limit;
  588. V8JSG(timer_mutex).lock();
  589. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  590. it != V8JSG(timer_stack).end(); it ++) {
  591. if((*it)->ctx == c && !(*it)->killed) {
  592. (*it)->memory_limit = memory_limit;
  593. }
  594. }
  595. V8JSG(timer_mutex).unlock();
  596. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  597. /* If timer thread is not started already and we now impose a memory limit
  598. * finally install the timer. */
  599. V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
  600. }
  601. }
  602. /* }}} */
  603. static void v8js_persistent_zval_ctor(zval **p) /* {{{ */
  604. {
  605. zval *orig_ptr = *p;
  606. *p = (zval *) malloc(sizeof(zval));
  607. **p = *orig_ptr;
  608. switch (Z_TYPE_P(*p)) {
  609. case IS_STRING:
  610. Z_STRVAL_P(*p) = (char *) zend_strndup(Z_STRVAL_P(*p), Z_STRLEN_P(*p));
  611. break;
  612. default:
  613. zend_bailout();
  614. }
  615. INIT_PZVAL(*p);
  616. }
  617. /* }}} */
  618. static void v8js_persistent_zval_dtor(zval **p) /* {{{ */
  619. {
  620. switch (Z_TYPE_P(*p)) {
  621. case IS_STRING:
  622. free(Z_STRVAL_P(*p));
  623. break;
  624. default:
  625. zend_bailout();
  626. }
  627. free(*p);
  628. }
  629. /* }}} */
  630. static void v8js_script_free(v8js_script *res, bool dispose_persistent)
  631. {
  632. if (res->name) {
  633. efree(res->name);
  634. res->name = NULL;
  635. }
  636. if (dispose_persistent) {
  637. res->script->~Persistent(); // does Reset()
  638. res->script = NULL;
  639. }
  640. }
  641. static void v8js_script_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
  642. {
  643. v8js_script *res = (v8js_script *)rsrc->ptr;
  644. if (res) {
  645. v8js_script_free(res, false);
  646. efree(res);
  647. }
  648. }
  649. /* }}} */
  650. static int v8js_register_extension(char *name, uint name_len, char *source, uint source_len, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
  651. {
  652. v8js_jsext *jsext = NULL;
  653. if (!V8JSG(extensions)) {
  654. V8JSG(extensions) = (HashTable *) malloc(sizeof(HashTable));
  655. zend_hash_init(V8JSG(extensions), 1, NULL, (dtor_func_t) v8js_jsext_dtor, 1);
  656. } else if (zend_hash_exists(V8JSG(extensions), name, name_len + 1)) {
  657. return FAILURE;
  658. }
  659. jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
  660. if (deps_arr) {
  661. jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
  662. if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
  663. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
  664. v8js_jsext_dtor(jsext);
  665. free(jsext);
  666. return FAILURE;
  667. }
  668. }
  669. jsext->auto_enable = auto_enable;
  670. jsext->name = zend_strndup(name, name_len);
  671. jsext->source = zend_strndup(source, source_len);
  672. if (jsext->deps) {
  673. jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
  674. zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, (dtor_func_t) v8js_persistent_zval_dtor, 1);
  675. zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), (copy_ctor_func_t) v8js_persistent_zval_ctor, NULL, sizeof(zval *));
  676. }
  677. if (zend_hash_add(V8JSG(extensions), name, name_len + 1, jsext, sizeof(v8js_jsext), NULL) == FAILURE) {
  678. v8js_jsext_dtor(jsext);
  679. free(jsext);
  680. return FAILURE;
  681. }
  682. v8::Extension *extension = new v8::Extension(jsext->name, jsext->source, jsext->deps_count, jsext->deps);
  683. extension->set_auto_enable(auto_enable ? true : false);
  684. v8::RegisterExtension(extension);
  685. free(jsext);
  686. return SUCCESS;
  687. }
  688. /* }}} */
  689. /* {{{ proto bool V8Js::registerExtension(string ext_name, string script [, array deps [, bool auto_enable]])
  690. */
  691. static PHP_METHOD(V8Js, registerExtension)
  692. {
  693. char *ext_name, *script;
  694. zval *deps_arr = NULL;
  695. int ext_name_len, script_len;
  696. zend_bool auto_enable = 0;
  697. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ab", &ext_name, &ext_name_len, &script, &script_len, &deps_arr, &auto_enable) == FAILURE) {
  698. return;
  699. }
  700. if (!ext_name_len) {
  701. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
  702. } else if (!script_len) {
  703. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
  704. } else if (v8js_register_extension(ext_name, ext_name_len, script, script_len, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
  705. RETURN_TRUE;
  706. }
  707. RETURN_FALSE;
  708. }
  709. /* }}} */
  710. /* ## Static methods ## */
  711. /* {{{ proto array V8Js::getExtensions()
  712. */
  713. static PHP_METHOD(V8Js, getExtensions)
  714. {
  715. v8js_jsext *jsext;
  716. zval *ext, *deps_arr;
  717. HashPosition pos;
  718. ulong index;
  719. char *key;
  720. uint key_len;
  721. if (zend_parse_parameters_none() == FAILURE) {
  722. return;
  723. }
  724. array_init(return_value);
  725. if (V8JSG(extensions)) {
  726. zend_hash_internal_pointer_reset_ex(V8JSG(extensions), &pos);
  727. while (zend_hash_get_current_data_ex(V8JSG(extensions), (void **) &jsext, &pos) == SUCCESS) {
  728. if (zend_hash_get_current_key_ex(V8JSG(extensions), &key, &key_len, &index, 0, &pos) == HASH_KEY_IS_STRING) {
  729. MAKE_STD_ZVAL(ext)
  730. array_init(ext);
  731. add_assoc_bool_ex(ext, ZEND_STRS("auto_enable"), jsext->auto_enable);
  732. if (jsext->deps_ht) {
  733. MAKE_STD_ZVAL(deps_arr);
  734. array_init(deps_arr);
  735. zend_hash_copy(Z_ARRVAL_P(deps_arr), jsext->deps_ht, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
  736. add_assoc_zval_ex(ext, ZEND_STRS("deps"), deps_arr);
  737. }
  738. add_assoc_zval_ex(return_value, key, key_len, ext);
  739. }
  740. zend_hash_move_forward_ex(V8JSG(extensions), &pos);
  741. }
  742. }
  743. }
  744. /* }}} */
  745. /* {{{ arginfo */
  746. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_construct, 0, 0, 0)
  747. ZEND_ARG_INFO(0, object_name)
  748. ZEND_ARG_INFO(0, variables)
  749. ZEND_ARG_INFO(0, extensions)
  750. ZEND_ARG_INFO(0, report_uncaught_exceptions)
  751. ZEND_END_ARG_INFO()
  752. ZEND_BEGIN_ARG_INFO(arginfo_v8js_sleep, 0)
  753. ZEND_END_ARG_INFO()
  754. ZEND_BEGIN_ARG_INFO(arginfo_v8js_wakeup, 0)
  755. ZEND_END_ARG_INFO()
  756. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executestring, 0, 0, 1)
  757. ZEND_ARG_INFO(0, script)
  758. ZEND_ARG_INFO(0, identifier)
  759. ZEND_ARG_INFO(0, flags)
  760. ZEND_ARG_INFO(0, time_limit)
  761. ZEND_ARG_INFO(0, memory_limit)
  762. ZEND_END_ARG_INFO()
  763. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_compilestring, 0, 0, 1)
  764. ZEND_ARG_INFO(0, script)
  765. ZEND_ARG_INFO(0, identifier)
  766. ZEND_END_ARG_INFO()
  767. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executescript, 0, 0, 1)
  768. ZEND_ARG_INFO(0, script)
  769. ZEND_ARG_INFO(0, flags)
  770. ZEND_ARG_INFO(0, time_limit)
  771. ZEND_ARG_INFO(0, memory_limit)
  772. ZEND_END_ARG_INFO()
  773. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_checkstring, 0, 0, 1)
  774. ZEND_ARG_INFO(0, script)
  775. ZEND_END_ARG_INFO()
  776. #ifdef ENABLE_DEBUGGER_SUPPORT
  777. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_destruct, 0, 0, 0)
  778. ZEND_END_ARG_INFO()
  779. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_startdebugagent, 0, 0, 0)
  780. ZEND_ARG_INFO(0, agentName)
  781. ZEND_ARG_INFO(0, port)
  782. ZEND_ARG_INFO(0, auto_break)
  783. ZEND_END_ARG_INFO()
  784. #endif /* ENABLE_DEBUGGER_SUPPORT */
  785. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getpendingexception, 0)
  786. ZEND_END_ARG_INFO()
  787. ZEND_BEGIN_ARG_INFO(arginfo_v8js_clearpendingexception, 0)
  788. ZEND_END_ARG_INFO()
  789. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1)
  790. ZEND_ARG_INFO(0, callable)
  791. ZEND_END_ARG_INFO()
  792. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_registerextension, 0, 0, 2)
  793. ZEND_ARG_INFO(0, extension_name)
  794. ZEND_ARG_INFO(0, script)
  795. ZEND_ARG_INFO(0, dependencies)
  796. ZEND_ARG_INFO(0, auto_enable)
  797. ZEND_END_ARG_INFO()
  798. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
  799. ZEND_END_ARG_INFO()
  800. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
  801. ZEND_ARG_INFO(0, time_limit)
  802. ZEND_END_ARG_INFO()
  803. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
  804. ZEND_ARG_INFO(0, memory_limit)
  805. ZEND_END_ARG_INFO()
  806. static const zend_function_entry v8js_methods[] = { /* {{{ */
  807. PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  808. PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  809. PHP_ME(V8Js, __wakeup, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  810. PHP_ME(V8Js, executeString, arginfo_v8js_executestring, ZEND_ACC_PUBLIC)
  811. PHP_ME(V8Js, compileString, arginfo_v8js_compilestring, ZEND_ACC_PUBLIC)
  812. PHP_ME(V8Js, executeScript, arginfo_v8js_executescript, ZEND_ACC_PUBLIC)
  813. PHP_ME(V8Js, checkString, arginfo_v8js_checkstring, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
  814. PHP_ME(V8Js, getPendingException, arginfo_v8js_getpendingexception, ZEND_ACC_PUBLIC)
  815. PHP_ME(V8Js, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC)
  816. PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC)
  817. PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  818. PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  819. PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
  820. PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
  821. #ifdef ENABLE_DEBUGGER_SUPPORT
  822. PHP_ME(V8Js, __destruct, arginfo_v8js_destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
  823. PHP_ME(V8Js, startDebugAgent, arginfo_v8js_startdebugagent, ZEND_ACC_PUBLIC)
  824. #endif
  825. {NULL, NULL, NULL}
  826. };
  827. /* }}} */
  828. /* V8Js object handlers */
  829. static void v8js_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
  830. {
  831. V8JS_BEGIN_CTX(c, object)
  832. /* Check whether member is public, if so, export to V8. */
  833. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1 TSRMLS_CC);
  834. if(property_info->flags & ZEND_ACC_PUBLIC) {
  835. /* Global PHP JS object */
  836. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  837. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  838. /* Write value to PHP JS object */
  839. jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  840. }
  841. /* Write value to PHP object */
  842. std_object_handlers.write_property(object, member, value ZEND_HASH_KEY_CC TSRMLS_CC);
  843. }
  844. /* }}} */
  845. static void v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
  846. {
  847. V8JS_BEGIN_CTX(c, object)
  848. /* Global PHP JS object */
  849. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  850. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  851. /* Delete value from PHP JS object */
  852. jsobj->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
  853. /* Unset from PHP object */
  854. std_object_handlers.unset_property(object, member ZEND_HASH_KEY_CC TSRMLS_CC);
  855. }
  856. /* }}} */
  857. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  858. {
  859. zend_class_entry ce;
  860. /* V8Js Class */
  861. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  862. php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
  863. php_ce_v8js->create_object = v8js_new;
  864. /* V8Js handlers */
  865. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  866. v8js_object_handlers.clone_obj = NULL;
  867. v8js_object_handlers.write_property = v8js_write_property;
  868. v8js_object_handlers.unset_property = v8js_unset_property;
  869. /* V8Js Class Constants */
  870. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);
  871. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE TSRMLS_CC);
  872. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY TSRMLS_CC);
  873. #ifdef ENABLE_DEBUGGER_SUPPORT
  874. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_NEVER"), V8JS_DEBUG_AUTO_BREAK_NEVER TSRMLS_CC);
  875. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ONCE"), V8JS_DEBUG_AUTO_BREAK_ONCE TSRMLS_CC);
  876. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ALWAYS"), V8JS_DEBUG_AUTO_BREAK_ALWAYS TSRMLS_CC);
  877. #endif
  878. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  879. #if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
  880. static ArrayBufferAllocator array_buffer_allocator;
  881. v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
  882. #endif
  883. return SUCCESS;
  884. } /* }}} */
  885. /*
  886. * Local variables:
  887. * tab-width: 4
  888. * c-basic-offset: 4
  889. * End:
  890. * vim600: noet sw=4 ts=4 fdm=marker
  891. * vim<600: noet sw=4 ts=4
  892. */