Changeset 890
- Timestamp:
- Jan 9, 2019, 4:11:59 PM (6 years ago)
- Location:
- branches/prototype-v0/zoo-project/zoo-kernel
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/caching.c
r888 r890 49 49 for(i = 0; i < len; i++){ 50 50 if(i>0){ 51 char *tmp= strdup(fresult);51 char *tmp=zStrdup(fresult); 52 52 sprintf(fresult,"%s%02x", tmp,result[i]); 53 53 free(tmp); … … 73 73 int bytes; 74 74 int dlen=65536; 75 unsigned char data[ dlen+1];75 unsigned char data[65537]; 76 76 FILE *inFile = fopen (file, "rb"); 77 77 EVP_DigestInit(md5ctx, EVP_md5()); … … 356 356 */ 357 357 char* isInCache(maps* conf,char* request){ 358 map* tmpUrl=getMapFromMaps(conf,"main","tmpUrl"); 358 359 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 359 if(tmpM!=NULL){ 360 if(strncasecmp(request,"file://",7)==0){ 361 char* tmpStr=zStrdup(request+7); 362 fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr); 363 return tmpStr; 364 } 365 else{ 366 char* myRequest=getFilenameForRequest(conf,request); 367 char* md5str=getMd5(myRequest); 368 free(myRequest); 369 #ifdef DEBUG 370 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 371 #endif 372 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6)); 373 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 374 struct stat f_status; 375 int s=stat(fname, &f_status); 376 if(s==0 && f_status.st_size>0){ 377 free(md5str); 378 return fname; 379 } 360 if(tmpM==NULL) 361 tmpM=getMapFromMaps(conf,"main","tmpPath"); 362 if(strstr(request,tmpUrl->value)!=NULL){ 363 map* tmpPath=getMapFromMaps(conf,"main","tmpPath"); 364 char* tmpStr=strstr(request,tmpUrl->value); 365 char* tmpStr1=zStrdup(tmpStr+strlen(tmpUrl->value)); 366 char* res=(char*) malloc((strlen(tmpPath->value)+strlen(tmpStr1)+2)*sizeof(char)); 367 sprintf(res,"%s/%s",tmpPath->value,tmpStr1); 368 free(tmpStr1); 369 return res; 370 } 371 #ifdef MS_FORCE_LOCAL_FILE_USE 372 map* msUrl=getMapFromMaps(conf,"main","mapserverAddress"); 373 if(msUrl!=NULL && strstr(request,msUrl->value)!=NULL){ 374 char *tmpStr=strstr(request,"?"); 375 char *cursor=zStrdup(tmpStr+1); 376 char *token, *saveptr; 377 token = strtok_r (cursor, "&", &saveptr); 378 while(token!=NULL){ 379 char *token1, *saveptr1; 380 token1 = strtok_r (token, "=", &saveptr1); 381 char *name=NULL; 382 while(token1!=NULL){ 383 if(name==NULL) 384 name=zStrdup(token1); 385 else 386 if(strcasecmp(name,"map")==0){ 387 mapObj *myMap=msLoadMap(token1,NULL); 388 char * res=zStrdup(myMap->layers[0]->data); 389 free(name); 390 free(cursor); 391 msFreeMap(myMap); 392 return res; 393 } 394 token1 = strtok_r (NULL, "=", &saveptr1); 395 } 396 token = strtok_r (NULL, "&", &saveptr); 397 } 398 free(cursor); 399 } 400 #endif 401 if(strncasecmp(request,"file://",7)==0){ 402 char* tmpStr=zStrdup(request+7); 403 fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr); 404 return tmpStr; 405 } 406 else{ 407 char* myRequest=getFilenameForRequest(conf,request); 408 char* md5str=getMd5(myRequest); 409 free(myRequest); 410 #ifdef DEBUG 411 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 412 #endif 413 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6)); 414 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 415 zStatStruct f_status; 416 int s=zStat(fname, &f_status); 417 if(s==0 && f_status.st_size>0){ 380 418 free(md5str); 381 free(fname); 382 } 419 return fname; 420 } 421 free(md5str); 422 free(fname); 383 423 } 384 424 return NULL; … … 609 649 */ 610 650 void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){ 611 hInternet->waitingRequests[hInternet->nb]= strdup(url);651 hInternet->waitingRequests[hInternet->nb]=zStrdup(url); 612 652 if(req) 613 653 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0,*m); … … 648 688 649 689 if(cached!=NULL){ 650 struct stat f_status;651 int s= stat(cached, &f_status);690 zStatStruct f_status; 691 int s=zStat(cached, &f_status); 652 692 if(s==0){ 653 693 zooLock* lck=lockFile(*m,cached,'r'); … … 668 708 } 669 709 cached[strlen(cached)-1]='m'; 670 s= stat(cached, &f_status);710 s=zStat(cached, &f_status); 671 711 if(s==0){ 672 712 zooLock* lck=lockFile(*m,cached,'r'); … … 681 721 } 682 722 cached[strlen(cached)-1]='p'; 683 s= stat(cached, &f_status);723 s=zStat(cached, &f_status); 684 724 if(s==0){ 685 725 zooLock* lck=lockFile(*m,cached,'r'); … … 728 768 addToMap(*content,"isCached","true"); 729 769 map* tmp=getMapFromMaps(*m,"main","cacheDir"); 730 if(tmp!=NULL){ 770 map* tmp1=getMap((*content),"cache_file"); 771 if(tmp!=NULL && tmp1==NULL){ 731 772 map *c=getMap((*content),"xlink:href"); 732 773 if(strncasecmp(c->value,"file://",7)!=0){ -
branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c
r880 r890 154 154 addToMap(cursor->content,"base64_value",tmp->value); 155 155 int size=0; 156 char *s= strdup(tmp->value);156 char *s=zStrdup(tmp->value); 157 157 free(tmp->value); 158 158 tmp->value=base64d(s,strlen(s),&size); … … 174 174 addToMap(cursor->content,key,tmp->value); 175 175 int size=0; 176 char *s= strdup(tmp->value);176 char *s=zStrdup(tmp->value); 177 177 free(tmp->value); 178 178 tmp->value=base64d(s,strlen(s),&size); … … 795 795 #endif 796 796 bInternet.waitingRequests[0] = 797 strdup ((char *) val);797 zStrdup ((char *) val); 798 798 res1 = 799 799 InternetOpenUrl (&bInternet, … … 1806 1806 #endif 1807 1807 targetFile = 1808 open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,1808 zOpen (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, 1809 1809 S_IRWXU | S_IRGRP | S_IROTH); 1810 1810 if (targetFile < 0) … … 1826 1826 addToMap (tmpReqI->content, "lref", storageNameOnServer); 1827 1827 cgiFormFileClose (file); 1828 close (targetFile);1828 zClose (targetFile); 1829 1829 free(fileNameOnServer); 1830 1830 free(storageNameOnServer); -
branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
r888 r890 79 79 } 80 80 if(prefix!=NULL){ 81 char* tmp0= strdup(serv->name);81 char* tmp0=zStrdup(serv->name); 82 82 free(serv->name); 83 83 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); … … 183 183 nbNs++; 184 184 currId=0; 185 nsName[currId]= strdup(name);185 nsName[currId]=zStrdup(name); 186 186 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 187 187 }else{ … … 190 190 nbNs++; 191 191 currId=nbNs-1; 192 nsName[currId]= strdup(name);192 nsName[currId]=zStrdup(name); 193 193 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 194 194 } … … 255 255 if(soap!=NULL && strcasecmp(soap->value,"true")==0){ 256 256 int lNbNs=nbNs; 257 nsName[lNbNs]= strdup("soap");257 nsName[lNbNs]=zStrdup("soap"); 258 258 usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 259 259 nbNs++; 260 260 xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); 261 nsName[nbNs]= strdup("soap");261 nsName[nbNs]=zStrdup("soap"); 262 262 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 263 263 nbNs++; 264 nsName[nbNs]= strdup("xsi");264 nsName[nbNs]=zStrdup("xsi"); 265 265 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 266 266 nbNs++; … … 594 594 map* tmp=getMap(toto1->content,"serverAddress"); 595 595 if(tmp!=NULL){ 596 SERVICE_URL = strdup(tmp->value);596 SERVICE_URL = zStrdup(tmp->value); 597 597 } 598 598 else 599 SERVICE_URL = strdup("not_defined");599 SERVICE_URL = zStrdup("not_defined"); 600 600 } 601 601 else 602 SERVICE_URL = strdup("not_defined");602 SERVICE_URL = zStrdup("not_defined"); 603 603 604 604 for(j=0;j<nbSupportedRequests;j++){ … … 1269 1269 while(token!=NULL){ 1270 1270 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1271 char *tmps= strdup(token);1271 char *tmps=zStrdup(token); 1272 1272 tmps[strlen(tmps)]=0; 1273 1273 nc8 = xmlNewText(BAD_CAST tmps); … … 1746 1746 while(cursor!=NULL){ 1747 1747 elements* ccursor=cursor; 1748 char* tmp= strdup(ccursor->name);1748 char* tmp=zStrdup(ccursor->name); 1749 1749 free(ccursor->name); 1750 1750 ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char)); … … 2671 2671 else 2672 2672 sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1); 2673 sessId= strdup(session_file_path);2673 sessId=zStrdup(session_file_path); 2674 2674 }else{ 2675 2675 maps* t=getMaps(m,"senv"); … … 2677 2677 while(p!=NULL){ 2678 2678 if(strstr(p->name,"ID")!=NULL){ 2679 sessId= strdup(p->value);2679 sessId=zStrdup(p->value); 2680 2680 break; 2681 2681 } -
branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c
r862 r890 367 367 */ 368 368 void readGeneratedFile(maps* m,map* content,char* filename){ 369 char rsize[1024]; 369 370 FILE * file=fopen(filename,"rb"); 370 371 if(file==NULL){ … … 374 375 fseek(file, 0, SEEK_END); 375 376 long count = ftell(file); 377 sprintf(rsize,"%lld",ftell(file)); 376 378 rewind(file); 377 struct stat file_status;378 stat(filename, &file_status);379 379 if(getMap(content,"storage")==NULL){ 380 380 map* tmpMap1=getMap(content,"value"); … … 391 391 tmpMap1->value[count]=0; 392 392 } 393 fclose(file); 394 char rsize[1000]; 395 sprintf(rsize,"%ld",count); 393 fclose(file); 396 394 addToMap(content,"size",rsize); 397 395 } … … 760 758 map* tmpV=getMap(tmpI->content,"value"); 761 759 if(tmpV!=NULL){ 762 char *tmpVS= strdup(tmpV->value);760 char *tmpVS=zStrdup(tmpV->value); 763 761 map* tmp=parseBoundingBox(tmpVS); 764 762 free(tmpVS); … … 797 795 map* length=getMap(tmpMaps->content,"length"); 798 796 int i; 799 char *tcn= strdup(tmpContent->name);797 char *tcn=zStrdup(tmpContent->name); 800 798 for(i=1;i<atoi(length->value);i++){ 801 799 #ifdef DEBUG … … 1007 1005 char* tmpStr=_getStatus(conf,pid); 1008 1006 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1009 char *tmpStr1= strdup(tmpStr);1010 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1007 char *tmpStr1=zStrdup(tmpStr); 1008 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1011 1009 free(tmpStr); 1012 1010 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; … … 1043 1041 char* tmpStr=_getStatus(conf,pid); 1044 1042 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 1045 char *tmpStr1= strdup(tmpStr);1046 char *tmpStr0= strdup(strstr(tmpStr,"|")+1);1043 char *tmpStr1=zStrdup(tmpStr); 1044 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 1047 1045 free(tmpStr); 1048 1046 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; -
branches/prototype-v0/zoo-project/zoo-kernel/service.c
r881 r890 759 759 map* toload=getMap(in,"to_load"); 760 760 if(toload!=NULL && strcasecmp(toload->value,"false")==0){ 761 #ifdef DEBUG 761 762 fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__); 763 #endif 762 764 return ; 763 765 } -
branches/prototype-v0/zoo-project/zoo-kernel/service.h
r881 r890 43 43 #define zStrdup _strdup 44 44 #define zMkdir _mkdir 45 #define zGetpid _getpid 45 46 #define zOpen _open 47 #define zClose _close 48 #define zUnlink _unlink 49 #define zDup _dup 50 #define zDup2 _dup2 46 51 #define zWrite _write 47 52 #define zSleep Sleep … … 65 70 } 66 71 72 #define zStatStruct struct _stati64 73 #define zStat _stati64 74 67 75 #else 68 76 /** … … 78 86 */ 79 87 #define zOpen open 88 /** 89 * The crossplatform close alias 90 */ 91 #define zClose close 92 /** 93 * The crossplatform unlink alias 94 */ 95 #define zUnlink unlink 96 /** 97 * The crossplatform dup alias 98 */ 99 #define zDup dup 100 /** 101 * The crossplatform dup2 alias 102 */ 103 #define zDup2 dup2 80 104 /** 81 105 * The crossplatform write alias … … 97 121 */ 98 122 #define ztimeval timeval 123 /** 124 * The crossplatform getpid alias 125 */ 126 #define zGetpid getpid 127 128 #define zStatStruct struct stat64 129 #define zStat stat64 130 99 131 #endif 100 132 -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
r877 r890 31 31 #include "service_internal.h" 32 32 33 #ifndef TRUE34 #define TRUE 135 #endif36 #ifndef FALSE37 #define FALSE -138 #endif39 40 33 #ifdef WIN32 41 // cf. https://stackoverflow.com/questions/3168504/lockfileex-read-write-upgrade-downgrade 42 // only works for (SEEK_SET, start=0, len=0) file locking. 34 // ref. https://docs.microsoft.com/en-us/windows/desktop/fileio/locking-and-unlocking-byte-ranges-in-files 43 35 __inline int fcntl(int fd, int cmd, ...) 44 36 { 45 46 47 37 va_list a; 38 va_start(a, cmd); 39 switch(cmd) 48 40 { 49 41 case F_SETLK: 50 { 51 struct flock *l = va_arg(a, struct flock*); 52 switch(l->l_type) 53 { 54 case F_RDLCK: 55 { 56 LPOVERLAPPED o = { 0 }; 57 HANDLE h = (HANDLE)_get_osfhandle(fd); 58 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 59 { 60 _set_errno(ENOTSUP); 61 return -1; 62 } 63 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 1, o)) // read lock 64 { 65 unsigned long x = GetLastError(); 66 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 67 return -1; 68 } 69 UnlockFile(h, 0, 0, 1, 1); // write lock 70 } 71 break; 72 case F_WRLCK: 73 { 74 LPOVERLAPPED o = { 0 }; 75 HANDLE h = (HANDLE)_get_osfhandle(fd); 76 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 77 { 78 _set_errno(ENOTSUP); 79 return -1; 80 } 81 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock 82 { 83 unsigned long x = GetLastError(); 84 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 85 return -1; 86 } 87 UnlockFile(h, 0, 0, 0, 1); // read lock 88 } 89 break; 90 case F_UNLCK: 91 { 92 HANDLE h = (HANDLE)_get_osfhandle(fd); 93 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 94 { 95 _set_errno(ENOTSUP); 96 return -1; 97 } 98 UnlockFile(h, 0, 0, 0, 1); // read lock 99 UnlockFile(h, 0, 0, 1, 1); // write lock 100 } 101 break; 102 default: 103 _set_errno(ENOTSUP); 104 return -1; 105 } 106 } 107 break; 108 case F_SETLKW: 109 { 110 struct flock *l = va_arg(a, struct flock*); 111 switch(l->l_type) 112 { 113 case F_RDLCK: 114 { 115 LPOVERLAPPED o = { 0 }; 116 HANDLE h = (HANDLE)_get_osfhandle(fd); 117 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 118 { 119 _set_errno(ENOTSUP); 120 return -1; 121 } 122 if(!LockFileEx(h, 0, 0, 0, 1, o)) // read lock 123 { 124 unsigned long x = GetLastError(); 125 return -1; 126 } 127 UnlockFile(h, 0, 0, 1, 1); // write lock 128 } 129 break; 130 case F_WRLCK: 131 { 132 LPOVERLAPPED o = { 0 }; 133 HANDLE h = (HANDLE)_get_osfhandle(fd); 134 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 135 { 136 _set_errno(ENOTSUP); 137 return -1; 138 } 139 if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock 140 { 141 unsigned long x = GetLastError(); 142 return -1; 143 } 144 UnlockFile(h, 0, 0, 0, 1); // read lock 145 } 146 break; 147 case F_UNLCK: 148 { 149 flock *l = va_arg(a, flock*); 150 HANDLE h = (HANDLE)_get_osfhandle(fd); 151 if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0) 152 { 153 _set_errno(ENOTSUP); 154 return -1; 155 } 156 UnlockFile(h, 0, 0, 0, 1); // read lock 157 UnlockFile(h, 0, 0, 1, 1); // write lock 158 } 159 break; 160 default: 161 _set_errno(ENOTSUP); 162 return -1; 163 } 164 } 165 break; 42 { 43 HANDLE h = (HANDLE)_get_osfhandle(fd); 44 struct flock* l= va_arg(a, struct flock*); 45 OVERLAPPED sOverlapped; 46 sOverlapped.Offset = 0; 47 sOverlapped.OffsetHigh = 0; 48 switch(l->l_type) 49 { 50 case F_RDLCK: 51 { 52 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, l->l_len, 0, &sOverlapped)) 53 { 54 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 55 return -1; 56 } 57 } 58 break; 59 case F_WRLCK: 60 { 61 if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, l->l_len, 0, &sOverlapped)) 62 { 63 _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF); 64 return -1; 65 } 66 } 67 break; 68 case F_UNLCK: 69 { 70 UnlockFileEx(h, 0, l->l_len, 0, &sOverlapped); 71 } 72 break; 73 default: 74 _set_errno(ENOTSUP); 75 return -1; 76 } 77 } 78 break; 166 79 default: 167 _set_errno(ENOTSUP); 168 return -1; 169 } 170 171 return 0; 172 } 173 #endif 174 80 _set_errno(ENOTSUP); 81 return -1; 82 } 83 return 0; 84 } 85 #endif 175 86 #define ERROR_MSG_MAX_LENGTH 1024 176 87 … … 197 108 if(itn<ZOO_LOCK_MAX_RETRY){ 198 109 itn++; 199 fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",getpid(),myLock->filename,itn); 110 #ifdef DEBUG 111 fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",zGetpid(),myLock->filename,itn); 200 112 fflush(stderr); 113 #endif 201 114 zSleep(5); 202 115 free(myLock->filename); … … 216 129 myLock->lockfile=fopen(myLock->filename,local_mode); 217 130 char tmp[512]; 218 sprintf(tmp,"%d", getpid());131 sprintf(tmp,"%d",zGetpid()); 219 132 if(myLock->lockfile==NULL){ 220 133 myLock->lockfile=fopen(myLock->filename,"w+"); … … 249 162 return NULL; 250 163 } 251 fprintf(stderr,"(%d) Wait for lock on %s, tried %d times ... \n",getpid(),myLock->filename,cnt); 164 #ifdef DEBUG 165 fprintf(stderr,"(%d) Wait for lock on %s, tried %d times ... \n",zGetpid(),myLock->filename,cnt); 252 166 fflush(stderr); 167 #endif 253 168 zSleep(1); 254 169 cnt++; … … 265 180 else 266 181 tmp="The system has run out of file lock resources; there are already too many file locks in place."; 182 #ifdef DEBUG 267 183 fprintf(stderr,"Unable to get the lock on %s due to the following error: %s\n",myLock->filename,tmp); 184 #endif 268 185 return NULL; 269 186 } … … 285 202 if(res==-1) 286 203 return res; 204 fclose(s->lockfile); 205 #ifndef WIN32 287 206 // Check if there is any process locking a file and delete the lock if not. 288 207 s->lock.l_type = F_WRLCK; 289 208 if(fcntl(fileno(s->lockfile), F_GETLK, &s->lock)!=-1 && s->lock.l_type == F_UNLCK){ 290 unlink(s->filename); 291 } 292 fclose(s->lockfile); 209 #endif 210 zUnlink(s->filename); 211 #ifndef WIN32 212 } 213 #endif 293 214 free(s->filename); 294 215 free(s); … … 507 428 * sizeof (char)); 508 429 sprintf (fbkpid, "%s/%s.status", r_inputs->value, usid->value); 509 unlink(fbkpid);430 zUnlink(fbkpid); 510 431 free(fbkpid); 511 432 } -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
r888 r890 1162 1162 char tmpMm[100],tmpMp[100]; 1163 1163 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1164 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 1164 if(pdfMin!=pdfMax) 1165 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 1166 /*else 1167 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMin,pdfMax);*/ 1165 1168 char tmpI[31]; 1166 1169 sprintf(tmpI,"%s_interval",tmpN); -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c
r863 r890 201 201 char* toto=(char*)malloc((strlen(pythonpath)+12)*sizeof(char)); 202 202 sprintf(toto,"PYTHONPATH=%s",pythonpath); 203 putenv(toto);203 _putenv(toto); 204 204 free(toto); 205 205 #endif -
branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
r865 r890 419 419 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 420 420 if( poFeature->IsFieldSet( iField ) ){ 421 tmp1= strdup(poFeature->GetFieldAsString( iField ));421 tmp1=zStrdup(poFeature->GetFieldAsString( iField )); 422 422 } 423 423 else … … 463 463 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 464 464 if( poFeature->IsFieldSet( iField ) ){ 465 tmp1= strdup(poFeature->GetFieldAsString( iField ));465 tmp1=zStrdup(poFeature->GetFieldAsString( iField )); 466 466 hasRes=1; 467 467 } -
branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
r888 r890 161 161 if (hpc_public_key != NULL) { 162 162 public_key = hpc_public_key->value; 163 private_key = strdup(hpc_public_key->value);163 private_key = zStrdup(hpc_public_key->value); 164 164 private_key[strlen(public_key)-4]=0; 165 165 }else{ -
branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
r871 r890 238 238 HINTERNET ret; 239 239 ret.handle=curl_multi_init(); 240 ret.agent= strdup(lpszAgent);240 ret.agent=zStrdup(lpszAgent); 241 241 ret.nb=0; 242 242 ret.waitingRequests[ret.nb] = NULL; … … 269 269 char* getProvenance(maps* conf,const char* url){ 270 270 map* sharedCache=getMapFromMaps(conf,"security","shared"); 271 char *res="OTHER"; 272 char *paths[2]={ 273 "mapserverAddress", 274 "tmpUrl" 275 }; 271 276 if(sharedCache!=NULL){ 272 char *res=NULL;273 277 char *hosts=sharedCache->value; 274 278 char *curs=strtok(hosts,","); 275 279 while(curs!=NULL){ 276 if(strstr(url,curs)==NULL) 277 res="OTHER"; 278 else{ 279 res="SHARED"; 280 return res; 280 if(strstr(url,curs)==NULL){ 281 return "SHARED"; 281 282 } 282 283 curs=strtok(NULL,","); 283 284 } 284 return res; 285 } 286 return "OTHER"; 285 } 286 for(int i=0;i<2;i++){ 287 sharedCache=getMapFromMaps(conf,"main",paths[i]); 288 if(sharedCache!=NULL){ 289 if(strstr(url,sharedCache->value)!=NULL){ 290 return "LOCAL"; 291 } 292 } 293 } 294 return res; 287 295 } 288 296 … … 482 490 #endif 483 491 484 if(memUse !=NULL && strcasecmp(memUse->value,"load")==0)492 if(memUse==NULL || strcasecmp(memuse->value,"load")==0) 485 493 ldwFlags=INTERNET_FLAG_NO_CACHE_WRITE; 486 494 … … 502 510 sprintf(filename,"/tmp/ZOO_Cache%s", tmpUuid); 503 511 else 504 sprintf(filename," /%s/ZOO_Cache%s", tmpPath->value,tmpUuid);512 sprintf(filename,"%s/ZOO_Cache%s", tmpPath->value,tmpUuid); 505 513 free(tmpUuid); 506 hInternet->ihandle[hInternet->nb].filename= strdup(filename);514 hInternet->ihandle[hInternet->nb].filename=zStrdup(filename); 507 515 hInternet->ihandle[hInternet->nb].file=fopen(hInternet->ihandle[hInternet->nb].filename,"w+"); 508 516 hInternet->ihandle[hInternet->nb].hasCacheFile=1; … … 524 532 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_VERBOSE,1); 525 533 #endif 526 hInternet->ihandle[hInternet->nb].post= strdup(lpszHeaders);534 hInternet->ihandle[hInternet->nb].post=zStrdup(lpszHeaders); 527 535 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDS,hInternet->ihandle[hInternet->nb].post); 528 536 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength); … … 602 610 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp); 603 611 if(tmp!=NULL) 604 hInternet->ihandle[i].mimeType= strdup(tmp);612 hInternet->ihandle[i].mimeType=zStrdup(tmp); 605 613 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code); 606 614 curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle); … … 618 626 */ 619 627 int freeCookieList(HINTERNET hInternet){ 620 hInternet.ihandle[hInternet.nb].cookie= strdup("");628 hInternet.ihandle[hInternet.nb].cookie=zStrdup(""); 621 629 #ifndef TIGER 622 630 curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL"); -
branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
r882 r890 340 340 if (s1 == NULL) 341 341 { 342 dup2 (saved_stdout, fileno (stdout));342 zDup2 (saved_stdout, fileno (stdout)); 343 343 errorException (m, _("Unable to allocate memory"), 344 344 "InternalError", NULL); … … 361 361 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 362 362 dp->d_name); 363 dup2 (saved_stdout, fileno (stdout));363 zDup2 (saved_stdout, fileno (stdout)); 364 364 errorException (m, tmp01, "InternalError", NULL); 365 365 return -1; … … 1101 1101 char tmp1[13]; 1102 1102 sprintf (tmp1, "LC_ALL=%s", tmp); 1103 putenv (tmp1);1103 _putenv (tmp1); 1104 1104 #endif 1105 1105 free (tmp); … … 1113 1113 char tmp1[13]; 1114 1114 sprintf (tmp1, "LC_ALL=en_US"); 1115 putenv (tmp1);1115 _putenv (tmp1); 1116 1116 #endif 1117 1117 setMapInMaps (m, "main", "language", "en-US"); … … 1123 1123 char tmp1[17]; 1124 1124 sprintf (tmp1, "LC_NUMERIC=C"); 1125 putenv (tmp1);1125 _putenv (tmp1); 1126 1126 #endif 1127 1127 bind_textdomain_codeset ("zoo-kernel", "UTF-8"); … … 1306 1306 registry* zooRegistry=NULL; 1307 1307 if(reg!=NULL){ 1308 int saved_stdout = dup (fileno (stdout));1309 dup2 (fileno (stderr), fileno (stdout));1308 int saved_stdout = zDup (fileno (stdout)); 1309 zDup2 (fileno (stderr), fileno (stdout)); 1310 1310 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1311 1311 map *message=getMapFromMaps(m,"lenv","message"); 1312 1312 map *type=getMapFromMaps(m,"lenv","type"); 1313 dup2 (saved_stdout, fileno (stdout));1313 zDup2 (saved_stdout, fileno (stdout)); 1314 1314 errorException (m, message->value, 1315 1315 type->value, NULL); 1316 1316 return 0; 1317 1317 } 1318 dup2 (saved_stdout, fileno (stdout));1319 close(saved_stdout);1318 zDup2 (saved_stdout, fileno (stdout)); 1319 zClose(saved_stdout); 1320 1320 } 1321 1321 … … 1331 1331 * has been found in the zcfg and then printed on stdout 1332 1332 */ 1333 int saved_stdout = dup (fileno (stdout));1334 dup2 (fileno (stderr), fileno (stdout));1333 int saved_stdout = zDup (fileno (stdout)); 1334 zDup2 (fileno (stderr), fileno (stdout)); 1335 1335 1336 1336 maps* imports = getMaps(m, IMPORTSERVICE); … … 1371 1371 } 1372 1372 fflush (stdout); 1373 dup2 (saved_stdout, fileno (stdout));1373 zDup2 (saved_stdout, fileno (stdout)); 1374 1374 #ifdef META_DB 1375 1375 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1376 1376 close_sql(m,0); 1377 1377 #endif 1378 printDocument (m, doc, getpid ());1378 printDocument (m, doc, zGetpid ()); 1379 1379 freeMaps (&m); 1380 1380 free (m); … … 1466 1466 char *orig = zStrdup (r_inputs->value); 1467 1467 1468 int saved_stdout = dup (fileno (stdout));1469 dup2 (fileno (stderr), fileno (stdout));1468 int saved_stdout = zDup (fileno (stdout)); 1469 zDup2 (fileno (stderr), fileno (stdout)); 1470 1470 if (strcasecmp ("all", orig) == 0) 1471 1471 { … … 1535 1535 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value); 1536 1536 1537 dup2 (saved_stdout, fileno (stdout));1537 zDup2 (saved_stdout, fileno (stdout)); 1538 1538 errorException (m, tmp01, "InternalError", NULL); 1539 1539 … … 1602 1602 ("Unable to parse the ZCFG file for the following ZOO-Service: %s."), 1603 1603 tmps); 1604 dup2 (saved_stdout, fileno (stdout));1604 zDup2 (saved_stdout, fileno (stdout)); 1605 1605 errorException (m, tmp01, "InvalidParameterValue", 1606 1606 "identifier"); … … 1674 1674 if (s1 == NULL) 1675 1675 { 1676 dup2 (saved_stdout, fileno (stdout));1676 zDup2 (saved_stdout, fileno (stdout)); 1677 1677 return errorException (m, 1678 1678 _ … … 1705 1705 ("Unable to parse the ZCFG file: %s."), 1706 1706 dp->d_name); 1707 dup2 (saved_stdout, fileno (stdout));1707 zDup2 (saved_stdout, fileno (stdout)); 1708 1708 errorException (m, tmp01, "InternalError", 1709 1709 NULL); … … 1757 1757 _("Unable to parse the ZCFG file: %s."), 1758 1758 buff); 1759 dup2 (saved_stdout, fileno (stdout));1759 zDup2 (saved_stdout, fileno (stdout)); 1760 1760 errorException (m, tmp01, "InvalidParameterValue", 1761 1761 "Identifier"); … … 1782 1782 closedir (dirp); 1783 1783 fflush (stdout); 1784 dup2 (saved_stdout, fileno (stdout));1784 zDup2 (saved_stdout, fileno (stdout)); 1785 1785 free (orig); 1786 printDocument (m, doc, getpid ());1786 printDocument (m, doc, zGetpid ()); 1787 1787 freeMaps (&m); 1788 1788 free (m); … … 1942 1942 } 1943 1943 1944 int saved_stdout = dup (fileno (stdout));1945 dup2 (fileno (stderr), fileno (stdout));1944 int saved_stdout = zDup (fileno (stdout)); 1945 zDup2 (fileno (stderr), fileno (stdout)); 1946 1946 t = readServiceFile (m, tmps1, &s1, r_inputs->value); 1947 1947 fprintf(stderr,"%d %s %d",t,__FILE__,__LINE__); … … 1958 1958 } 1959 1959 fflush (stdout); 1960 dup2 (saved_stdout, fileno (stdout));1960 zDup2 (saved_stdout, fileno (stdout)); 1961 1961 if (t < 0) 1962 1962 { … … 1975 1975 return 0; 1976 1976 } 1977 close (saved_stdout);1977 zClose (saved_stdout); 1978 1978 #ifdef META_DB 1979 1979 } … … 2058 2058 2) * sizeof (char)); 2059 2059 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 2060 putenv (toto);2060 _putenv (toto); 2061 2061 #ifdef DEBUG 2062 2062 fflush (stderr); … … 2155 2155 2156 2156 int eres = SERVICE_STARTED; 2157 int cpid = getpid ();2157 int cpid = zGetpid (); 2158 2158 2159 2159 // Create a map containing a copy of the request map … … 2241 2241 if (istat == 0 && file_status.st_size > 0) 2242 2242 { 2243 int saved_stdout = dup (fileno (stdout));2244 dup2 (fileno (stderr), fileno (stdout));2243 int saved_stdout = zDup (fileno (stdout)); 2244 zDup2 (fileno (stderr), fileno (stdout)); 2245 2245 conf_read (session_file_path, tmpSess); 2246 2246 addMapsToMaps (&m, tmpSess); 2247 2247 freeMaps (&tmpSess); 2248 2248 fflush(stdout); 2249 dup2 (saved_stdout, fileno (stdout));2250 close(saved_stdout);2249 zDup2 (saved_stdout, fileno (stdout)); 2250 zClose(saved_stdout); 2251 2251 } 2252 2252 free (tmpSess); … … 2271 2271 2272 2272 _tmpMaps = createMaps("renv"); 2273 for (; s; ei++) { 2273 if(orig!=NULL) 2274 for (; 2275 #ifdef WIN32 2276 *s; 2277 s++ 2278 #else 2279 s; 2280 ei++ 2281 #endif 2282 ) { 2274 2283 if(strstr(s,"=")!=NULL && strlen(strstr(s,"="))>1){ 2275 2284 int len=strlen(s); … … 2285 2294 free(tmpName); 2286 2295 } 2287 #ifdef WIN32 2288 s++; 2289 #else 2296 #ifndef WIN32 2290 2297 s = *(orig+ei); 2291 2298 #endif … … 2297 2304 freeMaps (&_tmpMaps); 2298 2305 free (_tmpMaps); 2299 2306 #ifdef WIN32 2307 FreeEnvironmentStrings((LPCH)orig); 2308 #endif 2300 2309 if(postRequest!=NULL) 2301 2310 setMapInMaps (m, "renv", "xrequest", postRequest->value); … … 2389 2398 #ifdef DEBUG 2390 2399 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2391 getpid ());2400 zGetpid ()); 2392 2401 #endif 2393 2402 eres = SERVICE_ACCEPTED; … … 2417 2426 bmap->content=createMap("usid",usid->value); 2418 2427 addToMap(bmap->content,"sid",tmpm->value); 2419 addIntToMap(bmap->content,"pid", getpid());2428 addIntToMap(bmap->content,"pid",zGetpid()); 2420 2429 2421 2430 // Create PID file referencing the OS process identifier … … 2428 2437 2429 2438 f0 = freopen (fbkpid, "w+",stdout); 2430 printf("%d", getpid());2439 printf("%d",zGetpid()); 2431 2440 fflush(stdout); 2432 2441 … … 2460 2469 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 2461 2470 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 2462 getpid ());2471 zGetpid ()); 2463 2472 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 2464 2473 #endif … … 2539 2548 #endif 2540 2549 #endif 2541 unlink (fbkpid);2550 zUnlink (fbkpid); 2542 2551 unhandleStatus (m); 2543 2552 #ifdef RELY_ON_DB … … 2617 2626 #endif 2618 2627 2619 if (((int) getpid ()) != cpid || cgiSid != NULL)2628 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2620 2629 { 2621 2630 if (eres == SERVICE_SUCCEEDED) … … 2633 2642 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2634 2643 return -1; 2635 unlink (fbkpid);2644 zUnlink (fbkpid); 2636 2645 switch(eres){ 2637 2646 default: … … 2657 2666 freeMaps(&bmap); 2658 2667 free(bmap); 2659 unlink (fbkp1);2668 zUnlink (fbkp1); 2660 2669 unhandleStatus (m); 2661 2670 #ifdef RELY_ON_DB … … 2676 2685 fflush(stderr); 2677 2686 fclose (stderr); 2678 unlink (flog);2687 zUnlink (flog); 2679 2688 free (flog); 2680 2689 } … … 2705 2714 #endif 2706 2715 2707 if (((int) getpid ()) != cpid || cgiSid != NULL)2716 if (((int) zGetpid ()) != cpid || cgiSid != NULL) 2708 2717 { 2709 2718 exit (0);
Note: See TracChangeset
for help on using the changeset viewer.