Changeset 889 for trunk/zoo-project/zoo-kernel/service.c
- Timestamp:
- Jan 3, 2019, 12:44:57 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service.c
r868 r889 25 25 #include "service.h" 26 26 27 // knut: time utilities required for new log function (logMessage) 28 #include <ctime> 29 #include <chrono> 30 #include <process.h> 27 31 28 32 #if defined(_MSC_VER) && _MSC_VER < 1800 … … 450 454 */ 451 455 void addToMap(map* m,const char* n,const char* v){ 452 if(hasKey(m,n)==false){ 453 map* _cursor=m; 454 while(_cursor->next!=NULL){ 455 _cursor=_cursor->next; 456 } 457 _cursor->next=createMap(n,v); 458 } 459 else{ 460 map *tmp=getMap(m,n); 461 if(tmp->value!=NULL) 462 free(tmp->value); 463 tmp->value=zStrdup(v); 456 if (m != NULL) { // knut: add NULL-pointer check 457 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 } 464 470 } 465 471 } … … 1597 1603 } 1598 1604 1605 /** 1606 * Verify that a map has a value 1607 * 1608 * @param map pointer to map that should be checked 1609 * @return true if map has a value or false if value is missing/empty/NULL 1610 */ 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 1617 * data structure, and obtain that value 1618 * 1619 * @param source pointer to maps structure 1620 * @param node name of maps node to search 1621 * @param key name of map node to find 1622 * @param address to the map* if it exists, otherwise NULL 1623 * @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 ); 1629 } 1630 1631 /* 1632 * Set error message in configuration maps 1633 * 1634 * @param conf reference to configuration maps 1635 * @param service name of service 1636 * @param exc WPSException code 1637 * @param message exception text (default: exception text in WPS specification) 1638 */ 1639 void setErrorMessage( maps*& conf, const char* service, WPSException exc, const char* message ) { 1640 1641 if (message == NULL) { 1642 message = WPSExceptionText[exc]; 1643 } 1644 1645 size_t len = strlen( service ) + strlen(": ") + strlen( message ) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16; 1646 char* msg = (char*) malloc( len * sizeof(char) ); 1647 1648 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 } 1653 } 1654 1655 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 size_t msglen = 512; 1658 const char empty[] = ""; 1659 1660 FILE* log; 1661 1662 // system time, process time [nanoseconds] 1663 unsigned long long sys_t, proc_t; 1664 1665 // processor time consumed by the program: 1666 clock_t t = clock(); 1667 1668 // system time: 1669 std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 1670 1671 std::time_t now_t = std::chrono::system_clock::to_time_t( now ); 1672 std::tm* tm = localtime( &now_t ); 1673 char* str = asctime(tm); 1674 str[strlen(str)-1] = '\0'; // remove newline 1675 1676 sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count(); 1677 //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC); 1678 proc_t = t; 1679 1680 if ( message != NULL ) { 1681 msglen += strlen(message); 1682 } 1683 else { 1684 message = empty; 1685 } 1686 //getLastErrorMessage(); // cgiScriptName 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 else { 1697 #ifdef MSG_LOG_FILE 1698 if ( (log = fopen( MSG_LOG_FILE, "a+" )) != NULL ) { 1699 fputs( text, log ); 1700 fclose( log ); 1701 } 1702 #endif 1703 } 1704 1705 if ( text != NULL ) free( text ); 1706 } 1707 1708 // knut: 1709 // Example: 1710 // zooLog; 1711 // zooLogMsg(NULL, getLastErrorMessage()); 1712 // zooLogMsg(log.txt, getLastErrorMessage()); 1713 1599 1714 #ifdef WIN32 1600 1715 #ifndef USE_MS
Note: See TracChangeset
for help on using the changeset viewer.