Changeset 508


Ignore:
Timestamp:
Oct 8, 2014, 4:28:05 PM (6 years ago)
Author:
djay
Message:

Stop blowing the stack in ulinet. Add API function addToMapWithSize for assigning binary data to map. Add support for binary inputs/outputs for the PHP language.

Location:
trunk/zoo-project/zoo-kernel
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service.h

    r507 r508  
    437437      tmp->value=zStrdup(v);
    438438    }
     439  }
     440
     441  static void addToMapWithSize(map* m,const char* n,const char* v,int size){
     442    if(hasKey(m,n)==false){
     443      map* _cursor=m;
     444      if(_cursor!=NULL){
     445        addToMap(m,n,"");
     446      }else{
     447        m=createMap(n,"");
     448      }
     449    }
     450    map *tmp=getMap(m,n);
     451    if(tmp->value!=NULL)
     452      free(tmp->value);
     453    tmp->value=(char*)malloc((size+1)*sizeof(char));
     454    memmove(tmp->value,v,size*sizeof(char));
     455    tmp->value[size]=0;
     456    char sin[128];
     457    sprintf(sin,"%ld",size);
     458    addToMap(m,"size",sin);
    439459  }
    440460
  • trunk/zoo-project/zoo-kernel/service_internal_php.c

    r348 r508  
    5656
    5757  php_embed_init(0,NULL,&tsrm_ls);
    58 
    59   fprintf(stderr,"PHP EMBEDED\n");
    6058 
    6159  zend_try {
    62     fprintf(stderr,"PHP EMBEDED include script %s\n",tmp->value);
    6360    php_execute_script(&iscript TSRMLS_CC);
    64     fprintf(stderr,"PHP EMBEDED include script done\n");
    6561
    6662    zval *iargs[3];
     
    6864     
    6965    ZVAL_STRING(&ifunc, s->name, 0);
    70     fprintf(stderr,"PHP EMBEDED include script done\n");
    7166    iargs[0] = php_Array_from_maps(*main_conf);
    72     fprintf(stderr,"PHP EMBEDED include script done\n");
    7367    iargs[1] = php_Array_from_maps(*real_inputs);
    74     fprintf(stderr,"PHP EMBEDED include script done\n");
    7568    iargs[2] = php_Array_from_maps(*real_outputs);
    76     fprintf(stderr,"PHP EMBEDED include script done\n");
    7769   
    7870    call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC);
     
    8173    *real_outputs=php_maps_from_Array(t);
    8274   
    83     dumpMaps(*real_outputs);
    84 
    8575    char tmp1[1024];
    86 
    87     sprintf(tmp1,"PHP EMBEDED ran function successfully and return %d !?",Z_STRVAL(iret));
    8876
    8977    res=SERVICE_SUCCEEDED;
     
    10694  maps* tmp=t;
    10795  int tres=0;
    108   fprintf(stderr,"arra_init\n");
    10996  MAKE_STD_ZVAL(mapArray);
    11097  tres=array_init(mapArray);
    111   fprintf(stderr,"arra_init %d\n",tres);
    11298  while(tmp!=NULL){
    11399    add_assoc_zval(mapArray,tmp->name,php_Array_from_map(tmp->content));
     
    122108  map* tmp=t;
    123109  int tres=0;
    124   fprintf(stderr,"arra_init\n");
    125110  MAKE_STD_ZVAL(mapArray);
    126111  tres=array_init(mapArray);
    127   fprintf(stderr,"arra_init\n");
    128112  while(tmp!=NULL){
    129     fprintf(stderr,"=> %s %d %s %d \n",tmp->name,strlen(tmp->name),tmp->value,strlen(tmp->value));
    130     tres=add_assoc_string(mapArray,tmp->name,tmp->value,1);
     113    map* sMap=getMapArray(tmp,"size",i);
     114    if(strncmp(tmp->name,"value",5)==0 && sMap!=NULL){
     115      tres=add_assoc_stringl(mapArray,tmp->name,tmp->value,atoi(sMap->value),1);
     116    }else
     117      tres=add_assoc_string(mapArray,tmp->name,tmp->value,1);
    131118    tmp=tmp->next;
    132119  }
     
    135122
    136123maps* php_maps_from_Array(HashTable *t){
    137   //#ifdef DEBUG
    138   fprintf(stderr,"mapsFromPHPArray start\n");
    139   //#endif
    140124  maps* final_res=NULL;
    141125  maps* cursor=final_res;
     
    150134    zval **ppzval, tmpcopy;
    151135    type = zend_hash_get_current_key_ex(t, &key, &keylen, &idx, 0, NULL);
    152     fprintf(stderr,"key : %s\n",key);
    153136    if (zend_hash_get_current_data(t, (void**)&ppzval) == FAILURE) {
    154137      /**
     
    161144     */
    162145    tmpcopy = **ppzval;
    163     fprintf(stderr,"key : %s\n",key);
     146#ifdef DEBUG
     147    fprintf(stderr,"key : %s\n",key);
     148#endif
    164149    zval_copy_ctor(&tmpcopy);
    165     fprintf(stderr,"key : %s\n",key);
     150#ifdef DEBUG
     151    fprintf(stderr,"key : %s\n",key);
     152#endif
    166153    /**
    167154     * Reset refcount & Convert
     
    178165    fprintf(stderr,"key : %s\n",key);
    179166    HashTable* t=HASH_OF(*ppzval);
    180     fprintf(stderr,"key : %s\n",key);
     167#ifdef DEBUG
     168    fprintf(stderr,"key : %s\n",key);
     169#endif
    181170    cursor->content=php_map_from_HasTable(t);
    182171    cursor->next=NULL;
     
    185174    else
    186175      addMapsToMaps(&final_res,cursor);
    187     fprintf(stderr,"key : %s\n",key);
     176#ifdef DEBUG
     177    fprintf(stderr,"key : %s\n",key);
     178#endif
    188179    /**
    189180     * Toss out old copy
     
    201192  final_res=NULL;
    202193  char key[1024];
    203   for(zend_hash_internal_pointer_reset(t);
    204       zend_hash_has_more_elements(t) == SUCCESS;
    205       zend_hash_move_forward(t)) {
    206     char *key;
    207     uint keylen;
    208     ulong idx;
    209     int type;
    210     zval **ppzval, tmpcopy;
     194  for(zend_hash_internal_pointer_reset(t);
     195      zend_hash_has_more_elements(t) == SUCCESS;
     196      zend_hash_move_forward(t)) {
     197    char *key;
     198    uint keylen;
     199    ulong idx;
     200    int type;
     201    int len;
     202    zval **ppzval, tmpcopy;
    211203    type = zend_hash_get_current_key_ex(t, &key, &keylen, &idx, 0, NULL);
    212204    if (zend_hash_get_current_data(t, (void**)&ppzval) == FAILURE) {
     
    223215     */
    224216    INIT_PZVAL(&tmpcopy);
    225     convert_to_string(&tmpcopy); 
    226     if(final_res==NULL){
    227       fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
    228       final_res=createMap(key,Z_STRVAL(tmpcopy));
     217    convert_to_string(&tmpcopy);
     218    if(strncmp(key,"value")==0){
     219      len=Z_STRLEN_P(varcopy);
     220      addToMapWithSize(final_res,key,Z_STRVAL_P(tmpcopy),len);
    229221    }
    230222    else{
    231       fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
    232       addMapToMap(&final_res,createMap(key,Z_STRVAL(tmpcopy)));
     223      if(final_res==NULL){
     224#ifdef DEBUG
     225        fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
     226#endif
     227        final_res=createMap(key,Z_STRVAL(tmpcopy));
     228      }
     229      else{
     230#ifdef DEBUG
     231        fprintf(stderr,"%s => %s\n",key,Z_STRVAL(tmpcopy));
     232#endif
     233        addToMap(&final_res,key,Z_STRVAL(tmpcopy));
     234      }
    233235    }
    234236    /* Toss out old copy */
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r505 r508  
    502502      PyString_AsStringAndSize(value,&buffer,&size);
    503503#endif
    504       if(res!=NULL){
    505         addToMap(res,PyString_AsString(key),"");
    506       }else{
    507         res=createMap(PyString_AsString(key),"");
    508       }
    509       map* tmpR=getMap(res,"value");
    510       free(tmpR->value);
    511       tmpR->value=(char*)malloc((size+1)*sizeof(char));
    512       memmove(tmpR->value,buffer,size*sizeof(char));
    513       tmpR->value[size]=0;
    514       char sin[1024];
    515       sprintf(sin,"%ld",size);
    516       addToMap(res,"size",sin);
     504      addToMapWithSize(res,"value",buffer,size);
    517505    }else{
    518506      char* lkey=PyString_AsString(key);
  • trunk/zoo-project/zoo-kernel/ulinet.c

    r492 r508  
    6161  if(strncmp("Set-Cookie: ",buffer,12)==0){
    6262    int i;
    63     char env[1024];
    64     char path[1024];
    65     char domain[1024];
     63    char env[256];
     64    char path[256];
     65    char domain[256];
    6666    char* tmp;
    6767    for(i=0;i<12;i++)
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png