- Main Page
- Data Structures
- Files

- File List
- Globals

# jasperserver/repository.c

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (C) 2007 JasperSoft http://www.jaspersoft.com
    00003  *
    00004  * This program is free software; you can redistribute it and/or modify
    00005  * it under the terms of the GNU General Public License as published by
    00006  * the Free Software Foundation; either version 2 of the License, or
    00007  * (at your option) any later version.
    00008  *
    00009  * This program is distributed WITHOUT ANY WARRANTY; and without the
    00010  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00011  * See the GNU General Public License for more details.
    00012  *
    00013  * You should have received a copy of the GNU General Public License
    00014  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
    00015  * or write to:
    00016  *
    00017  * Free Software Foundation, Inc.,
    00018  * 59 Temple Place - Suite 330,
    00019  * Boston, MA  USA  02111-1307
    00020  */
    00021
    00022 #define DEFAULT_ENCODING "ISO-8859-1"
    00023
    00024 #include "repository.h"
    00025 #include "stringbuffer.h"
    00026
    00027 #include <stdio.h>
    00028 #include <string.h>
    00029 #include <libxml/encoding.h>
    00030
    00031
    00032 void jasperserver_print_resource_descriptor(jasperserver_resource_descriptor_t *rd, int depth);
    00033 void jasperserver_print_resource_property(jasperserver_resource_property_t *rp, int depth);
    00034 void jasperserver_print_parameter(jasperserver_parameter_t *rp, int depth);
    00035
    00036 /*
    00037  This function free a list using a callback to function to correctly free the specific node type.
    00038 */
    00039 void jasperserver_list_free(jasperserver_list_t *list, void (*freeFunc)(void *) )
    00040 {
    00041           if (!list) return;
    00042           jasperserver_list_free(list->next, freeFunc);
    00043           //printf("Freeing node %x\n", list);
    00044           //fflush(stdout);
    00045           (*freeFunc)(list);
    00046 }
    00047
    00048
    00049 jasperserver_request_t * jasperserver_request_new()
    00050 {
    00051      jasperserver_request_t *request = (jasperserver_request_t *)malloc(sizeof(jasperserver_request_t));
    00052      jasperserver_string_t *operationName;
    00053      jasperserver_string_t *language;
    00054
    00055      operationName = jasperserver_string_new();
    00056      jasperserver_string_cappend(operationName, JS_OPERATION_LIST );
    00057
    00058      language = jasperserver_string_new();
    00059      jasperserver_string_cappend(language, "en" );
    00060
    00061      request->resource = 0;
    00062      request->opertation = operationName;
    00063      request->locale = language;
    00064      request->arguments = 0;
    00065
    00066      return request;
    00067 }
    00068
    00069
    00070 void jasperserver_request_free(jasperserver_request_t *request)
    00071 {
    00072      if (request->opertation)
    00073      {
    00074        jasperserver_string_free(request->opertation);
    00075      }
    00076
    00077      if (request->locale)
    00078      {
    00079        jasperserver_string_free(request->locale);
    00080      }
    00081
    00082      if (request->arguments)
    00083      {
    00084         jasperserver_list_free( (jasperserver_list_t *)request->arguments, jasperserver_argument_free);
    00085      }
    00086
    00087      if (request->resource)
    00088      {
    00089         jasperserver_resource_descriptor_free( request->resource);
    00090      }
    00091
    00092      free(request);
    00093 }
    00094
    00095
    00096
    00097 jasperserver_argument_t * jasperserver_argument_new()
    00098 {
    00099      jasperserver_argument_t *argument = (jasperserver_argument_t *)malloc(sizeof(jasperserver_argument_t));
    00100      jasperserver_string_t *name;
    00101      jasperserver_string_t *value;
    00102
    00103      argument->next = NULL;
    00104      argument->isListItem = 0;
    00105
    00106      name = jasperserver_string_new();
    00107      jasperserver_string_cappend(name, "" );
    00108      argument->name = name;
    00109
    00110      value = jasperserver_string_new();
    00111      jasperserver_string_cappend(value, "" );
    00112      argument->value = value;
    00113
    00114      return argument;
    00115 }
    00116
    00117
    00118 void jasperserver_argument_free(void *argument_ptr)
    00119 {
    00120      jasperserver_argument_t *argument;
    00121      argument = argument_ptr;
    00122
    00123      if (argument->name)
    00124      {
    00125         jasperserver_string_free(argument->name);
    00126      }
    00127
    00128      if (argument->value)
    00129      {
    00130         jasperserver_string_free(argument->value);
    00131      }
    00132
    00133      free(argument);
    00134 }
    00135
    00136
    00137 jasperserver_resource_descriptor_t * jasperserver_resource_descriptor_new()
    00138 {
    00139      jasperserver_resource_descriptor_t *res = (jasperserver_resource_descriptor_t *)malloc(sizeof(jasperserver_resource_descriptor_t));
    00140      jasperserver_string_t *name, *label, *description, *wsType, *uriString;
    00141
    00142      res->next = NULL;
    00143      res->isNew = 0;
    00144
    00145      res->parameters = NULL;
    00146      res->properties = NULL;
    00147      res->children = NULL;
    00148
    00149      name = jasperserver_string_new();
    00150      jasperserver_string_cappend(name, "newfolder" );
    00151      res->name = name;
    00152
    00153      label = jasperserver_string_new();
    00154      jasperserver_string_cappend(label, "newfolder" );
    00155      res->label = label;
    00156
    00157      description = jasperserver_string_new();
    00158      jasperserver_string_cset(description, "" );
    00159      res->description = description;
    00160
    00161      wsType = jasperserver_string_new();
    00162      jasperserver_string_cset(wsType, "" );
    00163      res->wsType = wsType;
    00164
    00165      uriString = jasperserver_string_new();
    00166      jasperserver_string_cappend(uriString, "/" );
    00167      res->uriString = uriString;
    00168
    00169      return res;
    00170 }
    00171
    00172
    00173 void jasperserver_resource_descriptor_free(void *res_ptr)
    00174 {
    00175      jasperserver_resource_descriptor_t *res;
    00176      res = (jasperserver_resource_descriptor_t *)res_ptr;
    00177
    00178      // Free the strings
    00179      if (res->name) {jasperserver_string_free(res->name); }
    00180      if (res->label) {jasperserver_string_free(res->label); }
    00181      if (res->description) {jasperserver_string_free(res->description); }
    00182      if (res->wsType) {jasperserver_string_free(res->wsType); }
    00183      if (res->uriString) {jasperserver_string_free(res->uriString); }
    00184
    00185      // Free the lists...
    00186      if (res->properties) {
    00187         //printf("Free properties...\n");
    00188         //fflush(stdout);
    00189         jasperserver_list_free((jasperserver_list_t *)res->properties, jasperserver_resource_property_free);
    00190         res->properties=NULL;
    00191      }
    00192
    00193      if (res->children) {
    00194         //printf("Free resources...\n");
    00195         //fflush(stdout);
    00196         jasperserver_list_free((jasperserver_list_t *)res->children, jasperserver_resource_descriptor_free);
    00197         res->children = NULL;
    00198      }
    00199
    00200      if (res->parameters) {
    00201         jasperserver_parameter_t *par = NULL;
    00202         jasperserver_list_free((jasperserver_list_t *)res->parameters, jasperserver_parameter_free);
    00203         res->parameters = NULL;
    00204      }
    00205
    00206      free(res);
    00207 }
    00208
    00209
    00210
    00211
    00212 jasperserver_resource_property_t * jasperserver_resource_property_new()
    00213 {
    00214      jasperserver_resource_property_t *resp = (jasperserver_resource_property_t *)malloc(sizeof(jasperserver_resource_property_t));
    00215      jasperserver_string_t *name;
    00216      jasperserver_string_t *value;
    00217
    00218      resp->next = NULL;
    00219      resp->properties = NULL;
    00220
    00221      name = jasperserver_string_new();
    00222      jasperserver_string_cappend(name, "" );
    00223      resp->name = name;
    00224
    00225      value = jasperserver_string_new();
    00226      jasperserver_string_cappend(value, "" );
    00227      resp->value = value;
    00228
    00229      return resp;
    00230 }
    00231
    00232
    00233 void jasperserver_resource_property_free(void *resp_ptr)
    00234 {
    00235      jasperserver_resource_property_t *resp;
    00236      resp = (jasperserver_resource_property_t *)resp_ptr;
    00237
    00238      if (resp->name)
    00239      {
    00240         jasperserver_string_free(resp->name);
    00241      }
    00242
    00243      if (resp->value)
    00244      {
    00245         jasperserver_string_free(resp->value);
    00246      }
    00247
    00248      if (resp->properties) {
    00249            jasperserver_list_free((jasperserver_list_t *)resp->properties, jasperserver_resource_property_free);
    00250            resp->properties=NULL;
    00251      }
    00252
    00253      free(resp);
    00254 }
    00255
    00256
    00257 jasperserver_parameter_t *jasperserver_parameter_new()
    00258 {
    00259      jasperserver_parameter_t *resp = (jasperserver_parameter_t *)jasperserver_argument_new();
    00260      return resp;
    00261 }
    00262
    00263
    00264 void jasperserver_parameter_free(void *resp_ptr)
    00265 {
    00266      jasperserver_argument_free(resp_ptr);
    00267 }
    00268
    00269
    00270
    00271 jasperserver_operation_result_t * jasperserver_operation_result_new()
    00272 {
    00273      jasperserver_operation_result_t *operationResult = (jasperserver_operation_result_t *)malloc(sizeof(jasperserver_operation_result_t));
    00274      jasperserver_string_t *returnMessage, *version;
    00275
    00276      operationResult->returnCode = 0;
    00277      operationResult->resources = NULL;
    00278
    00279      returnMessage = jasperserver_string_new();
    00280      jasperserver_string_cappend(returnMessage, "" );
    00281      operationResult->returnMessage = returnMessage;
    00282
    00283      version = jasperserver_string_new();
    00284      jasperserver_string_cappend(version, "" );
    00285      operationResult->version = version;
    00286
    00287      return operationResult;
    00288 }
    00289
    00290
    00291 void jasperserver_operation_result_free(void *op_ptr)
    00292 {
    00293      jasperserver_operation_result_t *resp;
    00294      resp = (jasperserver_operation_result_t *)op_ptr;
    00295
    00296      if (resp->returnMessage)
    00297      {
    00298         jasperserver_string_free(resp->returnMessage);
    00299      }
    00300
    00301      if (resp->version)
    00302      {
    00303         jasperserver_string_free(resp->version);
    00304      }
    00305
    00306      if (resp->resources) {
    00307            jasperserver_list_free((jasperserver_list_t *)resp->resources, jasperserver_resource_descriptor_free);
    00308            resp->resources=NULL;
    00309      }
    00310
    00311      free(resp);
    00312 }
    00313
    00314
    00315
    00316 jasperserver_server_t * jasperserver_server_new()
    00317 {
    00318      jasperserver_server_t *server = (jasperserver_server_t *)malloc(sizeof(jasperserver_server_t));
    00319      jasperserver_string_t *url, *username, *password;
    00320
    00321      url = jasperserver_string_new();
    00322      jasperserver_string_cappend(url, "" );
    00323      server->url = url;
    00324
    00325      username = jasperserver_string_new();
    00326      jasperserver_string_cappend(username, "" );
    00327      server->username = username;
    00328
    00329      password = jasperserver_string_new();
    00330      jasperserver_string_cappend(password, "" );
    00331      server->password = password;
    00332
    00333      return server;
    00334 }
    00335
    00336
    00337 void jasperserver_server_free(void *op_ptr)
    00338 {
    00339      jasperserver_server_t *resp;
    00340      resp = (jasperserver_server_t *)op_ptr;
    00341
    00342      if (resp->url)
    00343      {
    00344         jasperserver_string_free(resp->url);
    00345      }
    00346
    00347      if (resp->username)
    00348      {
    00349         jasperserver_string_free(resp->username);
    00350      }
    00351
    00352      if (resp->password)
    00353      {
    00354         jasperserver_string_free(resp->password);
    00355      }
    00356
    00357      free(resp);
    00358 }
    00359
    00360
    00361 void jasperserver_list_append( jasperserver_list_t **list, jasperserver_list_t *node)
    00362 {
    00363      jasperserver_list_t *current_node = NULL;
    00364
    00365      if (*list == NULL)
    00366      {
    00367         *list = node;
    00368      }
    00369      else
    00370      {
    00371          current_node = *list;
    00372          while (current_node->next)
    00373          {
    00374                current_node = current_node->next;
    00375          }
    00376          current_node->next = node;
    00377      }
    00378 }
    00379
    00380
    00381 void jasperserver_print_resource_descriptor(jasperserver_resource_descriptor_t *rd, int depth)
    00382 {
    00383           int i=0;
    00384           jasperserver_resource_property_t *property = NULL;
    00385           jasperserver_resource_descriptor_t *resource = NULL;
    00386           jasperserver_parameter_t *parameter = NULL;
    00387
    00388           if (!rd) return;
    00389           for (i=0; i<depth; ++i) printf("  ");
    00390           printf("resourceDescriptor (%s,%s,%s)\n", JS_UTFSTR(rd->name), JS_UTFSTR(rd->label), JS_UTFSTR(rd->description));
    00391
    00392           for (property = rd->properties; property; property = property->next)
    00393           {
    00394               jasperserver_print_resource_property(property, depth+1);
    00395           }
    00396
    00397           for (resource = rd->children; resource; resource = resource->next)
    00398           {
    00399               jasperserver_print_resource_descriptor(resource, depth+1);
    00400           }
    00401
    00402           for (parameter = rd->parameters; parameter; parameter = parameter->next)
    00403           {
    00404               jasperserver_print_parameter(parameter, depth+1);
    00405           }
    00406
    00407 }
    00408
    00409 void jasperserver_print_resource_property(jasperserver_resource_property_t *rp, int depth)
    00410 {
    00411           int i=0;
    00412           jasperserver_resource_property_t *subProperty = NULL;
    00413
    00414           if (!rp) return;
    00415           for (i=0; i<depth; ++i) printf("  ");
    00416           printf("resourceProperty (%s,%s)\n", JS_UTFSTR(rp->name), JS_UTFSTR(rp->value));
    00417
    00418           for (subProperty = rp->properties; subProperty; subProperty = subProperty->next)
    00419           {
    00420               jasperserver_print_resource_property(subProperty, depth+1);
    00421           }
    00422 }
    00423
    00424 void jasperserver_print_parameter(jasperserver_parameter_t *p, int depth)
    00425 {
    00426           int i=0;
    00427
    00428           if (!p) return;
    00429           for (i=0; i<depth; ++i) printf("  ");
    00430           printf("Parameter (%s,%s)\n", JS_UTFSTR(p->name), JS_UTFSTR(p->value));
    00431 }
    00432
    00433
    00434 jasperserver_resource_property_t *jasperserver_get_property(jasperserver_resource_descriptor_t *resource, char *propName)
    00435 {
    00436    jasperserver_resource_property_t *prop = NULL;
    00437    for (prop = resource->properties; prop; prop = prop->next )
    00438    {
    00439        if ( !strcmp( JS_UTFSTR(prop->name), propName ))
    00440        {
    00441             return prop;
    00442        }
    00443    }
    00444
    00445    return NULL;
    00446 }
    00447
    00448
    00449 jasperserver_string_t *jasperserver_get_property_value(jasperserver_resource_descriptor_t *resource, char *propName)
    00450 {
    00451    jasperserver_resource_property_t *prop = NULL;
    00452    prop = jasperserver_get_property( resource, propName);
    00453    if (prop) return prop->value;
    00454
    00455    return NULL;
    00456 }