v8js_class.cc 32 KB

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