Changeset 917 for trunk/zoo-project/zoo-kernel/service.c
- Timestamp:
- May 7, 2019, 2:17:08 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
False
/branches/prototype-v0 merged eligible
-
Property
svn:mergeinfo
set to
False
-
trunk/zoo-project/zoo-kernel/service.c
r889 r917 2 2 * Author : Gérald FENOY 3 3 * 4 * Copyright (c) 2015 GeoLabs SARL4 * Copyright (c) 2015-2019 GeoLabs SARL 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 28 28 #include <ctime> 29 29 #include <chrono> 30 #ifdef WIN32 30 31 #include <process.h> 32 #endif 31 33 32 34 #if defined(_MSC_VER) && _MSC_VER < 1800 … … 102 104 fprintf(stderr," * CONTENT [%s] \n",tmp->name); 103 105 dumpMap(tmp->content); 104 fprintf(stderr," * CHILD [%s] \n",tmp->name); 105 dumpMaps(tmp->child); 106 if(tmp->child!=NULL){ 107 fprintf(stderr," * CHILD [%s] \n",tmp->name); 108 dumpMaps(tmp->child); 109 fprintf(stderr," * /CHILD [%s] \n",tmp->name); 110 } 106 111 tmp=tmp->next; 107 112 } … … 125 130 fflush(file); 126 131 tmp=tmp->next; 127 cnt++;128 132 if(limit>=0 && cnt==limit) 129 133 tmp=NULL; 134 cnt++; 130 135 } 131 136 fflush(file); … … 144 149 fflush(file); 145 150 fclose(file); 151 } 152 153 /** 154 * Create a new iotype* 155 * 156 * @return a pointer to the allocated iotype 157 */ 158 iotype* createIoType(){ 159 iotype* io=(iotype*)malloc(IOTYPE_SIZE); 160 io->content=NULL; 161 io->next=NULL; 162 return io; 146 163 } 147 164 … … 179 196 * Count number of map in a map 180 197 * 181 * @param m the map sto count198 * @param m the map to count 182 199 * @return number of map in a map 183 200 */ 184 201 int count(map* m){ 185 202 map* tmp=m; 203 int c=0; 204 while(tmp!=NULL){ 205 c++; 206 tmp=tmp->next; 207 } 208 return c; 209 } 210 211 /** 212 * Count number of maps in a maps 213 * 214 * @param m the maps to count 215 * @return number of maps in a maps 216 */ 217 int maps_length(maps* m){ 218 maps* tmp=m; 186 219 int c=0; 187 220 while(tmp!=NULL){ … … 401 434 if(tmp->metadata!=NULL) 402 435 free(tmp->metadata); 436 freeMap(&tmp->additional_parameters); 437 if(tmp->additional_parameters!=NULL) 438 free(tmp->additional_parameters); 403 439 if(tmp->format!=NULL) 404 440 free(tmp->format); 441 freeElements(&tmp->child); 405 442 if(tmp->child!=NULL){ 406 freeElements(&tmp->child);407 443 free(tmp->child); 408 444 } 409 freeIOType(&tmp->defaults);410 if(tmp->defaults!=NULL)445 if(tmp->defaults!=NULL){ 446 freeIOType(&tmp->defaults); 411 447 free(tmp->defaults); 412 freeIOType(&tmp->supported);448 } 413 449 if(tmp->supported!=NULL){ 450 freeIOType(&tmp->supported); 414 451 free(tmp->supported); 415 452 } 416 freeElements(&tmp->next);417 if(tmp->next!=NULL)453 if(tmp->next!=NULL){ 454 freeElements(&tmp->next); 418 455 free(tmp->next); 419 } 456 } 457 } 458 } 459 460 461 /** 462 * Allocate memory for a service. 463 * Require to call free after calling this function. 464 * 465 * @return the service 466 */ 467 service* createService(){ 468 service *s1 = (service *) malloc (SERVICE_SIZE); 469 s1->name=NULL; 470 s1->content=NULL; 471 s1->metadata=NULL; 472 s1->additional_parameters=NULL; 473 s1->inputs=NULL; 474 s1->outputs=NULL; 475 return s1; 420 476 } 421 477 422 478 /** 423 479 * Free allocated memory of a service. 424 * Require to call free on e after calling this function.480 * Require to be invoked for every createService call. 425 481 * 426 482 * @param s the service to free … … 437 493 if(tmp->metadata!=NULL) 438 494 free(tmp->metadata); 495 freeMap(&tmp->additional_parameters); 496 if(tmp->additional_parameters!=NULL) 497 free(tmp->additional_parameters); 439 498 freeElements(&tmp->inputs); 440 499 if(tmp->inputs!=NULL) … … 454 513 */ 455 514 void addToMap(map* m,const char* n,const char* v){ 456 if (m != NULL) { // knut: add NULL-pointer check457 if(hasKey(m,n)==false){458 map* _cursor=m;459 while(_cursor->next!=NULL){460 _cursor=_cursor->next;461 }462 _cursor->next=createMap(n,v);463 }464 else{465 map *tmp=getMap(m,n);466 if(tmp->value!=NULL)467 free(tmp->value);468 tmp->value=zStrdup(v);469 }470 }515 if (m != NULL) { // knut: add NULL-pointer check 516 if (hasKey(m, n) == false) { 517 map* _cursor = m; 518 while (_cursor->next != NULL) { 519 _cursor = _cursor->next; 520 } 521 _cursor->next = createMap(n, v); 522 } 523 else { 524 map *tmp = getMap(m, n); 525 if (tmp->value != NULL) 526 free(tmp->value); 527 tmp->value = zStrdup(v); 528 } 529 } 471 530 } 472 531 … … 506 565 */ 507 566 map* addToMapWithSize(map* m,const char* n,const char* v,int size){ 567 char sin[128]; 568 char sname[10]="size"; 569 map *tmp; 508 570 if(hasKey(m,n)==false){ 509 571 map* _cursor=m; … … 514 576 } 515 577 } 516 char sname[10]="size";517 578 if(strlen(n)>5) 518 579 sprintf(sname,"size_%s",n+6); 519 map *tmp=getMap(m,n);580 tmp=getMap(m,n); 520 581 if(tmp->value!=NULL) 521 582 free(tmp->value); … … 524 585 memmove(tmp->value,v,size*sizeof(char)); 525 586 tmp->value[size]=0; 526 char sin[128];527 587 sprintf(sin,"%d",size); 528 588 addToMap(m,sname,sin); … … 545 605 } 546 606 else{ 547 #ifdef DEBUG548 fprintf(stderr,"_CURSOR\n");549 dumpMap(_cursor);550 #endif551 while(_cursor->next!=NULL)552 _cursor=_cursor->next;553 607 map* tmp1=getMap(*mo,tmp->name); 554 608 if(tmp1==NULL){ 609 while(_cursor->next!=NULL) 610 _cursor=_cursor->next; 555 611 _cursor->next=createMap(tmp->name,tmp->value); 556 612 } … … 561 617 _cursor=*mo; 562 618 tmp=tmp->next; 563 #ifdef DEBUG564 fprintf(stderr,"MO\n");565 dumpMap(*mo);566 #endif567 619 } 568 620 } … … 678 730 map* size=getMap(in,"size"); 679 731 map *lout=*out; 732 map *tmpVin,*tmpVout; 680 733 if(size!=NULL && pos>0){ 681 734 char tmp[11]; … … 683 736 size=getMap(in,tmp); 684 737 sprintf(tmp,"value_%d",pos); 685 map*tmpVin=getMap(in,tmp);686 map*tmpVout=getMap(lout,tmp);738 tmpVin=getMap(in,tmp); 739 tmpVout=getMap(lout,tmp); 687 740 free(tmpVout->value); 688 741 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char)); … … 691 744 }else{ 692 745 if(size!=NULL){ 693 map*tmpVin=getMap(in,"value");694 map*tmpVout=getMap(lout,"value");746 tmpVin=getMap(in,"value"); 747 tmpVout=getMap(lout,"value"); 695 748 free(tmpVout->value); 696 749 tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char)); … … 712 765 map* size=getMap(in,"size"); 713 766 map* length=getMap(in,"length"); 767 map* toload=getMap(in,"to_load"); 768 if(toload!=NULL && strcasecmp(toload->value,"false")==0){ 769 #ifdef DEBUG 770 fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__); 771 #endif 772 return ; 773 } 714 774 if(length!=NULL){ 715 775 int len=atoi(length->value); … … 734 794 maps* res=NULL; 735 795 if(_cursor!=NULL){ 796 map* mc=_cursor->content; 797 maps* mcs=_cursor->child; 736 798 res=createMaps(_cursor->name); 737 map* mc=_cursor->content;738 799 if(mc!=NULL){ 739 800 addMapToMap(&res->content,mc); 740 801 loadMapBinaries(&res->content,mc); 741 802 } 742 maps* mcs=_cursor->child;743 803 if(mcs!=NULL){ 744 804 res->child=dupMaps(&mcs); … … 764 824 } 765 825 else{ 826 maps* tmp1=getMaps(*mo,tmp->name); 766 827 while(_cursor->next!=NULL) 767 828 _cursor=_cursor->next; 768 maps* tmp1=getMaps(*mo,tmp->name);769 829 if(tmp1==NULL){ 770 830 _cursor->next=dupMaps(&tmp); … … 797 857 map* getMapArray(map* m,const char* key,int index){ 798 858 char tmp[1024]; 859 map* tmpMap; 799 860 if(index>0) 800 861 sprintf(tmp,"%s_%d",key,index); … … 804 865 fprintf(stderr,"** KEY %s\n",tmp); 805 866 #endif 806 map*tmpMap=getMap(m,tmp);867 tmpMap=getMap(m,tmp); 807 868 #ifdef DEBUG 808 869 if(tmpMap!=NULL) … … 823 884 void setMapArray(map* m,const char* key,int index,const char* value){ 824 885 char tmp[1024]; 886 map* tmpSize; 825 887 if(index>0){ 888 map* len=getMap(m,"length"); 826 889 sprintf(tmp,"%s_%d",key,index); 827 map* len=getMap(m,"length");828 890 if((len!=NULL && atoi(len->value)<index+1) || len==NULL){ 829 891 char tmp0[5]; … … 832 894 } 833 895 } 834 else 896 else{ 835 897 sprintf(tmp,"%s",key); 836 map* tmpSize=getMapArray(m,"size",index); 898 addToMap(m,"length","1"); 899 } 900 tmpSize=getMapArray(m,"size",index); 837 901 if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){ 902 map* ptr=getMapOrFill(&m,tmp,(char *)""); 838 903 #ifdef DEBUG 839 904 fprintf(stderr,"%s\n",tmpSize->value); 840 905 #endif 841 map* ptr=getMapOrFill(&m,tmp,(char *)"");842 906 free(ptr->value); 843 907 ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char)); … … 846 910 else 847 911 addToMap(m,tmp,value); 912 } 913 914 /** 915 * Add a key and an integer value to an existing map array. 916 * 917 * @param m the map to add the KVP 918 * @param n the key to add 919 * @param index the index of the MapArray 920 * @param v the corresponding value to add 921 */ 922 void addIntToMapArray(map* m,const char* n,int index,const int v){ 923 char svalue[10]; 924 sprintf(svalue,"%d",v); 925 setMapArray(m,n,index,svalue); 848 926 } 849 927 … … 881 959 maps* tmp=mi; 882 960 maps* _cursor=getMaps(*mo,tmp->name); 883 884 if(_cursor==NULL)885 return -1;886 887 map* tmpLength=getMap(_cursor->content,"length");888 961 char tmpLen[10]; 889 962 int len=1; 890 if(tmpLength!=NULL){891 len=atoi(tmpLength->value);892 }893 894 963 char *tmpV[14]={ 895 964 (char*)"size", … … 906 975 (char*)"isCached", 907 976 (char*)"LowerCorner", 908 (char*)"UpperCorner" 977 (char*)"UpperCorner" 909 978 }; 979 int i=0; 980 map* tmpLength; 981 982 if(_cursor==NULL) 983 return -1; 984 985 tmpLength=getMap(_cursor->content,"length"); 986 if(tmpLength!=NULL){ 987 len=atoi(tmpLength->value); 988 } 989 910 990 sprintf(tmpLen,"%d",len+1); 911 991 addToMap(_cursor->content,"length",tmpLen); 912 int i=0;913 992 for(i=0;i<14;i++){ 914 993 map* tmpVI=getMap(tmp->content,tmpV[i]); … … 967 1046 res->content=NULL; 968 1047 res->metadata=NULL; 1048 res->additional_parameters=NULL; 969 1049 res->format=NULL; 970 1050 res->defaults=NULL; … … 981 1061 * @return a pointer to the allocated elements 982 1062 */ 983 elements* createElements(c har* name){1063 elements* createElements(const char* name){ 984 1064 elements* res=(elements*)malloc(ELEMENTS_SIZE); 985 1065 res->name=zStrdup(name); 986 1066 res->content=NULL; 987 1067 res->metadata=NULL; 1068 res->additional_parameters=NULL; 988 1069 res->format=NULL; 989 1070 res->defaults=NULL; … … 1020 1101 elements* tmp=e; 1021 1102 while(tmp!=NULL){ 1103 iotype* tmpio=tmp->defaults; 1104 int ioc=0; 1022 1105 fprintf(stderr,"ELEMENT [%s]\n",tmp->name); 1023 1106 fprintf(stderr," > CONTENT [%s]\n",tmp->name); … … 1025 1108 fprintf(stderr," > METADATA [%s]\n",tmp->name); 1026 1109 dumpMap(tmp->metadata); 1110 fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name); 1111 dumpMap(tmp->additional_parameters); 1027 1112 fprintf(stderr," > FORMAT [%s]\n",tmp->format); 1028 iotype* tmpio=tmp->defaults;1029 int ioc=0;1030 1113 while(tmpio!=NULL){ 1031 1114 fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc); … … 1060 1143 int i; 1061 1144 while(tmp!=NULL){ 1145 map* mcurs=tmp->content; 1146 int ioc=0; 1147 iotype* tmpio; 1062 1148 for(i=0;i<2+(4*level);i++) 1063 1149 fprintf(stderr," "); 1064 1150 fprintf(stderr,"%s:\n",tmp->name); 1065 map* mcurs=tmp->content;1066 1151 while(mcurs!=NULL){ 1067 1152 for(i=0;i<4+(4*level);i++) … … 1091 1176 dumpElementsAsYAML(tmp->child,level+1); 1092 1177 } 1093 iotype* tmpio=tmp->defaults; 1094 int ioc=0; 1178 tmpio=tmp->defaults; 1095 1179 while(tmpio!=NULL){ 1096 1180 for(i=0;i<6+(4*level);i++) … … 1142 1226 elements* cursor=e; 1143 1227 elements* tmp=NULL; 1144 if(cursor!=NULL ){1228 if(cursor!=NULL && cursor->name!=NULL){ 1145 1229 #ifdef DEBUG 1146 1230 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); … … 1149 1233 #endif 1150 1234 tmp=(elements*)malloc(ELEMENTS_SIZE); 1151 tmp->name=zStrdup( e->name);1235 tmp->name=zStrdup(cursor->name); 1152 1236 tmp->content=NULL; 1153 addMapToMap(&tmp->content, e->content);1237 addMapToMap(&tmp->content,cursor->content); 1154 1238 tmp->metadata=NULL; 1155 addMapToMap(&tmp->metadata,e->metadata); 1156 if(e->format!=NULL) 1157 tmp->format=zStrdup(e->format); 1239 addMapToMap(&tmp->metadata,cursor->metadata); 1240 tmp->additional_parameters=NULL; 1241 addMapToMap(&tmp->additional_parameters,cursor->additional_parameters); 1242 if(cursor->format!=NULL) 1243 tmp->format=zStrdup(cursor->format); 1158 1244 else 1159 1245 tmp->format=NULL; 1160 if( e->defaults!=NULL){1246 if(cursor->defaults!=NULL){ 1161 1247 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); 1162 1248 tmp->defaults->content=NULL; 1163 addMapToMap(&tmp->defaults->content, e->defaults->content);1249 addMapToMap(&tmp->defaults->content,cursor->defaults->content); 1164 1250 tmp->defaults->next=NULL; 1165 1251 #ifdef DEBUG … … 1169 1255 }else 1170 1256 tmp->defaults=NULL; 1171 if(e->supported!=NULL){ 1257 if(cursor->supported!=NULL && cursor->supported->content!=NULL){ 1258 iotype *tmp2=cursor->supported->next; 1172 1259 tmp->supported=(iotype*)malloc(IOTYPE_SIZE); 1173 1260 tmp->supported->content=NULL; 1174 addMapToMap(&tmp->supported->content, e->supported->content);1261 addMapToMap(&tmp->supported->content,cursor->supported->content); 1175 1262 tmp->supported->next=NULL; 1176 iotype *tmp2=e->supported->next; 1177 while(tmp2!=NULL){ 1263 while(tmp2!=NULL){ 1178 1264 addMapToIoType(&tmp->supported,tmp2->content); 1179 1265 #ifdef DEBUG … … 1190 1276 else 1191 1277 tmp->child=NULL; 1192 tmp->next=dupElements(cursor->next); 1278 if(cursor->next!=NULL) 1279 tmp->next=dupElements(cursor->next); 1280 else 1281 tmp->next=NULL; 1193 1282 } 1194 1283 return tmp; … … 1205 1294 elements* tmp=e; 1206 1295 if(*m==NULL){ 1207 *m=dupElements(tmp);1296 (*m)=dupElements(tmp); 1208 1297 }else{ 1209 1298 addToElements(&(*m)->next,tmp); … … 1237 1326 fprintf(stderr,"CONTENT MAP\n"); 1238 1327 dumpMap(s->content); 1239 fprintf(stderr,"CONTENT METADATA\n"); 1328 if(s->metadata!=NULL) 1329 fprintf(stderr,"CONTENT METADATA\n"); 1240 1330 dumpMap(s->metadata); 1331 if(s->additional_parameters!=NULL) 1332 fprintf(stderr,"CONTENT AdditionalParameters\n"); 1333 dumpMap(s->additional_parameters); 1241 1334 } 1242 1335 if(s->inputs!=NULL){ … … 1296 1389 res->metadata=NULL; 1297 1390 addMapToMap(&res->metadata,s->metadata); 1391 res->additional_parameters=NULL; 1392 addMapToMap(&res->additional_parameters,s->additional_parameters); 1298 1393 res->inputs=dupElements(s->inputs); 1299 1394 res->outputs=dupElements(s->outputs); … … 1309 1404 registry* p=r; 1310 1405 while(p!=NULL){ 1406 services* s=p->content; 1311 1407 fprintf(stderr,"%s \n",p->name); 1312 services* s=p->content;1313 1408 s=p->content; 1314 1409 while(s!=NULL){ … … 1509 1604 */ 1510 1605 void inheritance(registry *r,service** s){ 1606 service* ls=*s; 1607 map *profile,*level; 1511 1608 if(r==NULL) 1512 1609 return; 1513 service* ls=*s; 1514 if(ls->content==NULL) 1610 if(ls==NULL || ls->content==NULL) 1515 1611 return; 1516 map*profile=getMap(ls->content,"extend");1517 map*level=getMap(ls->content,"level");1612 profile=getMap(ls->content,"extend"); 1613 level=getMap(ls->content,"level"); 1518 1614 if(profile!=NULL&&level!=NULL){ 1519 1615 service* s1; … … 1550 1646 memset(tmp,0,1024*10*10); 1551 1647 while(tm!=NULL){ 1648 map* tc=tm->content; 1552 1649 if(i>=10) 1553 1650 break; … … 1556 1653 strcpy(tmp[i][j],tm->name); 1557 1654 j++; 1558 map* tc=tm->content;1559 1655 while(tc!=NULL){ 1560 1656 if(j>=30) … … 1609 1705 * @return true if map has a value or false if value is missing/empty/NULL 1610 1706 */ 1611 bool nonempty( map* map) {1612 return ( map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);1613 } 1614 1615 /** 1616 * Verify that a particular map value exists in a maps 1707 bool nonempty(map* map) { 1708 return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0); 1709 } 1710 1711 /** 1712 * Verify that a particular map value exists in a maps 1617 1713 * data structure, and obtain that value 1618 1714 * … … 1620 1716 * @param node name of maps node to search 1621 1717 * @param key name of map node to find 1622 * @param address to the map* if it exists, otherwise NULL1718 * @param kvp address to the map* if it exists, otherwise NULL 1623 1719 * @return true if map has a value or false if value is missing/NULL 1624 */ 1625 bool hasvalue( maps* source, const char* node, const char* key, map** kvp ) { 1626 *kvp = getMapFromMaps(source, node, key); 1627 return ( *kvp != NULL && (*kvp)->value != NULL && 1628 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0 ); 1720 * 1721 * @note The map assigned to kvp is owned by the source maps 1722 */ 1723 bool hasvalue(maps* source, const char* node, const char* key, map** kvp) { 1724 *kvp = getMapFromMaps(source, node, key); 1725 return (*kvp != NULL && (*kvp)->value != NULL && 1726 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0); 1629 1727 } 1630 1728 … … 1633 1731 * 1634 1732 * @param conf reference to configuration maps 1635 * @param service name of service 1733 * @param service name of service 1636 1734 * @param exc WPSException code 1637 1735 * @param message exception text (default: exception text in WPS specification) 1638 1736 */ 1639 void setErrorMessage( maps*& conf, const char* service, WPSException exc, const char* message) {1640 1641 1642 1643 } 1644 1645 size_t len = strlen( service ) + strlen(": ") + strlen( message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;1646 char* msg = (char*) malloc( len * sizeof(char));1737 void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) { 1738 1739 if (message == NULL) { 1740 message = WPSExceptionText[exc]; 1741 } 1742 1743 size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16; 1744 char* msg = (char*)malloc(len * sizeof(char)); 1647 1745 1648 1746 if (msg != NULL) { 1649 snprintf( msg, len*sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]);1650 setMapInMaps( conf, "lenv", "message", msg);1651 free( msg);1652 } 1747 snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]); 1748 setMapInMaps(conf, "lenv", "message", msg); 1749 free(msg); 1750 } 1653 1751 } 1654 1752 1655 1753 void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) { 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 std::time_t now_t = std::chrono::system_clock::to_time_t( now);1672 std::tm* tm = localtime( &now_t);1754 1755 size_t msglen = 512; 1756 const char empty[] = ""; 1757 1758 FILE* log; 1759 1760 // system time, process time [nanoseconds] 1761 unsigned long long sys_t, proc_t; 1762 1763 // processor time consumed by the program: 1764 clock_t t = clock(); 1765 1766 // system time: 1767 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 1768 1769 std::time_t now_t = std::chrono::system_clock::to_time_t(now); 1770 std::tm* tm = localtime(&now_t); 1673 1771 char* str = asctime(tm); 1674 str[strlen(str)-1] = '\0'; // remove newline1675 1676 1677 1678 1679 1680 if ( message != NULL) {1681 1682 } 1683 1684 1685 1686 1687 char* text = (char*) malloc( sizeof(char)*msglen);1688 1689 snprintf( text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1690 _getpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ //1691 1692 if ( file != NULL && (log = fopen( file, "a+" )) != NULL) {1693 fputs( text, log);1694 fclose( log);1695 1696 1697 1698 if ( (log = fopen( MSG_LOG_FILE, "a+" )) != NULL) {1699 fputs( text, log);1700 fclose( log);1701 } 1702 1703 1704 1705 if ( text != NULL ) free( text);1772 str[strlen(str) - 1] = '\0'; // remove newline 1773 1774 sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); 1775 //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC); 1776 proc_t = t; 1777 1778 if (message != NULL) { 1779 msglen += strlen(message); 1780 } 1781 else { 1782 message = empty; 1783 } 1784 //getLastErrorMessage(); // cgiScriptName 1785 char* text = (char*)malloc(sizeof(char)*msglen); 1786 1787 snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n", 1788 zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ // 1789 1790 if (file != NULL && (log = fopen(file, "a+")) != NULL) { 1791 fputs(text, log); 1792 fclose(log); 1793 } 1794 else { 1795 #ifdef MSG_LOG_FILE 1796 if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) { 1797 fputs(text, log); 1798 fclose(log); 1799 } 1800 #endif 1801 } 1802 1803 if (text != NULL) free(text); 1706 1804 } 1707 1805 … … 1710 1808 // zooLog; 1711 1809 // zooLogMsg(NULL, getLastErrorMessage()); 1712 // zooLogMsg(log.txt, getLastErrorMessage()); 1713 1714 #ifdef WIN32 1715 #ifndef USE_MS 1716 char *strcasestr (char const *a, char const *b) 1717 { 1718 char *x = zStrdup (a); 1719 char *y = zStrdup (b); 1720 1721 x = _strlwr (x); 1722 y = _strlwr (y); 1723 char *pos = strstr (x, y); 1724 char *ret = pos == NULL ? NULL : (char *) (a + (pos - x)); 1725 free (x); 1726 free (y); 1727 return ret; 1728 }; 1729 #else 1730 ; 1731 #endif 1732 #endif 1810 // zooLogMsg("log.txt", getLastErrorMessage());
Note: See TracChangeset
for help on using the changeset viewer.