Changeset 580 for trunk/zoo-project/zoo-kernel/service_internal_js.c
- Timestamp:
- Feb 12, 2015, 11:18:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal_js.c
r576 r580 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 31 31 static char dbg[1024]; 32 32 33 /** 34 * The function used as alert from the JavaScript environment (ZOO-API) 35 * 36 * @param cx the JavaScript context 37 * @param argc the number of parameters 38 * @param argv1 the parameter values 39 * @return true 40 */ 33 41 JSBool 34 42 JSAlert(JSContext *cx, uintN argc, jsval *argv1) … … 48 56 } 49 57 58 /** 59 * The function used as importScript from the JavaScript environment (ZOO-API) 60 * 61 * @param cx the JavaScript context 62 * @param argc the number of parameters 63 * @param argv1 the parameter values 64 * @return true 65 */ 50 66 JSBool 51 67 JSLoadScripts(JSContext *cx, uintN argc, jsval *argv1) … … 79 95 } 80 96 81 82 int zoo_js_support(maps** main_conf,map* request,service* s, 83 maps **inputs,maps **outputs) 97 /** 98 * Load a JavaScript file then run the function corresponding to the service by 99 * passing the conf, inputs and outputs parameters by value as JavaScript 100 * Objects. 101 * 102 * @param main_conf the conf maps containing the main.cfg settings 103 * @param request the map containing the HTTP request 104 * @param s the service structure 105 * @param inputs the maps containing the inputs 106 * @param outputs the maps containing the outputs 107 * @return ZOO_SERVICE_SUCCEEDED or ZOO_SERVICE_FAILED if the service run, -1 108 * if the service failed to load or throw error at runtime. 109 */ 110 int zoo_js_support(maps** main_conf,map* request,service* s,maps **inputs,maps **outputs) 84 111 { 85 112 maps* main=*main_conf; … … 355 382 } 356 383 384 /** 385 * Load a JavaScript file 386 * 387 * @param cx the JavaScript context 388 * @param globale the global JavaScript object (not used) 389 * @param filename the file name to load 390 * @return a JavaScript Object on success, NULL if an errro occured 391 */ 357 392 JSObject * loadZooApiFile(JSContext *cx,JSObject *global, char* filename){ 358 393 struct stat api_status; … … 381 416 } 382 417 418 /** 419 * Convert a maps to a JavaScript Object 420 * 421 * @param cx the JavaScript context 422 * @param t the maps to convert 423 * @return a new JavaScript Object 424 */ 383 425 JSObject* JSObject_FromMaps(JSContext *cx,maps* t){ 384 385 426 JSObject* res=JS_NewObject(cx, NULL, NULL, NULL); 386 427 //JSObject *res = JS_NewArrayObject(cx, 0, NULL); … … 402 443 } 403 444 445 /** 446 * Convert a map to a JavaScript Object 447 * 448 * @param cx the JavaScript context 449 * @param t the map to convert 450 * @return a new JavaScript Object 451 */ 404 452 JSObject* JSObject_FromMap(JSContext *cx,map* t){ 405 453 JSObject* res=JS_NewObject(cx, NULL, NULL, NULL); … … 454 502 } 455 503 504 /** 505 * Convert a JavaScript Object to a maps 506 * 507 * @param cx the JavaScript context 508 * @param t the JavaScript Object to convert 509 * @return a new maps containing the JavaScript Object 510 */ 456 511 maps* mapsFromJSObject(JSContext *cx,jsval t){ 457 512 maps *res=NULL; … … 629 684 } 630 685 686 /** 687 * Convert a JavaScript Object to a map 688 * 689 * @param cx the JavaScript context 690 * @param t the JavaScript Object to convert 691 * @return a new map containing the JavaScript Object 692 */ 631 693 map* mapFromJSObject(JSContext *cx,jsval t){ 632 694 map *res=NULL; … … 684 746 } 685 747 686 /* The error reporter callback. */ 748 /** 749 * Print debug information messages on stderr 750 * 751 * @param cx the JavaScript context 752 * @param message the error message 753 * @param report the JavaScript Error Report 754 */ 687 755 void reportError(JSContext *cx, const char *message, JSErrorReport *report) 688 756 { … … 697 765 } 698 766 767 /** 768 * Convert a JavaScript value to a char* 769 * 770 * @param context the JavaScript context 771 * @param arg the JavaScript value 772 * @return a new char* 773 * @warning be sure to free the ressources returned by this function 774 */ 699 775 char* JSValToChar(JSContext* context, jsval* arg) { 700 776 char *c; … … 724 800 } 725 801 802 /** 803 * Set the HTTP header of a request 804 * 805 * @param handle the HINTERNET handle 806 * @param cx the JavaScript context 807 * @param header the JavaScript Array containing the headers to send 808 * @return the HINTERNET handle 809 */ 726 810 HINTERNET setHeader(HINTERNET* handle,JSContext *cx,JSObject *header){ 727 811 jsuint length=0; … … 758 842 } 759 843 844 /** 845 * The function used as ZOOTranslate from the JavaScript environment. 846 * Use the ZOO-Services messages translation function from the Python 847 * environment (ZOO-API) 848 * 849 * @param cx the JavaScript context 850 * @param argc the number of parameters 851 * @param argv1 the parameter values 852 * @return true 853 */ 760 854 JSBool 761 855 JSTranslate(JSContext *cx, uintN argc, jsval *argv1) … … 769 863 } 770 864 865 /** 866 * The function used as ZOORequest from the JavaScript environment (ZOO-API) 867 * 868 * @param cx the JavaScript context 869 * @param argc the number of parameters 870 * @param argv1 the parameter values 871 * @return true 872 * @see setHeader 873 */ 771 874 JSBool 772 875 JSRequest(JSContext *cx, uintN argc, jsval *argv1) … … 847 950 return JS_TRUE; 848 951 } 952 953 /** 954 * The function used as ZOOUpdateStatus from the JavaScript environment 955 * (ZOO-API). 956 * 957 * @param cx the JavaScript context 958 * @param argc the number of parameters 959 * @param argv1 the parameter values 960 * @return true 961 * @see setHeader 962 */ 963 JSBool 964 JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1) 965 { 966 jsval *argv = JS_ARGV(cx,argv1); 967 JS_MaybeGC(cx); 968 int istatus=0; 969 char *status=NULL; 970 maps *conf; 971 if(argc>2){ 972 #ifdef JS_DEBUG 973 fprintf(stderr,"Number of arguments used to call the function : %i",argc); 974 #endif 975 return JS_FALSE; 976 } 977 conf=mapsFromJSObject(cx,argv[0]); 978 if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){ 979 char tmpStatus[4]; 980 sprintf(tmpStatus,"%i",istatus); 981 tmpStatus[3]=0; 982 status=strdup(tmpStatus); 983 } 984 if(getMapFromMaps(conf,"lenv","status")!=NULL){ 985 if(status!=NULL){ 986 setMapInMaps(conf,"lenv","status",status); 987 free(status); 988 } 989 else 990 setMapInMaps(conf,"lenv","status","15"); 991 _updateStatus(conf); 992 } 993 freeMaps(&conf); 994 free(conf); 995 JS_MaybeGC(cx); 996 return JS_TRUE; 997 } 998
Note: See TracChangeset
for help on using the changeset viewer.