Changeset 513 for branches/PublicaMundi_David-devel
- Timestamp:
- Oct 23, 2014, 3:17:32 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c
r512 r513 39 39 #include "service_zcfg.h" 40 40 } 41 42 41 #include "ulinet.h" 43 44 42 #include <libintl.h> 45 43 #include <locale.h> 46 44 #include <string.h> 47 48 45 #include "service.h" 49 50 51 46 #include "service_internal.h" 52 53 47 #ifdef USE_PYTHON 54 48 #include "service_internal_python.h" 55 49 #endif 56 57 50 #ifdef USE_JAVA 58 51 #include "service_internal_java.h" 59 52 #endif 60 61 53 #ifdef USE_PHP 62 54 #include "service_internal_php.h" 63 55 #endif 64 65 56 #ifdef USE_JS 66 57 #include "service_internal_js.h" 67 58 #endif 68 69 59 #ifdef USE_RUBY 70 60 #include "service_internal_ruby.h" 71 61 #endif 72 73 62 #ifdef USE_PERL 74 63 #include "service_internal_perl.h" 75 64 #endif 76 77 65 #include <dirent.h> 78 66 #include <signal.h> … … 92 80 #include <time.h> 93 81 #include <stdarg.h> 94 95 82 #ifdef WIN32 96 83 extern "C" … … 115 102 } 116 103 #endif 117 118 104 #define _(String) dgettext ("zoo-kernel",String) 119 105 #define __(String) dgettext ("zoo-service",String) 120 121 106 extern int getServiceFromFile (maps *, const char *, service **); 122 107 … … 228 213 int 229 214 recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix, 230 int saved_stdout, int level, void (func) (maps *, xmlNodePtr, 215 int saved_stdout, int level, void (func) (maps *, 216 xmlNodePtr, 231 217 service *)) 232 218 { … … 250 236 setMapInMaps (m, "lenv", "level", levels); 251 237 while ((dp = readdir (dirp)) != NULL) 252 if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.'253 && strstr (dp->d_name, ".") == NULL)238 if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) 239 && dp->d_name[0] != '.' && strstr (dp->d_name, ".") == NULL) 254 240 { 255 241 256 242 char *tmp = 257 (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) * 258 sizeof (char)); 243 (char *) 244 malloc ((strlen (conf_dir) + strlen (dp->d_name) + 245 2) * sizeof (char)); 259 246 sprintf (tmp, "%s/%s", conf_dir, dp->d_name); 260 247 … … 266 253 sprintf (prefix, "%s.", dp->d_name); 267 254 268 // map* tmpMap=getMapFromMaps(m,"lenv",tmp1);255 // map* tmpMap=getMapFromMaps(m,"lenv",tmp1); 269 256 270 257 int res; … … 276 263 setMapInMaps (m, "lenv", "level", levels1); 277 264 res = 278 recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,279 func);265 recursReaddirF (m, n, tmp, prefix, saved_stdout, 266 level + 1, func); 280 267 sprintf (levels1, "%d", level); 281 268 setMapInMaps (m, "lenv", "level", levels1); … … 308 295 } 309 296 #ifdef DEBUG 310 fprintf (stderr, "#################\n%s\n#################\n",311 tmps1);297 fprintf (stderr, 298 "#################\n%s\n#################\n", tmps1); 312 299 #endif 313 300 t = readServiceFile (m, tmps1, &s1, dp->d_name); … … 318 305 char tmp01[1024]; 319 306 if (tmp00 != NULL) 320 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), 307 sprintf (tmp01, 308 _ 309 ("Unable to parse the ZCFG file: %s (%s)"), 321 310 dp->d_name, tmp00->value); 322 311 else 323 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), 312 sprintf (tmp01, 313 _ 314 ("Unable to parse the ZCFG file: %s."), 324 315 dp->d_name); 325 316 dup2 (saved_stdout, fileno (stdout)); … … 511 502 mapsToCharXXX (request_output_real_format, (char ***) outputs); 512 503 *eres = 513 execute ((char ***) &main_conf[0], (char ***) &inputs[0],514 (char ***) & outputs[0]);504 execute ((char ***) &main_conf[0], 505 (char ***) &inputs[0], (char ***) &outputs[0]); 515 506 #ifdef DEBUG 516 507 fprintf (stderr, "Function run successfully \n"); … … 524 515 #ifdef WIN32 525 516 errstr = GetLastError (); 526 fprintf (stderr, "Function %s failed to load because of %d\n", 517 fprintf (stderr, 518 "Function %s failed to load because of %d\n", 527 519 r_inputs->value, errstr); 528 520 #endif … … 556 548 free (tmpMsg); 557 549 #ifdef DEBUG 558 fprintf (stderr, "Function %s error %s\n", r_inputs->value,559 errstr);550 fprintf (stderr, "Function %s error %s\n", 551 r_inputs->value, errstr); 560 552 #endif 561 553 *eres = -1; 562 554 return; 563 555 } 564 565 556 #ifdef DEBUG 566 557 #ifdef WIN32 … … 626 617 { 627 618 *eres = 628 zoo_java_support (&m, request_inputs, s1, &request_input_real_format, 619 zoo_java_support (&m, request_inputs, s1, 620 &request_input_real_format, 629 621 &request_output_real_format); 630 622 } … … 636 628 { 637 629 *eres = 638 zoo_php_support (&m, request_inputs, s1, &request_input_real_format, 630 zoo_php_support (&m, request_inputs, s1, 631 &request_input_real_format, 639 632 &request_output_real_format); 640 633 } … … 647 640 { 648 641 *eres = 649 zoo_perl_support (&m, request_inputs, s1, &request_input_real_format, 642 zoo_perl_support (&m, request_inputs, s1, 643 &request_input_real_format, 650 644 &request_output_real_format); 651 645 } … … 657 651 { 658 652 *eres = 659 zoo_js_support (&m, request_inputs, s1, &request_input_real_format, 653 zoo_js_support (&m, request_inputs, s1, 654 &request_input_real_format, 660 655 &request_output_real_format); 661 656 } … … 667 662 { 668 663 *eres = 669 zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format, 664 zoo_ruby_support (&m, request_inputs, s1, 665 &request_input_real_format, 670 666 &request_output_real_format); 671 667 } … … 775 771 NULL, // Thread handle not inheritable 776 772 FALSE, // Set handle inheritance to FALSE 777 CREATE_NO_WINDOW, // Apache won't wait until the end 773 CREATE_NO_WINDOW, // Apache won't wait until 774 // the end 778 775 NULL, // Use parent's environment block 779 776 NULL, // Use parent's starting directory … … 947 944 else 948 945 { 949 sprintf (tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort,950 cgiS criptName);946 sprintf (tmpUrl, "http://%s:%s%s", cgiServerName, 947 cgiServerPort, cgiScriptName); 951 948 } 952 949 #ifdef DEBUG … … 1139 1136 || strlen (r_inputs->name) == 0 || strlen (r_inputs->value) == 0) 1140 1137 { 1141 errorException (m, _("Mandatory <identifier> was not specified"), 1138 errorException (m, 1139 _("Mandatory <identifier> was not specified"), 1142 1140 "MissingParameterValue", "identifier"); 1143 1141 freeMaps (&m); … … 1152 1150 if (dirp == NULL) 1153 1151 { 1154 errorException (m, _("The specified path path doesn't exist."), 1152 errorException (m, 1153 _("The specified path path doesn't exist."), 1155 1154 "InvalidParameterValue", conf_dir); 1156 1155 freeMaps (&m); … … 1339 1338 if (outputs_as_text == NULL) 1340 1339 { 1341 return errorException (m, _("Unable to allocate memory"), 1340 return errorException (m, 1341 _("Unable to allocate memory"), 1342 1342 "InternalError", NULL); 1343 1343 } … … 1354 1354 if (outputs_as_text[i] == NULL) 1355 1355 { 1356 return errorException (m, _("Unable to allocate memory"), 1356 return errorException (m, 1357 _ 1358 ("Unable to allocate memory"), 1357 1359 "InternalError", NULL); 1358 1360 } … … 1398 1400 tmpn[strlen (tmpc) - strlen (tmpv)] = 0; 1399 1401 #ifdef DEBUG 1400 fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn,1401 tmp v + 1);1402 fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", 1403 tmpn, tmpv + 1); 1402 1404 #endif 1403 1405 if (tmp_output->content == NULL) … … 1444 1446 else 1445 1447 { 1446 errorException (m, _("Parameter <DataInputs> was not specified"), 1448 errorException (m, 1449 _("Parameter <DataInputs> was not specified"), 1447 1450 "MissingParameterValue", "DataInputs"); 1448 1451 freeMaps (&m); … … 1466 1469 { 1467 1470 char *tmp2 = url_decode (tmp1); 1468 snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",1469 tmp2);1471 snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), 1472 "%s", tmp2); 1470 1473 free (tmp2); 1471 1474 pToken = strtok (cursor_input, ";"); … … 1494 1497 if (inputs_as_text[i] == NULL) 1495 1498 { 1496 return errorException (m, _("Unable to allocate memory."), 1499 return errorException (m, 1500 _("Unable to allocate memory."), 1497 1501 "InternalError", NULL); 1498 1502 } … … 1535 1539 { 1536 1540 return errorException (m, 1537 _("Unable to allocate memory."), 1541 _ 1542 ("Unable to allocate memory."), 1538 1543 "InternalError", NULL); 1539 1544 } … … 1553 1558 { 1554 1559 #ifdef DEBUG 1555 fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",1556 tmpc);1560 fprintf (stderr, 1561 "*** KVP NON URL-ENCODED \n***%s***\n", tmpc); 1557 1562 #endif 1558 1563 char *tmpv1 = strstr (tmpc, "="); 1559 1564 #ifdef DEBUG 1560 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1565 fprintf (stderr, 1566 "*** VALUE NON URL-ENCODED \n***%s***\n", 1561 1567 tmpv1 + 1); 1562 1568 #endif … … 1575 1581 map *lmap = getLastMap (tmpmaps->content); 1576 1582 char *tmpValue = 1577 (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) * 1578 sizeof (char)); 1583 (char *) 1584 malloc ((strlen (tmpv) + strlen (tmpc) + 1585 1) * sizeof (char)); 1579 1586 sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc); 1580 1587 free (lmap->value); … … 1585 1592 } 1586 1593 #ifdef DEBUG 1587 fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n", 1588 tmpn1); 1589 fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n", 1594 fprintf (stderr, 1595 "*** NAME NON URL-ENCODED \n***%s***\n", tmpn1); 1596 fprintf (stderr, 1597 "*** VALUE NON URL-ENCODED \n***%s***\n", 1590 1598 tmpv1 + 1); 1591 1599 #endif … … 1595 1603 { 1596 1604 char *tmpx2 = url_decode (tmpv1 + 1); 1597 if (strncasecmp (tmpx2, "http://", 7) != 0 &&1598 strncasecmp (tmpx2, "ftp://", 6) != 0 &&1599 strncasecmp (tmpx2, "https://", 8) != 0)1605 if (strncasecmp (tmpx2, "http://", 7) != 0 1606 && strncasecmp (tmpx2, "ftp://", 6) != 0 1607 && strncasecmp (tmpx2, "https://", 8) != 0) 1600 1608 { 1601 1609 char emsg[1024]; … … 1650 1658 else 1651 1659 { 1652 maps *testPresence = 1653 getMaps (request_input_real_format,tmpmaps->name);1660 maps *testPresence = getMaps (request_input_real_format, 1661 tmpmaps->name); 1654 1662 if (testPresence != NULL) 1655 1663 { … … 1659 1667 { 1660 1668 if (appendMapsToMaps 1661 (m, request_input_real_format, tmpmaps,1662 elem) < 0)1669 (m, request_input_real_format, 1670 tmpmaps, elem) < 0) 1663 1671 { 1664 1672 freeMaps (&m); … … 1735 1743 xmlStrlen (cur2->name)) == 0) 1736 1744 { 1737 xmlChar *val = 1738 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 1745 xmlChar *val = xmlNodeListGetString (doc, 1746 cur2->xmlChildrenNode, 1747 1); 1739 1748 if (tmpmaps == NULL) 1740 1749 { … … 1759 1768 (cur2->name, BAD_CAST "Title", 1760 1769 xmlStrlen (cur2->name)) == 0 1761 || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract", 1770 || xmlStrncasecmp (cur2->name, 1771 BAD_CAST "Abstract", 1762 1772 xmlStrlen (cur2->name)) == 0) 1763 1773 { 1764 xmlChar *val = 1765 xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1); 1774 xmlChar *val = xmlNodeListGetString (doc, 1775 cur2->xmlChildrenNode, 1776 1); 1766 1777 if (tmpmaps == NULL) 1767 1778 { … … 1807 1818 #endif 1808 1819 const char *refs[5] = 1809 { "mimeType", "encoding", "schema", "method", 1820 { "mimeType", "encoding", "schema", 1821 "method", 1810 1822 "href" 1811 1823 }; … … 1815 1827 fprintf (stderr, "*** %s ***", refs[l]); 1816 1828 #endif 1817 xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]); 1829 xmlChar *val = xmlGetProp (cur2, 1830 BAD_CAST refs[l]); 1818 1831 if (val != NULL && xmlStrlen (val) > 0) 1819 1832 { 1820 1833 if (tmpmaps->content != NULL) 1821 addToMap (tmpmaps->content, refs[l],1822 (char *) val);1834 addToMap (tmpmaps->content, 1835 refs[l], (char *) val); 1823 1836 else 1824 1837 tmpmaps->content = 1825 1838 createMap (refs[l], (char *) val); 1826 map *ltmp = getMap (tmpmaps->content, "method"); 1839 map *ltmp = getMap (tmpmaps->content, 1840 "method"); 1827 1841 if (l == 4) 1828 1842 { 1829 1843 if (! 1830 1844 (ltmp != NULL 1831 && strncmp (ltmp->value, "POST", 1845 && strncmp (ltmp->value, 1846 "POST", 1832 1847 4) == 0) 1833 1848 && CHECK_INET_HANDLE (hInternet)) 1834 1849 { 1835 1850 if (loadRemoteFile 1836 (&m, &tmpmaps->content, &hInternet, 1837 (char *) val) != 0) 1851 (&m, 1852 &tmpmaps->content, 1853 &hInternet, (char *) val) != 0) 1838 1854 { 1839 1855 freeMaps (&m); … … 1859 1875 #endif 1860 1876 xmlNodePtr cur3 = cur2->children; 1861 /* HINTERNET hInternetP; 1862 hInternetP=InternetOpen( 1863 #ifndef WIN32 1864 (LPCTSTR) 1865 #endif 1866 "ZooWPSClient\0", 1867 INTERNET_OPEN_TYPE_PRECONFIG, 1868 NULL,NULL, 0); */ 1869 //hInternet.ihandle[hInternet.nb].header=NULL; 1877 /* 1878 * HINTERNET hInternetP; hInternetP=InternetOpen( 1879 * #ifndef WIN32 (LPCTSTR) #endif 1880 * "ZooWPSClient\0", INTERNET_OPEN_TYPE_PRECONFIG, 1881 * NULL,NULL, 0); 1882 */ 1883 // hInternet.ihandle[hInternet.nb].header=NULL; 1870 1884 while (cur3 != NULL) 1871 1885 { … … 1875 1889 if (cur3 == NULL) 1876 1890 break; 1877 if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") ==1878 0)1891 if (xmlStrcasecmp 1892 (cur3->name, BAD_CAST "Header") == 0) 1879 1893 { 1880 1894 const char *ha[2]; … … 1886 1900 for (hai = 0; hai < 2; hai++) 1887 1901 { 1888 xmlChar *val = 1889 xmlGetProp (cur3, BAD_CAST ha[hai]); 1902 xmlChar *val = xmlGetProp (cur3, 1903 BAD_CAST 1904 ha[hai]); 1890 1905 #ifdef POST_DEBUG 1891 fprintf (stderr, "%s = %s\n", ha[hai], 1892 (char *) val); 1906 fprintf (stderr, 1907 "%s = %s\n", 1908 ha[hai], (char *) val); 1893 1909 #endif 1894 1910 if (hai == 0) … … 1898 1914 else 1899 1915 { 1900 has = 1901 (char *) 1902 malloc ((4 + xmlStrlen (val) + 1903 strlen (key)) * 1904 sizeof (char)); 1916 has = (char *) 1917 malloc ((4 + 1918 xmlStrlen 1919 (val) + 1920 strlen 1921 (key)) * sizeof (char)); 1905 1922 if (has == NULL) 1906 1923 { 1907 return errorException (m, 1908 _ 1909 ("Unable to allocate memory."), 1910 "InternalError", 1911 NULL); 1924 return 1925 errorException 1926 (m, 1927 _ 1928 ("Unable to allocate memory."), 1929 "InternalError", NULL); 1912 1930 } 1913 1931 snprintf (has, 1914 (3 + xmlStrlen (val) + 1915 strlen (key)), "%s: %s", key, 1916 (char *) val); 1932 (3 + 1933 xmlStrlen 1934 (val) + 1935 strlen 1936 (key)), 1937 "%s: %s", key, (char *) val); 1917 1938 free (key); 1918 1939 #ifdef POST_DEBUG … … 1923 1944 } 1924 1945 hInternet.ihandle[hInternet.nb].header = 1925 curl_slist_append (hInternet.ihandle 1926 [hInternet.nb].header, 1927 has); 1946 curl_slist_append 1947 (hInternet.ihandle[hInternet.nb].header, has); 1928 1948 if (has != NULL) 1929 1949 free (has); … … 1935 1955 "Try to fetch the body part of the request ...\n"); 1936 1956 #endif 1937 if (xmlStrcasecmp (cur3->name, BAD_CAST "Body")1938 == 0)1957 if (xmlStrcasecmp 1958 (cur3->name, BAD_CAST "Body") == 0) 1939 1959 { 1940 1960 #ifdef POST_DEBUG 1941 fprintf (stderr, "Body part found !!!\n", 1961 fprintf (stderr, 1962 "Body part found !!!\n", 1942 1963 (char *) cur3->content); 1943 1964 #endif 1944 1965 char *tmp = 1945 (char *) malloc (cgiContentLength + 1946 1 * sizeof (char)); 1966 (char *) 1967 malloc 1968 (cgiContentLength + 1 * sizeof (char)); 1947 1969 memset (tmp, 0, cgiContentLength); 1948 1970 xmlNodePtr cur4 = cur3->children; … … 1970 1992 xmlFreeDoc (bdoc); 1971 1993 } 1972 map *btmp = 1973 getMap (tmpmaps->content,"href");1994 map *btmp = getMap (tmpmaps->content, 1995 "href"); 1974 1996 if (btmp != NULL) 1975 1997 { 1976 1998 #ifdef POST_DEBUG 1977 fprintf (stderr, "%s %s\n", btmp->value, 1978 tmp); 1979 curl_easy_setopt (hInternet.handle, 1980 CURLOPT_VERBOSE, 1); 1981 #endif 1982 hInternet.waitingRequests[hInternet. 1983 nb] = 1984 strdup (tmp); 1985 InternetOpenUrl (&hInternet, 1986 btmp->value, 1987 hInternet. 1988 waitingRequests 1989 [hInternet.nb], 1990 strlen (hInternet. 1991 waitingRequests 1992 [hInternet. 1993 nb]), 1994 INTERNET_FLAG_NO_CACHE_WRITE, 1995 0); 1999 fprintf (stderr, 2000 "%s %s\n", btmp->value, tmp); 2001 curl_easy_setopt 2002 (hInternet.handle, 2003 CURLOPT_VERBOSE, 1); 2004 #endif 2005 hInternet.waitingRequests 2006 [hInternet.nb] = strdup (tmp); 2007 InternetOpenUrl 2008 (&hInternet, 2009 btmp->value, 2010 hInternet.waitingRequests 2011 [hInternet.nb], 2012 strlen 2013 (hInternet.waitingRequests 2014 [hInternet.nb]), 2015 INTERNET_FLAG_NO_CACHE_WRITE, 0); 1996 2016 } 1997 2017 free (tmp); 1998 2018 } 1999 else 2000 if (xmlStrcasecmp 2001 (cur3->name, 2002 BAD_CAST "BodyReference") == 0) 2019 else if (xmlStrcasecmp 2020 (cur3->name, 2021 BAD_CAST "BodyReference") == 0) 2003 2022 { 2004 xmlChar *val = 2005 xmlGetProp (cur3,BAD_CAST "href");2023 xmlChar *val = xmlGetProp (cur3, 2024 BAD_CAST "href"); 2006 2025 HINTERNET bInternet, res1; 2007 2026 bInternet = InternetOpen ( … … 2016 2035 "WARNING : hInternet handle failed to initialize"); 2017 2036 #ifdef POST_DEBUG 2018 curl_easy_setopt (bInternet.handle,2019 2037 curl_easy_setopt 2038 (bInternet.handle, CURLOPT_VERBOSE, 1); 2020 2039 #endif 2021 2040 bInternet.waitingRequests[0] = 2022 2041 strdup ((char *) val); 2023 2042 res1 = 2024 InternetOpenUrl (&bInternet,2025 bInternet.waitingRequests2026 [0], NULL, 0,2027 INTERNET_FLAG_NO_CACHE_WRITE,2028 2043 InternetOpenUrl 2044 (&bInternet, 2045 bInternet.waitingRequests 2046 [0], NULL, 0, 2047 INTERNET_FLAG_NO_CACHE_WRITE, 0); 2029 2048 processDownloads (&bInternet); 2030 2049 char *tmp = 2031 2050 (char *) 2032 malloc ((bInternet.ihandle[0].nDataLen + 2033 1) * sizeof (char)); 2051 malloc ((bInternet.ihandle 2052 [0].nDataLen 2053 + 1) * sizeof (char)); 2034 2054 if (tmp == NULL) 2035 2055 { 2036 return errorException (m, 2037 _ 2038 ("Unable to allocate memory."), 2039 "InternalError", 2040 NULL); 2056 return 2057 errorException 2058 (m, 2059 _ 2060 ("Unable to allocate memory."), 2061 "InternalError", NULL); 2041 2062 } 2042 2063 size_t bRead; 2043 InternetReadFile (bInternet.ihandle[0],2044 (LPVOID) tmp,2045 bInternet.ihandle[0].2046 2064 InternetReadFile 2065 (bInternet.ihandle[0], 2066 (LPVOID) tmp, 2067 bInternet.ihandle[0].nDataLen, &bRead); 2047 2068 tmp[bInternet.ihandle[0].nDataLen] = 0; 2048 2069 InternetCloseHandle (&bInternet); 2049 map *btmp = 2050 getMap (tmpmaps->content,"href");2070 map *btmp = getMap (tmpmaps->content, 2071 "href"); 2051 2072 if (btmp != NULL) 2052 2073 { 2053 2074 #ifdef POST_DEBUG 2054 fprintf (stderr, "%s %s\n", btmp->value, 2055 tmp); 2056 #endif 2057 hInternet.waitingRequests[hInternet. 2058 nb] = 2059 strdup (tmp); 2075 fprintf (stderr, 2076 "%s %s\n", btmp->value, tmp); 2077 #endif 2078 hInternet.waitingRequests 2079 [hInternet.nb] = strdup (tmp); 2060 2080 res = 2061 InternetOpenUrl (&hInternet, 2062 btmp->value, 2063 hInternet. 2064 waitingRequests 2065 [hInternet.nb], 2066 strlen (hInternet. 2067 waitingRequests 2068 [hInternet. 2069 nb]), 2070 INTERNET_FLAG_NO_CACHE_WRITE, 2071 0); 2081 InternetOpenUrl 2082 (&hInternet, 2083 btmp->value, 2084 hInternet.waitingRequests 2085 [hInternet.nb], 2086 strlen 2087 (hInternet.waitingRequests 2088 [hInternet.nb]), 2089 INTERNET_FLAG_NO_CACHE_WRITE, 0); 2072 2090 } 2073 2091 free (tmp); … … 2082 2100 #ifdef DEBUG 2083 2101 dumpMap (tmpmaps->content); 2084 fprintf (stderr, "= element 2 node \"%s\" = (%s)\n", 2102 fprintf (stderr, 2103 "= element 2 node \"%s\" = (%s)\n", 2085 2104 cur2->name, cur2->content); 2086 2105 #endif … … 2112 2131 { 2113 2132 #ifdef DEBUG 2114 fprintf (stderr, "*** LiteralData %s ***", 2115 list[l]); 2116 #endif 2117 xmlChar *val = 2118 xmlGetProp (cur4, BAD_CAST list[l]); 2133 fprintf (stderr, 2134 "*** LiteralData %s ***", list[l]); 2135 #endif 2136 xmlChar *val = xmlGetProp (cur4, 2137 BAD_CAST 2138 list[l]); 2119 2139 if (val != NULL 2120 2140 && strlen ((char *) val) > 0) 2121 2141 { 2122 2142 if (tmpmaps->content != NULL) 2123 addToMap (tmpmaps->content, list[l], 2124 (char *) val); 2143 addToMap 2144 (tmpmaps->content, 2145 list[l], (char *) val); 2125 2146 else 2126 2147 tmpmaps->content = … … 2134 2155 } 2135 2156 } 2136 else 2137 if (xmlStrcasecmp 2138 (cur4->name, BAD_CAST "ComplexData") == 0) 2157 else if (xmlStrcasecmp 2158 (cur4->name, BAD_CAST "ComplexData") == 0) 2139 2159 { 2140 2160 /** … … 2142 2162 * mimeType, encoding, schema 2143 2163 */ 2144 const char *coms[3] = 2145 { "mimeType", "encoding", "schema" }; 2164 const char *coms[3] = { "mimeType", "encoding", 2165 "schema" 2166 }; 2146 2167 for (int l = 0; l < 3; l++) 2147 2168 { 2148 2169 #ifdef DEBUG 2149 fprintf (stderr, "*** ComplexData %s ***\n", 2170 fprintf (stderr, 2171 "*** ComplexData %s ***\n", 2150 2172 coms[l]); 2151 2173 #endif 2152 xmlChar *val = 2153 xmlGetProp (cur4, BAD_CAST coms[l]); 2174 xmlChar *val = xmlGetProp (cur4, 2175 BAD_CAST 2176 coms[l]); 2154 2177 if (val != NULL 2155 2178 && strlen ((char *) val) > 0) 2156 2179 { 2157 2180 if (tmpmaps->content != NULL) 2158 addToMap (tmpmaps->content, coms[l], 2159 (char *) val); 2181 addToMap 2182 (tmpmaps->content, 2183 coms[l], (char *) val); 2160 2184 else 2161 2185 tmpmaps->content = … … 2169 2193 } 2170 2194 2171 map *test = getMap (tmpmaps->content, "encoding"); 2195 map *test = getMap (tmpmaps->content, 2196 "encoding"); 2172 2197 if (test == NULL) 2173 2198 { 2174 2199 if (tmpmaps->content != NULL) 2175 addToMap (tmpmaps->content, "encoding",2176 " utf-8");2200 addToMap (tmpmaps->content, 2201 "encoding", "utf-8"); 2177 2202 else 2178 2203 tmpmaps->content = … … 2184 2209 { 2185 2210 xmlChar *mv = xmlNodeListGetString (doc, 2186 cur4->xmlChildrenNode, 2211 cur4-> 2212 xmlChildrenNode, 2187 2213 1); 2188 map *ltmp = 2189 getMap (tmpmaps->content,"mimeType");2214 map *ltmp = getMap (tmpmaps->content, 2215 "mimeType"); 2190 2216 if (mv == NULL 2191 2217 || 2192 2218 (xmlStrcasecmp 2193 (cur4->name, BAD_CAST "ComplexData") == 0 2194 && (ltmp == NULL 2195 || strncasecmp (ltmp->value, 2196 "text/xml", 8) == 0))) 2219 (cur4->name, 2220 BAD_CAST "ComplexData") == 2221 0 && (ltmp == NULL 2222 || 2223 strncasecmp (ltmp->value, 2224 "text/xml", 8) == 0))) 2197 2225 { 2198 2226 xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0"); … … 2200 2228 xmlNodePtr cur5 = cur4->children; 2201 2229 while (cur5 != NULL 2202 && cur5->type != XML_ELEMENT_NODE 2230 && cur5->type != 2231 XML_ELEMENT_NODE 2203 2232 && cur5->type != 2204 2233 XML_CDATA_SECTION_NODE) … … 2208 2237 { 2209 2238 xmlDocSetRootElement (doc1, cur5); 2210 xmlDocDumpFormatMemoryEnc (doc1, &mv, 2211 &buffersize, 2212 "utf-8", 1); 2239 xmlDocDumpFormatMemoryEnc 2240 (doc1, &mv, &buffersize, "utf-8", 1); 2213 2241 char size[1024]; 2214 2242 sprintf (size, "%d", buffersize); 2215 addToMap (tmpmaps->content, "size",2216 size);2243 addToMap (tmpmaps->content, 2244 "size", size); 2217 2245 xmlFreeDoc (doc1); 2218 2246 } … … 2220 2248 if (mv != NULL) 2221 2249 { 2222 addToMap (tmpmaps->content, "value",2223 (char *) mv);2250 addToMap (tmpmaps->content, 2251 "value", (char *) mv); 2224 2252 xmlFree (mv); 2225 2253 } … … 2231 2259 xmlChildrenNode, 2232 2260 0); 2233 addToMap (tmpmaps->content, "value", 2234 (char *) tmp); 2235 map *tmpv = getMap (tmpmaps->content, "value"); 2261 addToMap (tmpmaps->content, 2262 "value", (char *) tmp); 2263 map *tmpv = getMap (tmpmaps->content, 2264 "value"); 2236 2265 char *res = NULL; 2237 2266 char *curs = tmpv->value; 2238 for (int i = 0; i <= strlen (tmpv->value) / 64;2239 i ++)2267 for (int i = 0; 2268 i <= strlen (tmpv->value) / 64; i++) 2240 2269 { 2241 2270 if (res == NULL) … … 2244 2273 else 2245 2274 res = 2246 (char *) realloc (res, 2247 (((i + 1) * 65) + 2248 i) * sizeof (char)); 2275 (char *) 2276 realloc (res, 2277 (((i + 2278 1) * 2279 65) + i) * sizeof (char)); 2249 2280 int csize = i * 65; 2250 2281 strncpy (res + csize, curs, 64); … … 2253 2284 else 2254 2285 { 2255 strncpy (res + (((i + 1) * 64) + i), 2256 "\n\0", 2); 2286 strncpy (res + 2287 (((i + 2288 1) * 64) + i), "\n\0", 2); 2257 2289 curs += 64; 2258 2290 } … … 2278 2310 2279 2311 { 2280 maps *testPresence = 2281 getMaps (request_input_real_format,tmpmaps->name);2312 maps *testPresence = getMaps (request_input_real_format, 2313 tmpmaps->name); 2282 2314 if (testPresence != NULL) 2283 2315 { … … 2346 2378 if (tmpmaps == NULL) 2347 2379 { 2348 return errorException (m, _("Unable to allocate memory."), 2380 return errorException (m, 2381 _ 2382 ("Unable to allocate memory."), 2349 2383 "InternalError", NULL); 2350 2384 } … … 2370 2404 { 2371 2405 if (tmpmaps->content != NULL) 2372 addToMap (tmpmaps->content, outs[l],2373 (char *) val);2406 addToMap (tmpmaps->content, 2407 outs[l], (char *) val); 2374 2408 else 2375 2409 tmpmaps->content = … … 2389 2423 xmlStrlen (cur2->name)) == 0) 2390 2424 { 2391 xmlChar *val = 2392 xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1); 2425 xmlChar *val = xmlNodeListGetString (NULL, 2426 cur2->xmlChildrenNode, 2427 1); 2393 2428 free (tmpmaps->name); 2394 2429 tmpmaps->name = zStrdup ((char *) val); … … 2413 2448 for (int k = 0; k < tmps->nodeNr; k++) 2414 2449 { 2415 // else2450 // else 2416 2451 addToMap (request_inputs, "ResponseDocument", ""); 2417 2452 maps *tmpmaps = NULL; … … 2475 2510 xmlStrlen (cur1->name)) == 0) 2476 2511 { 2477 xmlChar *val = 2478 xmlNodeListGetString (doc,cur1->xmlChildrenNode,2479 1);2512 xmlChar *val = xmlNodeListGetString (doc, 2513 cur1->xmlChildrenNode, 2514 1); 2480 2515 if (tmpmaps == NULL) 2481 2516 { … … 2498 2533 } 2499 2534 if (asRaw == true) 2500 addToMap (request_inputs, "RawDataOutput",2501 (char *) val);2535 addToMap (request_inputs, 2536 "RawDataOutput", (char *) val); 2502 2537 else 2503 2538 { 2504 2539 if (cur1cnt == 0) 2505 addToMap (request_inputs, "ResponseDocument",2506 (char *) val);2540 addToMap (request_inputs, 2541 "ResponseDocument", (char *) val); 2507 2542 else 2508 2543 { 2509 map *tt = 2510 getMap (request_inputs,"ResponseDocument");2544 map *tt = getMap (request_inputs, 2545 "ResponseDocument"); 2511 2546 char *tmp = zStrdup (tt->value); 2512 2547 free (tt->value); 2513 tt->value = 2514 (char *) 2548 tt->value = (char *) 2515 2549 malloc ((strlen (tmp) + 2516 strlen ((char *) val) + 2517 1) * sizeof (char)); 2518 sprintf (tt->value, "%s;%s", tmp, 2519 (char *) val); 2550 strlen ((char 2551 *) 2552 val) + 1) * sizeof (char)); 2553 sprintf (tt->value, "%s;%s", 2554 tmp, (char *) val); 2520 2555 free (tmp); 2521 2556 } … … 2527 2562 * Title, Asbtract 2528 2563 */ 2529 else 2530 if (xmlStrncasecmp 2531 (cur1->name, BAD_CAST "Title", 2532 xmlStrlen (cur1->name)) == 0 2533 || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract", 2534 xmlStrlen (cur1->name)) == 0) 2564 else if (xmlStrncasecmp 2565 (cur1->name, BAD_CAST "Title", 2566 xmlStrlen (cur1->name)) == 0 2567 || xmlStrncasecmp (cur1->name, 2568 BAD_CAST 2569 "Abstract", 2570 xmlStrlen (cur1->name)) == 0) 2535 2571 { 2536 xmlChar *val = 2537 xmlNodeListGetString (doc,cur1->xmlChildrenNode,2538 1);2572 xmlChar *val = xmlNodeListGetString (doc, 2573 cur1->xmlChildrenNode, 2574 1); 2539 2575 if (tmpmaps == NULL) 2540 2576 { … … 2555 2591 { 2556 2592 if (tmpmaps->content != NULL) 2557 addToMap (tmpmaps->content, (char *) cur1->name,2558 (char *) val);2593 addToMap (tmpmaps->content, 2594 (char *) cur1->name, (char *) val); 2559 2595 else 2560 2596 tmpmaps->content = … … 2563 2599 xmlFree (val); 2564 2600 } 2565 else 2566 if (xmlStrncasecmp 2567 (cur1->name, BAD_CAST "Output", 2568 xmlStrlen (cur1->name)) == 0) 2601 else if (xmlStrncasecmp 2602 (cur1->name, BAD_CAST "Output", 2603 xmlStrlen (cur1->name)) == 0) 2569 2604 { 2570 2605 /** … … 2573 2608 */ 2574 2609 const char *outs[5] = 2575 { "mimeType", "encoding", "schema", "uom", 2610 { "mimeType", "encoding", "schema", 2611 "uom", 2576 2612 "asReference" 2577 2613 }; … … 2581 2617 fprintf (stderr, "*** %s ***\t", outs[l]); 2582 2618 #endif 2583 xmlChar *val = 2584 xmlGetProp (cur1,BAD_CAST outs[l]);2619 xmlChar *val = xmlGetProp (cur1, 2620 BAD_CAST outs[l]); 2585 2621 if (val != NULL && strlen ((char *) val) > 0) 2586 2622 { 2587 2623 if (tmpmaps->content != NULL) 2588 addToMap (tmpmaps->content, outs[l],2589 (char *) val);2624 addToMap (tmpmaps->content, 2625 outs[l], (char *) val); 2590 2626 else 2591 2627 tmpmaps->content = … … 2606 2642 */ 2607 2643 if (xmlStrncasecmp 2608 (cur2->name, BAD_CAST "Identifier", 2644 (cur2->name, 2645 BAD_CAST "Identifier", 2609 2646 xmlStrlen (cur2->name)) == 0) 2610 2647 { 2611 2648 xmlChar *val = xmlNodeListGetString (doc, 2612 cur2->xmlChildrenNode, 2649 cur2-> 2650 xmlChildrenNode, 2613 2651 1); 2614 2652 if (tmpmaps == NULL) … … 2617 2655 if (tmpmaps == NULL) 2618 2656 { 2619 return errorException (m, 2620 _ 2621 ("Unable to allocate memory."), 2622 "InternalError", 2623 NULL); 2657 return 2658 errorException 2659 (m, 2660 _ 2661 ("Unable to allocate memory."), 2662 "InternalError", NULL); 2624 2663 } 2625 2664 tmpmaps->name = zStrdup ((char *) val); … … 2638 2677 * Title, Asbtract 2639 2678 */ 2640 else 2641 if (xmlStrncasecmp 2642 (cur2->name, BAD_CAST "Title", 2643 xmlStrlen (cur2->name)) == 0 2644 || xmlStrncasecmp (cur2->name, 2645 BAD_CAST "Abstract", 2646 xmlStrlen (cur2->name)) 2647 == 0) 2679 else if (xmlStrncasecmp 2680 (cur2->name, 2681 BAD_CAST "Title", 2682 xmlStrlen (cur2->name)) == 0 2683 || xmlStrncasecmp (cur2->name, 2684 BAD_CAST 2685 "Abstract", 2686 xmlStrlen 2687 (cur2->name)) == 0) 2648 2688 { 2649 2689 xmlChar *val = xmlNodeListGetString (doc, 2650 cur2->xmlChildrenNode, 2690 cur2-> 2691 xmlChildrenNode, 2651 2692 1); 2652 2693 if (tmpmaps == NULL) … … 2655 2696 if (tmpmaps == NULL) 2656 2697 { 2657 return errorException (m, 2658 _ 2659 ("Unable to allocate memory."), 2660 "InternalError", 2661 NULL); 2698 return 2699 errorException 2700 (m, 2701 _ 2702 ("Unable to allocate memory."), 2703 "InternalError", NULL); 2662 2704 } 2663 2705 tmpmaps->name = 2664 2706 zStrdup ("missingIndetifier"); 2665 2707 tmpmaps->content = 2666 createMap ((char *) cur2->name, 2667 (char *) val); 2708 createMap ((char 2709 *) 2710 cur2->name, (char *) val); 2668 2711 tmpmaps->next = NULL; 2669 2712 } … … 2671 2714 { 2672 2715 if (tmpmaps->content != NULL) 2673 addToMap (tmpmaps->content,2674 (char *) cur2->name,2675 2716 addToMap 2717 (tmpmaps->content, 2718 (char *) cur2->name, (char *) val); 2676 2719 else 2677 2720 tmpmaps->content = … … 2710 2753 runHttpRequests (&m, &request_input_real_format, &hInternet); 2711 2754 2712 // 2755 // if(CHECK_INET_HANDLE(hInternet)) 2713 2756 InternetCloseHandle (&hInternet); 2714 2757 … … 2845 2888 strcpy (fileNameOnServer, name + t + 1); 2846 2889 2847 sprintf (storageNameOnServer, "%s/%s", path->value,2848 fileNameOnServer);2890 sprintf (storageNameOnServer, "%s/%s", 2891 path->value, fileNameOnServer); 2849 2892 #ifdef DEBUG 2850 2893 fprintf (stderr, "Name on server %s\n", … … 2854 2897 #endif 2855 2898 targetFile = 2856 open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC, 2899 open (storageNameOnServer, 2900 O_RDWR | O_CREAT | O_TRUNC, 2857 2901 S_IRWXU | S_IRGRP | S_IROTH); 2858 2902 if (targetFile < 0) 2859 2903 { 2860 2904 #ifdef DEBUG 2861 fprintf (stderr, "could not create the new file,%s\n", 2905 fprintf (stderr, 2906 "could not create the new file,%s\n", 2862 2907 fileNameOnServer); 2863 2908 #endif … … 2865 2910 else 2866 2911 { 2867 while (cgiFormFileRead (file, buffer, BufferLen, &got) 2912 while (cgiFormFileRead 2913 (file, buffer, BufferLen, &got) 2868 2914 == cgiFormSuccess) 2869 2915 { … … 2915 2961 } 2916 2962 #ifdef DEBUG 2963 if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0) 2964 { 2965 fflush (stderr); 2966 fprintf (stderr, "setting variable... %s\n", "OK"); 2967 } 2968 else 2969 { 2970 fflush (stderr); 2971 fprintf (stderr, "setting variable... %s\n", "OK"); 2972 } 2973 #else 2974 2975 2976 SetEnvironmentVariable (mapcs->name, mapcs->value); 2977 #endif 2978 char *toto = 2979 (char 2980 *) malloc ((strlen 2981 (mapcs->name) + 2982 strlen (mapcs->value) + 2) * sizeof (char)); 2983 sprintf (toto, "%s=%s", mapcs->name, mapcs->value); 2984 putenv (toto); 2985 #ifdef DEBUG 2917 2986 fflush (stderr); 2918 fprintf (stderr, "setting variable... %s\n", ( 2919 #endif 2920 SetEnvironmentVariable 2921 (mapcs->name, 2922 mapcs->value) 2923 #ifdef DEBUG 2924 == 0) ? "OK" : 2925 "FAILED"); 2926 #else 2927 ; 2928 #endif 2929 char *toto = 2930 (char 2931 *)malloc ((strlen 2932 (mapcs-> 2933 name) + 2934 strlen 2935 (mapcs-> 2936 value) + 2937 2) * 2938 sizeof 2939 (char)); 2940 sprintf (toto, 2941 "%s=%s", 2942 mapcs->name, 2943 mapcs-> 2944 value); 2945 putenv (toto); 2946 #ifdef DEBUG 2947 fflush (stderr); 2948 #endif 2949 #endif 2950 #ifdef DEBUG 2951 fprintf (stderr, 2952 "[ZOO: setenv (%s=%s)]\n", 2953 mapcs->name, 2954 mapcs-> 2955 value); 2956 fflush (stderr); 2957 #endif 2958 mapcs = mapcs->next;} 2959 } 2960 2961 #ifdef DEBUG 2962 dumpMap 2963 (request_inputs); 2987 #endif 2988 #endif 2989 #ifdef DEBUG 2990 fprintf (stderr, 2991 "[ZOO: setenv (%s=%s)]\n", mapcs->name, mapcs->value); 2992 fflush (stderr); 2993 #endif 2994 mapcs = mapcs->next; 2995 } 2996 } 2997 #ifdef DEBUG 2998 dumpMap (request_inputs); 2964 2999 #endif 2965 3000 /** 2966 3001 * Need to check if we need to fork to load a status enabled 2967 3002 */ 2968 r_inputs = NULL; 2969 map * store = 2970 getMap 2971 (request_inputs, 2972 "storeExecuteResponse"); 2973 map * status = 2974 getMap 2975 (request_inputs, 2976 "status"); 3003 r_inputs = NULL; 3004 map *store = getMap (request_inputs, 3005 "storeExecuteResponse"); 3006 map *status = getMap (request_inputs, "status"); 2977 3007 /** 2978 3008 * 05-007r7 WPS 1.0.0 page 57 : … … 2980 3010 * shall raise an exception.' 2981 3011 */ 2982 if (status != NULL 2983 && 2984 strcmp 2985 (status->value, 2986 "true") == 0 2987 && store != NULL 2988 && 2989 strcmp 2990 (store->value, 2991 "false") == 0) 2992 { 2993 errorException (m, 2994 _ 2995 ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), 2996 "InvalidParameterValue", 2997 "storeExecuteResponse"); 2998 freeService (&s1); 2999 free (s1); 3000 freeMaps (&m); 3001 free (m); 3002 freeMaps 3003 (&request_input_real_format); 3004 free 3005 (request_input_real_format); 3006 freeMaps 3007 (&request_output_real_format); 3008 free 3009 (request_output_real_format); 3010 free (REQUEST); 3011 free (SERVICE_URL); 3012 return 1;} 3013 r_inputs = 3014 getMap 3015 (request_inputs, 3016 "storeExecuteResponse"); 3017 int eres = 3018 SERVICE_STARTED; 3019 int cpid = getpid (); 3012 if (status != NULL 3013 && 3014 strcmp 3015 (status->value, 3016 "true") == 0 && store != NULL && strcmp (store->value, "false") == 0) 3017 { 3018 errorException (m, 3019 _ 3020 ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), 3021 "InvalidParameterValue", "storeExecuteResponse"); 3022 freeService (&s1); 3023 free (s1); 3024 freeMaps (&m); 3025 free (m); 3026 freeMaps (&request_input_real_format); 3027 free (request_input_real_format); 3028 freeMaps (&request_output_real_format); 3029 free (request_output_real_format); 3030 free (REQUEST); 3031 free (SERVICE_URL); 3032 return 1; 3033 } 3034 r_inputs = getMap (request_inputs, "storeExecuteResponse"); 3035 int eres = SERVICE_STARTED; 3036 int cpid = getpid (); 3020 3037 /** 3021 3038 * Initialize the specific [lenv] section which contains runtime variables: … … 3036 3053 * 3037 3054 */ 3038 maps * _tmpMaps = 3039 (maps *) 3040 malloc (MAPS_SIZE); 3041 _tmpMaps->name = 3042 zStrdup ("lenv"); 3043 char tmpBuff[100]; 3044 sprintf (tmpBuff, 3045 "%i", 3046 (cpid + 3047 (int) 3048 time 3049 (NULL))); 3050 _tmpMaps->content = 3051 createMap ("usid", 3052 tmpBuff); 3053 _tmpMaps->next = 3054 NULL; 3055 sprintf (tmpBuff, 3056 "%i", cpid); 3057 addToMap 3058 (_tmpMaps->content, 3059 "sid", tmpBuff); 3060 addToMap 3061 (_tmpMaps->content, 3062 "status", "0"); 3063 addToMap 3064 (_tmpMaps->content, 3065 "cwd", ntmp); 3066 addToMap 3067 (_tmpMaps->content, 3068 "message", 3069 _ 3070 ("No message provided")); 3071 map * ltmp = 3072 getMap 3073 (request_inputs, 3074 "soap"); 3075 if (ltmp != 3076 NULL) 3077 addToMap 3078 (_tmpMaps->content, 3079 "soap", 3080 ltmp->value); 3081 else 3082 addToMap 3083 (_tmpMaps->content, 3084 "soap", "false"); 3085 if (cgiCookie != NULL 3086 && 3087 strlen 3088 (cgiCookie) > 0) 3089 { 3090 int hasValidCookie = 3091 -1; 3092 char *tcook = 3093 zStrdup (cgiCookie); 3094 char *tmp = NULL; 3095 map * testing = 3096 getMapFromMaps (m, 3097 "main", 3098 "cookiePrefix"); 3099 if (testing == NULL) 3100 { 3101 tmp = 3102 zStrdup ("ID=");} 3103 else 3104 { 3105 tmp = 3106 (char *) 3107 malloc ((strlen 3108 (testing-> 3109 value) + 3110 2) * 3111 sizeof 3112 (char)); 3113 sprintf (tmp, "%s=", 3114 testing-> 3115 value);} 3116 if (strstr 3117 (cgiCookie, 3118 ";") != NULL) 3119 { 3120 char *token, 3121 *saveptr; 3122 token = 3123 strtok_r (cgiCookie, 3124 ";", 3125 &saveptr); 3126 while (token != NULL) 3127 { 3128 if (strcasestr 3129 (token, 3130 tmp) != NULL) 3131 { 3132 if (tcook != NULL) 3133 free (tcook); 3134 tcook = 3135 zStrdup (token); 3136 hasValidCookie = 1;} 3137 token = 3138 strtok_r (NULL, ";", 3139 &saveptr);} 3140 } 3141 else 3142 { 3143 if (strstr 3144 (cgiCookie, 3145 "=") != NULL 3146 && 3147 strcasestr 3148 (cgiCookie, 3149 tmp) != NULL) 3150 { 3151 tcook = 3152 zStrdup (cgiCookie); 3153 hasValidCookie = 1;} 3154 if (tmp != NULL) 3155 { 3156 free (tmp);} 3157 } 3158 if (hasValidCookie > 3159 0) 3160 { 3161 addToMap 3162 (_tmpMaps->content, 3163 "sessid", 3164 strstr (tcook, 3165 "=") + 1); 3166 char 3167 session_file_path 3168 [1024]; 3169 map * tmpPath = 3170 getMapFromMaps (m, 3171 "main", 3172 "sessPath"); 3173 if (tmpPath == 3174 NULL) tmpPath = 3175 getMapFromMaps (m, 3176 "main", 3177 "tmpPath"); 3178 char *tmp1 = 3179 strtok (tcook, ";"); 3180 if (tmp1 != 3181 NULL) 3182 sprintf 3183 (session_file_path, 3184 "%s/sess_%s.cfg", 3185 tmpPath->value, 3186 strstr (tmp1, 3187 "=") + 1); 3188 else 3189 sprintf 3190 (session_file_path, 3191 "%s/sess_%s.cfg", 3192 tmpPath->value, 3193 strstr (cgiCookie, 3194 "=") + 1); 3195 free (tcook); 3196 maps * tmpSess = 3197 (maps *) 3198 malloc (MAPS_SIZE); 3199 struct stat 3200 file_status; 3201 int istat = 3202 stat 3203 (session_file_path, 3204 &file_status); 3205 if (istat == 0 3206 && 3207 file_status. 3208 st_size > 0) 3209 { 3210 conf_read 3211 (session_file_path, 3212 tmpSess); 3213 addMapsToMaps (&m, 3214 tmpSess); 3215 freeMaps (&tmpSess); 3216 free (tmpSess);} 3217 } 3218 } 3219 addMapsToMaps (&m, 3220 _tmpMaps); 3221 freeMaps (&_tmpMaps); 3222 free (_tmpMaps); 3223 #ifdef DEBUG 3224 dumpMap 3225 (request_inputs); 3055 maps *_tmpMaps = (maps *) malloc (MAPS_SIZE); 3056 _tmpMaps->name = zStrdup ("lenv"); 3057 char tmpBuff[100]; 3058 sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); 3059 _tmpMaps->content = createMap ("usid", tmpBuff); 3060 _tmpMaps->next = NULL; 3061 sprintf (tmpBuff, "%i", cpid); 3062 addToMap (_tmpMaps->content, "sid", tmpBuff); 3063 addToMap (_tmpMaps->content, "status", "0"); 3064 addToMap (_tmpMaps->content, "cwd", ntmp); 3065 addToMap (_tmpMaps->content, "message", _("No message provided")); 3066 map *ltmp = getMap (request_inputs, 3067 "soap"); 3068 if (ltmp != NULL) 3069 addToMap (_tmpMaps->content, "soap", ltmp->value); 3070 else 3071 addToMap (_tmpMaps->content, "soap", "false"); 3072 if (cgiCookie != NULL && strlen (cgiCookie) > 0) 3073 { 3074 int hasValidCookie = -1; 3075 char *tcook = zStrdup (cgiCookie); 3076 char *tmp = NULL; 3077 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 3078 if (testing == NULL) 3079 { 3080 tmp = zStrdup ("ID="); 3081 } 3082 else 3083 { 3084 tmp = 3085 (char *) malloc ((strlen (testing->value) + 2) * sizeof (char)); 3086 sprintf (tmp, "%s=", testing->value); 3087 } 3088 if (strstr (cgiCookie, ";") != NULL) 3089 { 3090 char *token, *saveptr; 3091 token = strtok_r (cgiCookie, ";", &saveptr); 3092 while (token != NULL) 3093 { 3094 if (strcasestr (token, tmp) != NULL) 3095 { 3096 if (tcook != NULL) 3097 free (tcook); 3098 tcook = zStrdup (token); 3099 hasValidCookie = 1; 3100 } 3101 token = strtok_r (NULL, ";", &saveptr); 3102 } 3103 } 3104 else 3105 { 3106 if (strstr 3107 (cgiCookie, "=") != NULL && strcasestr (cgiCookie, tmp) != NULL) 3108 { 3109 tcook = zStrdup (cgiCookie); 3110 hasValidCookie = 1; 3111 } 3112 if (tmp != NULL) 3113 { 3114 free (tmp); 3115 } 3116 } 3117 if (hasValidCookie > 0) 3118 { 3119 addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1); 3120 char session_file_path[1024]; 3121 map *tmpPath = getMapFromMaps (m, 3122 "main", 3123 "sessPath"); 3124 if (tmpPath == NULL) 3125 tmpPath = getMapFromMaps (m, "main", "tmpPath"); 3126 char *tmp1 = strtok (tcook, ";"); 3127 if (tmp1 != NULL) 3128 sprintf 3129 (session_file_path, 3130 "%s/sess_%s.cfg", tmpPath->value, strstr (tmp1, "=") + 1); 3131 else 3132 sprintf 3133 (session_file_path, 3134 "%s/sess_%s.cfg", tmpPath->value, strstr (cgiCookie, "=") + 1); 3135 free (tcook); 3136 maps *tmpSess = (maps *) malloc (MAPS_SIZE); 3137 struct stat file_status; 3138 int istat = stat (session_file_path, 3139 &file_status); 3140 if (istat == 0 && file_status.st_size > 0) 3141 { 3142 conf_read (session_file_path, tmpSess); 3143 addMapsToMaps (&m, tmpSess); 3144 freeMaps (&tmpSess); 3145 free (tmpSess); 3146 } 3147 } 3148 } 3149 addMapsToMaps (&m, _tmpMaps); 3150 freeMaps (&_tmpMaps); 3151 free (_tmpMaps); 3152 #ifdef DEBUG 3153 dumpMap (request_inputs); 3226 3154 #endif 3227 3155 #ifdef WIN32 3228 char *cgiSidL = NULL; 3229 if (getenv ("CGISID") 3230 != 3231 NULL) 3232 addToMap 3233 (request_inputs, 3234 "cgiSid", 3235 getenv ("CGISID")); 3236 map * test1 = 3237 getMap 3238 (request_inputs, 3239 "cgiSid"); 3240 if (test1 != NULL) 3241 { 3242 cgiSid = 3243 test1->value; 3244 addToMap 3245 (request_inputs, 3246 "storeExecuteResponse", 3247 "true"); 3248 addToMap 3249 (request_inputs, 3250 "status", "true"); 3251 setMapInMaps (m, 3252 "lenv", 3253 "sid", 3254 test1-> 3255 value); 3256 status = 3257 getMap 3258 (request_inputs, 3259 "status");} 3260 #endif 3261 char *fbkp, *fbkp1; 3262 FILE * f0, *f1; 3263 if (status != NULL) 3264 if (strcasecmp 3265 (status->value, 3266 "false") == 3267 0) status = 3268 NULLMAP; 3269 if (status == 3270 NULLMAP) 3271 { 3272 loadServiceAndRun 3273 (&m, s1, 3274 request_inputs, 3275 &request_input_real_format, 3276 &request_output_real_format, 3277 &eres);} 3278 else 3279 { 3280 int pid; 3281 #ifdef DEBUG 3282 fprintf (stderr, 3283 "\nPID : %d\n", 3284 cpid); 3156 char *cgiSidL = NULL; 3157 if (getenv ("CGISID") != NULL) 3158 addToMap (request_inputs, "cgiSid", getenv ("CGISID")); 3159 map *test1 = getMap (request_inputs, "cgiSid"); 3160 if (test1 != NULL) 3161 { 3162 cgiSid = test1->value; 3163 addToMap (request_inputs, "storeExecuteResponse", "true"); 3164 addToMap (request_inputs, "status", "true"); 3165 setMapInMaps (m, "lenv", "sid", test1->value); 3166 status = getMap (request_inputs, "status"); 3167 } 3168 #endif 3169 char *fbkp, *fbkp1; 3170 FILE *f0, *f1; 3171 if (status != NULL) 3172 if (strcasecmp (status->value, "false") == 0) 3173 status = NULLMAP; 3174 if (status == NULLMAP) 3175 { 3176 loadServiceAndRun 3177 (&m, s1, 3178 request_inputs, 3179 &request_input_real_format, &request_output_real_format, &eres); 3180 } 3181 else 3182 { 3183 int pid; 3184 #ifdef DEBUG 3185 fprintf (stderr, "\nPID : %d\n", cpid); 3285 3186 #endif 3286 3187 #ifndef WIN32 3287 3188 pid = fork (); 3288 3189 #else 3289 if (cgiSid == NULL) 3290 { 3291 createProcess (m, 3292 request_inputs, 3293 s1, 3294 NULL, 3295 cpid, 3296 request_input_real_format, 3297 request_output_real_format); 3298 pid = cpid;} 3299 else 3300 { 3301 pid = 0; 3302 cpid = 3303 atoi (cgiSid);} 3304 #endif 3305 if (pid > 0) 3306 { 3190 if (cgiSid == NULL) 3191 { 3192 createProcess (m, 3193 request_inputs, 3194 s1, 3195 NULL, 3196 cpid, 3197 request_input_real_format, 3198 request_output_real_format); 3199 pid = cpid; 3200 } 3201 else 3202 { 3203 pid = 0; 3204 cpid = atoi (cgiSid); 3205 } 3206 #endif 3207 if (pid > 0) 3208 { 3307 3209 /** 3308 3210 * dady : … … 3310 3212 */ 3311 3213 #ifdef DEBUG 3312 fprintf (stderr, 3313 "father pid continue (origin %d) %d ...\n", 3314 cpid, 3315 getpid ()); 3316 #endif 3317 eres = 3318 SERVICE_ACCEPTED;} 3319 else 3320 if (pid == 0) 3321 { 3214 fprintf (stderr, 3215 "father pid continue (origin %d) %d ...\n", 3216 cpid, getpid ()); 3217 #endif 3218 eres = SERVICE_ACCEPTED; 3219 } 3220 else if (pid == 0) 3221 { 3322 3222 /** 3323 3223 * son : have to close the stdout, stdin and stderr to let the parent 3324 3224 * process answer to http client. 3325 3225 */ 3326 r_inputs = 3327 getMapFromMaps (m, 3328 "main", 3329 "tmpPath"); 3330 map * r_inputs1 = 3331 getMap (s1->content, 3332 "ServiceProvider"); 3333 fbkp = 3334 (char *) 3335 malloc ((strlen 3336 (r_inputs-> 3337 value) + 3338 strlen 3339 (r_inputs1-> 3340 value) + 3341 1024) * 3342 sizeof 3343 (char)); 3344 sprintf (fbkp, 3345 "%s/%s_%d.xml", 3346 r_inputs-> 3347 value, 3348 r_inputs1-> 3349 value, 3350 cpid); 3351 char *flog = 3352 (char *) 3353 malloc ((strlen 3354 (r_inputs-> 3355 value) + 3356 strlen 3357 (r_inputs1-> 3358 value) + 3359 1024) * 3360 sizeof 3361 (char)); 3362 sprintf (flog, 3363 "%s/%s_%d_error.log", 3364 r_inputs-> 3365 value, 3366 r_inputs1-> 3367 value, 3368 cpid); 3369 #ifdef DEBUG 3370 fprintf (stderr, 3371 "RUN IN BACKGROUND MODE \n"); 3372 fprintf (stderr, 3373 "son pid continue (origin %d) %d ...\n", 3374 cpid, 3375 getpid ()); 3376 fprintf (stderr, 3377 "\nFILE TO STORE DATA %s\n", 3378 r_inputs-> 3379 value); 3380 #endif 3381 freopen (flog, "w+", 3382 stderr); 3383 f0 = 3384 freopen (fbkp, "w+", 3385 stdout); 3226 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 3227 map *r_inputs1 = getMap (s1->content, 3228 "ServiceProvider"); 3229 fbkp = (char *) 3230 malloc ((strlen 3231 (r_inputs->value) + 3232 strlen (r_inputs1->value) + 1024) * sizeof (char)); 3233 sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, 3234 r_inputs1->value, cpid); 3235 char *flog = 3236 (char *) 3237 malloc ((strlen (r_inputs->value) + 3238 strlen (r_inputs1->value) + 1024) * sizeof (char)); 3239 sprintf (flog, "%s/%s_%d_error.log", r_inputs->value, 3240 r_inputs1->value, cpid); 3241 #ifdef DEBUG 3242 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 3243 fprintf (stderr, 3244 "son pid continue (origin %d) %d ...\n", cpid, getpid ()); 3245 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 3246 #endif 3247 freopen (flog, "w+", stderr); 3248 f0 = freopen (fbkp, "w+", stdout); 3386 3249 #ifndef WIN32 3387 3388 #endif 3389 3250 fclose (stdin); 3251 #endif 3252 free (flog); 3390 3253 /** 3391 3254 * set status to SERVICE_STARTED and flush stdout to ensure full … … 3394 3257 * this way the data will be updated at the end of the process run. 3395 3258 */ 3396 printProcessResponse 3397 (m, request_inputs, 3398 cpid, s1, 3399 r_inputs1->value, 3400 SERVICE_STARTED, 3401 request_input_real_format, 3402 request_output_real_format); 3259 printProcessResponse 3260 (m, request_inputs, 3261 cpid, s1, 3262 r_inputs1->value, 3263 SERVICE_STARTED, 3264 request_input_real_format, request_output_real_format); 3403 3265 #ifndef WIN32 3404 3405 3266 fflush (stdout); 3267 rewind (stdout); 3406 3268 #else 3407 3269 #endif 3408 fbkp1 = 3409 (char *) 3410 malloc ((strlen 3411 (r_inputs-> 3412 value) + 3413 strlen 3414 (r_inputs1-> 3415 value) + 3416 1024) * 3417 sizeof 3418 (char)); 3419 sprintf (fbkp1, 3420 "%s/%s_final_%d.xml", 3421 r_inputs-> 3422 value, 3423 r_inputs1-> 3424 value, 3425 cpid); 3426 f1 = 3427 freopen (fbkp1, "w+", 3428 stdout); 3429 loadServiceAndRun 3430 (&m, s1, 3431 request_inputs, 3432 &request_input_real_format, 3433 &request_output_real_format, 3434 &eres);} 3435 else 3436 { 3270 fbkp1 = (char *) 3271 malloc ((strlen 3272 (r_inputs->value) + 3273 strlen (r_inputs1->value) + 1024) * sizeof (char)); 3274 sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value, 3275 r_inputs1->value, cpid); 3276 f1 = freopen (fbkp1, "w+", stdout); 3277 loadServiceAndRun 3278 (&m, s1, 3279 request_inputs, 3280 &request_input_real_format, &request_output_real_format, &eres); 3281 } 3282 else 3283 { 3437 3284 /** 3438 3285 * error server don't accept the process need to output a valid 3439 3286 * error response here !!! 3440 3287 */ 3441 eres = -1; 3442 errorException (m, 3443 _ 3444 ("Unable to run the child process properly"), 3445 "InternalError", 3446 NULL);} 3447 } 3448 3449 #ifdef DEBUG 3450 dumpMaps 3451 (request_output_real_format); 3452 #endif 3453 if (eres != -1) 3454 outputResponse (s1, 3455 request_input_real_format, 3456 request_output_real_format, 3457 request_inputs, 3458 cpid, 3459 m, 3460 eres); 3461 fflush (stdout); 3288 eres = -1; 3289 errorException (m, 3290 _ 3291 ("Unable to run the child process properly"), 3292 "InternalError", NULL); 3293 } 3294 } 3295 3296 #ifdef DEBUG 3297 dumpMaps (request_output_real_format); 3298 #endif 3299 if (eres != -1) 3300 outputResponse (s1, 3301 request_input_real_format, 3302 request_output_real_format, 3303 request_inputs, cpid, m, eres); 3304 fflush (stdout); 3462 3305 /** 3463 3306 * Ensure that if error occurs when freeing memory, no signal will return … … 3466 3309 */ 3467 3310 #ifndef USE_GDB 3468 (void) 3469 signal (SIGSEGV, 3470 donothing); 3471 (void) 3472 signal (SIGTERM, 3473 donothing); 3474 (void) 3475 signal (SIGINT, 3476 donothing); 3477 (void) 3478 signal (SIGILL, 3479 donothing); 3480 (void) 3481 signal (SIGFPE, 3482 donothing); 3483 (void) 3484 signal (SIGABRT, 3485 donothing); 3486 #endif 3487 if (((int) getpid ()) 3488 != cpid 3489 || cgiSid != 3490 NULL) 3491 { 3492 fclose (stdout); 3493 fclose (stderr); 3494 unhandleStatus (m); 3311 (void) signal (SIGSEGV, donothing); 3312 (void) signal (SIGTERM, donothing); 3313 (void) signal (SIGINT, donothing); 3314 (void) signal (SIGILL, donothing); 3315 (void) signal (SIGFPE, donothing); 3316 (void) signal (SIGABRT, donothing); 3317 #endif 3318 if (((int) getpid ()) != cpid || cgiSid != NULL) 3319 { 3320 fclose (stdout); 3321 fclose (stderr); 3322 unhandleStatus (m); 3495 3323 /** 3496 3324 * Dump back the final file fbkp1 to fbkp 3497 3325 */ 3498 fclose (f0); 3499 fclose (f1); 3500 FILE * f2 = 3501 fopen (fbkp1, "rb"); 3502 FILE * f3 = 3503 fopen (fbkp, "wb+"); 3504 free (fbkp); 3505 fseek (f2, 0, 3506 SEEK_END); 3507 long flen = 3508 ftell (f2); 3509 fseek (f2, 0, 3510 SEEK_SET); 3511 char *tmps1 = 3512 (char 3513 *)malloc ((flen + 3514 1) * 3515 sizeof 3516 (char)); 3517 fread (tmps1, flen, 3518 1, f2); 3519 fwrite (tmps1, 1, 3520 flen, f3); 3521 fclose (f2); 3522 fclose (f3); 3523 unlink (fbkp1); 3524 free (fbkp1); 3525 free (tmps1);} 3526 3527 freeService (&s1); 3528 free (s1); 3529 freeMaps (&m); 3530 free (m); 3531 freeMaps 3532 (&request_input_real_format); 3533 free 3534 (request_input_real_format); 3535 freeMaps 3536 (&request_output_real_format); 3537 free 3538 (request_output_real_format); 3539 free (REQUEST); 3540 free (SERVICE_URL); 3541 #ifdef DEBUG 3542 fprintf (stderr, 3543 "Processed response \n"); 3544 fflush (stdout); 3545 fflush (stderr); 3546 #endif 3547 return 0;} 3326 fclose (f0); 3327 fclose (f1); 3328 FILE *f2 = fopen (fbkp1, "rb"); 3329 FILE *f3 = fopen (fbkp, "wb+"); 3330 free (fbkp); 3331 fseek (f2, 0, SEEK_END); 3332 long flen = ftell (f2); 3333 fseek (f2, 0, SEEK_SET); 3334 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 3335 fread (tmps1, flen, 1, f2); 3336 fwrite (tmps1, 1, flen, f3); 3337 fclose (f2); 3338 fclose (f3); 3339 unlink (fbkp1); 3340 free (fbkp1); 3341 free (tmps1); 3342 } 3343 3344 freeService (&s1); 3345 free (s1); 3346 freeMaps (&m); 3347 free (m); 3348 freeMaps (&request_input_real_format); 3349 free (request_input_real_format); 3350 freeMaps (&request_output_real_format); 3351 free (request_output_real_format); 3352 free (REQUEST); 3353 free (SERVICE_URL); 3354 #ifdef DEBUG 3355 fprintf (stderr, "Processed response \n"); 3356 fflush (stdout); 3357 fflush (stderr); 3358 #endif 3359 return 0; 3360 }
Note: See TracChangeset
for help on using the changeset viewer.