Ignore:
Timestamp:
Feb 26, 2015, 11:53:34 AM (9 years ago)
Author:
knut
Message:

Implemented default result file extensions for many MIME types, based on Apache's mime.types list. Added file mimetypes.h. Made function printIOType more general with respect to media content. Rewrote the XML parsing of the <ResponseDocument?> block in Execute requests to fix problem caused by one output variable inheriting properties from another. Minor memory allocation modification in zoo_loader.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r587 r601  
    18671867      fflush (stderr);
    18681868#endif
     1869
    18691870    /**
    18701871     * Parse every Input in DataInputs node.
     
    23342335
    23352336                          map *test = getMap (tmpmaps->content, "encoding");
     2337
    23362338                          if (test == NULL)
    2337                             {
     2339                            { 
    23382340                              if (tmpmaps->content != NULL)
    23392341                                addToMap (tmpmaps->content, "encoding",
     
    23462348
    23472349                          if (strcasecmp (test->value, "base64") != 0)
    2348                             {
     2350                            { 
    23492351                              xmlChar *mv = xmlNodeListGetString (doc,
    23502352                                                                  cur4->
     
    23812383                                                size);
    23822384                                      xmlFreeDoc (doc1);
    2383                                     }
     2385                                    }                                                                   
    23842386                                }
    23852387                              if (mv != NULL)
     
    25762578        }
    25772579      else
    2578         for (int k = 0; k < tmps->nodeNr; k++)
    2579           {
    2580             //else
    2581             addToMap (request_inputs, "ResponseDocument", "");
    2582             maps *tmpmaps = NULL;
    2583             xmlNodePtr cur = tmps->nodeTab[k];
    2584             if (cur->type == XML_ELEMENT_NODE)
    2585               {
    2586           /**
    2587            * A specific responseDocument node.
    2588            */
    2589                 if (tmpmaps == NULL)
    2590                   {
    2591                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2592                     if (tmpmaps == NULL)
    2593                       {
    2594                         return errorException (m,
    2595                                                _
    2596                                                ("Unable to allocate memory."),
    2597                                                "InternalError", NULL);
    2598                       }
    2599                     tmpmaps->name = zStrdup ("unknownIdentifier");
    2600                     tmpmaps->content = NULL;
    2601                     tmpmaps->next = NULL;
    2602                   }
    2603           /**
    2604            * Get every attribute: storeExecuteResponse, lineage, status
    2605            */
    2606                 const char *ress[3] =
    2607                   { "storeExecuteResponse", "lineage", "status" };
    2608                 xmlChar *val;
    2609                 for (int l = 0; l < 3; l++)
    2610                   {
    2611 #ifdef DEBUG
    2612                     fprintf (stderr, "*** %s ***\t", ress[l]);
    2613 #endif
    2614                     val = xmlGetProp (cur, BAD_CAST ress[l]);
    2615                     if (val != NULL && strlen ((char *) val) > 0)
    2616                       {
    2617                         if (tmpmaps->content != NULL)
    2618                           addToMap (tmpmaps->content, ress[l], (char *) val);
    2619                         else
    2620                           tmpmaps->content =
    2621                             createMap (ress[l], (char *) val);
    2622                         addToMap (request_inputs, ress[l], (char *) val);
    2623                       }
    2624 #ifdef DEBUG
    2625                     fprintf (stderr, "%s\n", val);
    2626 #endif
    2627                     xmlFree (val);
    2628                   }
    2629                 xmlNodePtr cur1 = cur->children;
    2630                 while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
    2631                   cur1 = cur1->next;
    2632                 int cur1cnt = 0;
    2633                 while (cur1)
    2634                   {
    2635             /**
    2636              * Indentifier
    2637              */
    2638                     if (xmlStrncasecmp
    2639                         (cur1->name, BAD_CAST "Identifier",
    2640                          xmlStrlen (cur1->name)) == 0)
    2641                       {
    2642                         xmlChar *val =
    2643                           xmlNodeListGetString (doc, cur1->xmlChildrenNode,
    2644                                                 1);
    2645                         if (tmpmaps == NULL)
    2646                           {
    2647                             tmpmaps = (maps *) malloc (MAPS_SIZE);
    2648                             if (tmpmaps == NULL)
    2649                               {
    2650                                 return errorException (m,
    2651                                                        _
    2652                                                        ("Unable to allocate memory."),
    2653                                                        "InternalError", NULL);
    2654                               }
    2655                             tmpmaps->name = zStrdup ((char *) val);
    2656                             tmpmaps->content = NULL;
    2657                             tmpmaps->next = NULL;
    2658                           }
    2659                         else
    2660                           {
    2661                             free (tmpmaps->name);
    2662                             tmpmaps->name = zStrdup ((char *) val);
    2663                           }
    2664                         if (asRaw == true)
    2665                           addToMap (request_inputs, "RawDataOutput",
    2666                                     (char *) val);
    2667                         else
    2668                           {
    2669                             if (cur1cnt == 0)
    2670                               addToMap (request_inputs, "ResponseDocument",
    2671                                         (char *) val);
    2672                             else
    2673                               {
    2674                                 map *tt =
    2675                                   getMap (request_inputs, "ResponseDocument");
    2676                                 char *tmp = zStrdup (tt->value);
    2677                                 free (tt->value);
    2678                                 tt->value =
    2679                                   (char *)
    2680                                   malloc ((strlen (tmp) +
    2681                                            strlen ((char *) val) +
    2682                                            1) * sizeof (char));
    2683                                 sprintf (tt->value, "%s;%s", tmp,
    2684                                          (char *) val);
    2685                                 free (tmp);
    2686                               }
    2687                           }
    2688                         cur1cnt += 1;
    2689                         xmlFree (val);
    2690                       }
    2691             /**
    2692              * Title, Asbtract
    2693              */
    2694                     else
    2695                       if (xmlStrncasecmp
    2696                           (cur1->name, BAD_CAST "Title",
    2697                            xmlStrlen (cur1->name)) == 0
    2698                           || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract",
    2699                                              xmlStrlen (cur1->name)) == 0)
    2700                       {
    2701                         xmlChar *val =
    2702                           xmlNodeListGetString (doc, cur1->xmlChildrenNode,
    2703                                                 1);
    2704                         if (tmpmaps == NULL)
    2705                           {
    2706                             tmpmaps = (maps *) malloc (MAPS_SIZE);
    2707                             if (tmpmaps == NULL)
    2708                               {
    2709                                 return errorException (m,
    2710                                                        _
    2711                                                        ("Unable to allocate memory."),
    2712                                                        "InternalError", NULL);
    2713                               }
    2714                             tmpmaps->name = zStrdup ("missingIndetifier");
    2715                             tmpmaps->content =
    2716                               createMap ((char *) cur1->name, (char *) val);
    2717                             tmpmaps->next = NULL;
    2718                           }
    2719                         else
    2720                           {
    2721                             if (tmpmaps->content != NULL)
    2722                               addToMap (tmpmaps->content, (char *) cur1->name,
    2723                                         (char *) val);
    2724                             else
    2725                               tmpmaps->content =
    2726                                 createMap ((char *) cur1->name, (char *) val);
    2727                           }
    2728                         xmlFree (val);
    2729                       }
    2730                     else
    2731                       if (xmlStrncasecmp
    2732                           (cur1->name, BAD_CAST "Output",
    2733                            xmlStrlen (cur1->name)) == 0)
    2734                       {
    2735               /**
    2736                * Get every attribute from an Output node
    2737                * mimeType, encoding, schema, uom, asReference
    2738                */
    2739                         const char *outs[5] =
    2740                           { "mimeType", "encoding", "schema", "uom",
    2741                           "asReference"
    2742                         };
    2743                         for (int l = 0; l < 5; l++)
    2744                           {
    2745 #ifdef DEBUG
    2746                             fprintf (stderr, "*** %s ***\t", outs[l]);
    2747 #endif
    2748                             xmlChar *val =
    2749                               xmlGetProp (cur1, BAD_CAST outs[l]);
    2750                             if (val != NULL && strlen ((char *) val) > 0)
    2751                               {
    2752                                 if (tmpmaps->content != NULL)
    2753                                   addToMap (tmpmaps->content, outs[l],
    2754                                             (char *) val);
    2755                                 else
    2756                                   tmpmaps->content =
    2757                                     createMap (outs[l], (char *) val);
    2758                               }
    2759 #ifdef DEBUG
    2760                             fprintf (stderr, "%s\n", val);
    2761 #endif
    2762                             xmlFree (val);
    2763                           }
    2764                         xmlNodePtr cur2 = cur1->children;
    2765                         while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
    2766                           cur2 = cur2->next;
    2767                         while (cur2)
    2768                           {
    2769                 /**
    2770                  * Indentifier
     2580          {
     2581                addToMap (request_inputs, "ResponseDocument", "");
     2582                       
     2583                xmlNodePtr cur = tmps->nodeTab[0]; // only one ResponseDocument node
     2584                if (cur->type == XML_ELEMENT_NODE) {
     2585                /**
     2586                 * Get every attribute: storeExecuteResponse, lineage, status
    27712587                 */
    2772                             if (xmlStrncasecmp
    2773                                 (cur2->name, BAD_CAST "Identifier",
    2774                                  xmlStrlen (cur2->name)) == 0)
    2775                               {
    2776                                 xmlChar *val = xmlNodeListGetString (doc,
    2777                                                                      cur2->
    2778                                                                      xmlChildrenNode,
    2779                                                                      1);
    2780                                 if (tmpmaps == NULL)
    2781                                   {
    2782                                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2783                                     if (tmpmaps == NULL)
    2784                                       {
    2785                                         return errorException (m,
    2786                                                                _
    2787                                                                ("Unable to allocate memory."),
    2788                                                                "InternalError",
    2789                                                                NULL);
    2790                                       }
    2791                                     tmpmaps->name = zStrdup ((char *) val);
    2792                                     tmpmaps->content = NULL;
    2793                                     tmpmaps->next = NULL;
    2794                                   }
    2795                                 else
    2796                                   {
    2797                                     if (tmpmaps->name != NULL)
    2798                                       free (tmpmaps->name);
    2799                                     tmpmaps->name = zStrdup ((char *) val);;
    2800                                   }
    2801                                 xmlFree (val);
    2802                               }
    2803                 /**
    2804                  * Title, Asbtract
    2805                  */
    2806                             else
    2807                               if (xmlStrncasecmp
    2808                                   (cur2->name, BAD_CAST "Title",
    2809                                    xmlStrlen (cur2->name)) == 0
    2810                                   || xmlStrncasecmp (cur2->name,
    2811                                                      BAD_CAST "Abstract",
    2812                                                      xmlStrlen (cur2->name))
    2813                                   == 0)
    2814                               {
    2815                                 xmlChar *val = xmlNodeListGetString (doc,
    2816                                                                      cur2->
    2817                                                                      xmlChildrenNode,
    2818                                                                      1);
    2819                                 if (tmpmaps == NULL)
    2820                                   {
    2821                                     tmpmaps = (maps *) malloc (MAPS_SIZE);
    2822                                     if (tmpmaps == NULL)
    2823                                       {
    2824                                         return errorException (m,
    2825                                                                _
    2826                                                                ("Unable to allocate memory."),
    2827                                                                "InternalError",
    2828                                                                NULL);
    2829                                       }
    2830                                     tmpmaps->name =
    2831                                       zStrdup ("missingIndetifier");
    2832                                     tmpmaps->content =
    2833                                       createMap ((char *) cur2->name,
    2834                                                  (char *) val);
    2835                                     tmpmaps->next = NULL;
    2836                                   }
    2837                                 else
    2838                                   {
    2839                                     if (tmpmaps->content != NULL)
    2840                                       addToMap (tmpmaps->content,
    2841                                                 (char *) cur2->name,
    2842                                                 (char *) val);
    2843                                     else
    2844                                       tmpmaps->content =
    2845                                         createMap ((char *) cur2->name,
    2846                                                    (char *) val);
    2847                                   }
    2848                                 xmlFree (val);
    2849                               }
    2850                             cur2 = cur2->next;
    2851                             while (cur2 != NULL
    2852                                    && cur2->type != XML_ELEMENT_NODE)
    2853                               cur2 = cur2->next;
    2854                           }
    2855                       }
    2856                     cur1 = cur1->next;
    2857                     while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
    2858                       cur1 = cur1->next;
    2859                                  
    2860                                         if (request_output_real_format == NULL)
    2861                                           request_output_real_format = dupMaps (&tmpmaps);
    2862                                         else
    2863                                           addMapsToMaps (&request_output_real_format, tmpmaps);
    2864                   }
    2865               }
    2866           }
     2588                        //map* attributes = NULL;
     2589                        const char *ress[3] =
     2590                          { "storeExecuteResponse", "lineage", "status" };
     2591                        xmlChar *val;
     2592                        for (int l = 0; l < 3; l++)
     2593                        {
     2594        #ifdef DEBUG
     2595                                fprintf (stderr, "*** %s ***\t", ress[l]);
     2596        #endif
     2597                                val = xmlGetProp (cur, BAD_CAST ress[l]);
     2598                                if (val != NULL && strlen ((char *) val) > 0)
     2599                                {
     2600                                /*
     2601                                        if (attributes == NULL) {
     2602                                                attributes = createMap (ress[l], (char *) val);
     2603                                        }
     2604                                        else {
     2605                                                addToMap (attributes, ress[l], (char *) val);
     2606                                        }
     2607                                */             
     2608                                        addToMap (request_inputs, ress[l], (char *) val);
     2609                                  }
     2610        #ifdef DEBUG
     2611                                fprintf (stderr, "%s\n", val);
     2612        #endif
     2613                                xmlFree (val);
     2614                        }
     2615                       
     2616                        xmlNodePtr cur1 = cur->children;               
     2617                        while (cur1 != NULL) // iterate over Output nodes
     2618                        {
     2619                                if (cur1->type != XML_ELEMENT_NODE ||
     2620                                        xmlStrncasecmp(cur1->name, BAD_CAST "Output",
     2621                                                                   xmlStrlen (cur1->name)) != 0) {
     2622                                        cur1 = cur1->next;
     2623                                        continue;
     2624                                }
     2625                               
     2626                                maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node
     2627                                if (tmpmaps == NULL) {
     2628                                        return errorException (m,
     2629                                                                                   _
     2630                                                                                   ("Unable to allocate memory."),
     2631                                                                                   "InternalError", NULL);
     2632                                }
     2633                                tmpmaps->name = zStrdup ("unknownIdentifier");
     2634                                tmpmaps->content = NULL;
     2635                                tmpmaps->next = NULL;
     2636                               
     2637                                xmlNodePtr elems = cur1->children;
     2638                               
     2639                                while (elems != NULL) {
     2640                               
     2641                                        /**
     2642                                         * Identifier
     2643                                         */             
     2644                                        if (xmlStrncasecmp
     2645                                                (elems->name, BAD_CAST "Identifier",
     2646                                                 xmlStrlen (elems->name)) == 0)
     2647                                        {                       
     2648                                                xmlChar *val =
     2649                                                  xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
     2650                                               
     2651                                                free(tmpmaps->name);
     2652                                                tmpmaps->name = zStrdup ((char *) val); 
     2653                                                if (tmpmaps->content == NULL) {
     2654                                                        tmpmaps->content = createMap("Identifier", zStrdup ((char *) val));
     2655                                                }
     2656                                                else {
     2657                                                        addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val));
     2658                                                }
     2659                                         
     2660                                                map* tt = getMap (request_inputs, "ResponseDocument");                           
     2661                                                if (strlen(tt->value) == 0) {
     2662                                                  addToMap (request_inputs, "ResponseDocument",
     2663                                                                        (char *) val);                                                 
     2664                                                }       
     2665                                                else {
     2666                                                        char* tmp = (char*) malloc((strlen(tt->value) + 1
     2667                                                                                                + strlen((char*) val) + 1) * sizeof(char));
     2668                                                        sprintf (tmp, "%s;%s", tt->value, (char *) val);
     2669                                                        free(tt->value);
     2670                                                        tt->value = tmp;       
     2671                                                }       
     2672                                                xmlFree (val);
     2673                                        }                               
     2674                                        /**
     2675                                         * Title, Abstract
     2676                                         */
     2677                                        else if (xmlStrncasecmp(elems->name, BAD_CAST "Title",
     2678                                                                                        xmlStrlen (elems->name)) == 0
     2679                                                  || xmlStrncasecmp(elems->name, BAD_CAST "Abstract",
     2680                                                                                 xmlStrlen (elems->name)) == 0)
     2681                                        {
     2682                                                xmlChar *val =
     2683                                                        xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
     2684                                                       
     2685                                                if (tmpmaps->content == NULL) {
     2686                                                        tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val));
     2687                                                }
     2688                                                else {
     2689                                                        addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val));
     2690                                                }
     2691                                                xmlFree (val);
     2692                                        }
     2693                                        elems = elems->next;
     2694                                }
     2695                               
     2696                                /**
     2697                                 * Get every attribute from an Output node:
     2698                                 * mimeType, encoding, schema, uom, asReference
     2699                                 */
     2700                                const char *outs[5] =
     2701                                          { "mimeType", "encoding", "schema", "uom", "asReference" };
     2702                                         
     2703                                for (int l = 0; l < 5; l++) {
     2704        #ifdef DEBUG
     2705                                        fprintf (stderr, "*** %s ***\t", outs[l]);
     2706        #endif
     2707                                        xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]);                             
     2708                                        if (val != NULL && xmlStrlen(val) > 0) {
     2709                                                if (tmpmaps->content != NULL) {
     2710                                                        addToMap (tmpmaps->content, outs[l], (char *) val);
     2711                                                }                         
     2712                                                else {
     2713                                                        tmpmaps->content = createMap (outs[l], (char *) val);
     2714                                                }       
     2715                                        }
     2716        #ifdef DEBUG
     2717                                        fprintf (stderr, "%s\n", val);
     2718        #endif
     2719                                        xmlFree (val);
     2720                                }
     2721                               
     2722                                if (request_output_real_format == NULL) {
     2723                                        request_output_real_format = tmpmaps;
     2724                                }       
     2725                                else if (getMaps(request_output_real_format, tmpmaps->name) != NULL) {
     2726                                        return errorException (m,
     2727                                                                                   _
     2728                                                                                   ("Duplicate <Output> elements in WPS Execute request"),
     2729                                                                                   "InternalError", NULL);
     2730                                }
     2731                                else {
     2732                                        maps* mptr = request_output_real_format;
     2733                                        while (mptr->next != NULL) {
     2734                                                mptr = mptr->next;
     2735                                        }
     2736                                        mptr->next = tmpmaps;   
     2737                                }                                       
     2738                                cur1 = cur1->next;
     2739                        }                       
     2740                }
     2741          }
    28672742      xmlXPathFreeObject (tmpsptr);
    28682743      xmlFreeDoc (doc);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

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

Become a sponsor !

Knowledge partners

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

Become a knowledge partner

Related links

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