Beispiel #1
0
/*
 * Retrieve an ows_version, related to current PostGIS version.
 */
ows_version * ows_psql_postgis_version(ows *o)
{
    list *l;
    PGresult * res;
    ows_version * v = NULL;

    res = ows_psql_exec(o, "SELECT substr(postgis_full_version(), 10, 5)");
    if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
        PQclear(res);
        return NULL;
    }

    l = list_explode_str('.', (char *) PQgetvalue(res, 0, 0));

    if (    l->size == 3
            && check_regexp(l->first->value->buf,       "^[0-9]+$")
            && check_regexp(l->first->next->value->buf, "^[0-9]+$")
            && check_regexp(l->last->value->buf,        "^[0-9]+$") )
    {
        v = ows_version_init();
        v->major   = atoi(l->first->value->buf);
        v->minor   = atoi(l->first->next->value->buf);
        v->release = atoi(l->last->value->buf);
    }

    list_free(l);
    PQclear(res);
    return v;
}
Beispiel #2
0
static bool apply_regexp(const QString& regexp,
                         const QString& title,
                         QString& dst)
{
  QStringList cap;
  if (!check_regexp(regexp, cap))
    return false;

  const QString p = cap.at(1);
  const bool g = cap.at(2).contains("g");
#ifdef _1
  const bool i = cap.at(2).contains("i");
#endif

  QRegExp rx(p);
#ifdef _1
  rx.setCaseSensitivity(i ? Qt::CaseInsensitive : Qt::CaseSensitive);
#endif

  int pos = 0;
  while ((pos = rx.indexIn(title, pos)) != -1)
    {
      pos += rx.matchedLength();
      dst += rx.cap(1);
      if (!g) break;
    }

  dst = dst.simplified();

  return true;
}
Beispiel #3
0
/*
 * Add to the array a buffer
 */
static array *cgi_add_buffer(array * arr, buffer * b, char *name)
{
  buffer *key, *val;

  assert(arr);
  assert(b);
  assert(name);

  key = buffer_init();
  buffer_add_str(key, name);

  /* if there is only one element in brackets, brackets are useless so delete them */
  if (check_regexp(b->buf, "^\\([^\\)]*\\)$") || check_regexp(b->buf, "^\\(.*position\\(\\).*\\)$")) {
    buffer_shift(b, 1);
    buffer_pop(b, 1);
  }

  val = buffer_init();
  buffer_copy(val, b);
  array_add(arr, key, val);

  return arr;
}
Beispiel #4
0
/*
 * Transform syntax coordinates from GML 2.1.2 (x1,y1 x2,y2) into Postgis (x1 y1,x2 y2)
 */
static  buffer *fe_transform_coord_gml2_to_psql(buffer * coord)
{
    size_t i;
    assert(coord);

    /*check if the first separator is a comma else do nothing */
    if (check_regexp(coord->buf, "^[0-9.-]+,")) {
        for (i = 0; i < coord->use; i++) {
            if (coord->buf[i] == ' ')       coord->buf[i] = ',';
            else if (coord->buf[i] == ',')  coord->buf[i] = ' ';
        }
    }

    return coord;
}
Beispiel #5
0
/*
 * Convert a date from PostgreSQL to XML
 */
buffer *ows_psql_timestamp_to_xml_time(char *timestamp)
{
    buffer *time;

    assert(timestamp);

    time = buffer_init();
    buffer_add_str(time, timestamp);
    if (!time->use) return time;

    buffer_replace(time, " ", "T");

    if (check_regexp(time->buf, "\\+"))
        buffer_add_str(time, ":00");
    else
        buffer_add_str(time, "Z");

    return time;
}
Beispiel #6
0
/*
 * Parse char by char QUERY_STRING request and return an array key/value
 * (key are all lowercase)
 */
array *cgi_parse_kvp(ows * o, char *query)
{
  int i;
  bool in_key;
  buffer *key;
  buffer *val;
  array *arr;
  char string[2];

  assert(o);
  assert(query);

  key = buffer_init();
  val = buffer_init();
  arr = array_init();
  in_key = true;

  cgi_unescape_url(query);
  cgi_remove_crlf(query);
  cgi_plustospace(query);

  for (i = 0; i < CGI_QUERY_MAX && query[i] ; i++) {

    if (query[i] == '&') {

      in_key = true;

      array_add(arr, key, val);
      key = buffer_init();
      val = buffer_init();

    } else if (query[i] == '=') {
      /* char '=' inside filter key mustn't be taken into account */
      if ((!buffer_case_cmp(key, "filter") || !buffer_case_cmp(key, "outputformat")) && buffer_cmp(val, ""))
        in_key = false;
      else buffer_add(val, query[i]);
    }
    /* Check characters'CGI request */
    else {
      /* to check the regular expression, argument must be a string, not a char */
      string[0] = query[i];
      string[1] = '\0';

      if (in_key) {

        /* if word is key, only letters are allowed */
        if (check_regexp(string, "[A-Za-zà-ÿ]"))
          buffer_add(key, tolower(query[i]));
        else {
          buffer_free(key);
          buffer_free(val);
          array_free(arr);
          ows_error(o, OWS_ERROR_MISSING_PARAMETER_VALUE,
                    "QUERY_STRING contains forbidden characters", "request");
          return NULL;
        }
      } else {
        /* if word is filter key, more characters are allowed */
        if (                                 check_regexp(string, "[A-Za-zà-ÿ0-9.\\=;,():/\\*_ \\-]")
                                             || (buffer_cmp(key, "filter") && check_regexp(string, "[A-Za-zà-ÿ0-9.#\\,():/_<> %\"\'=\\*!\\-]|\\[|\\]")))
          buffer_add(val, query[i]);
        else {
          buffer_free(key);
          buffer_free(val);
          array_free(arr);
          ows_error(o, OWS_ERROR_MISSING_PARAMETER_VALUE,
                    "QUERY_STRING contains forbidden characters", "request");
          return NULL;
        }
      }
    }
  }

  if (i == CGI_QUERY_MAX) {
    buffer_free(key);
    buffer_free(val);
    array_free(arr);
    ows_error(o, OWS_ERROR_REQUEST_HTTP, "QUERY_STRING too long", "request");
    return NULL;
  }

  array_add(arr, key, val);

  return arr;
}
Beispiel #7
0
int CV_OneStepFromFile(FILE *file, char *msg, MsgData *msgData, 
		      Tcl_Interp *interp)
{
  int count = 0;
  int invalid_line;

  *msg = '\0';
  
  /* we loop until a valid message has been read from the log file. if the end
     of the file is reached then the function returns 0. */

  do {

//	if (ReadNlFromFile(file, msg) == EOF) 
//		return (0);
// @@@ O codigo abaixo ee para tratar linhas invalidas e substitui o codigo acima
	do
	{
		if (ReadNlFromFile(file, msg) == EOF) 
			return (0);

		invalid_line = 0;

		if (strstr(msg, "Logging Task Control Server"))	// Ignore this sentence
			invalid_line = 1;

		if (strstr(msg, "Expecting 1 on port 1381"))	// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "close Module"))		// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "x_ipcClose"))			// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "Clearing handler for message"))// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "Central Abort"))		// Ignore this sentence
			invalid_line = 1;

	} while (invalid_line);
    
    *msgData = ParseMsg(msg);
    //printf("linha = %s\n", msg); // @@@ Alberto: esta lina ee util para debug

    if (COMVIEW_DEBUG) {
      fprintf(stderr, "ReadNl Got : %s\n", msg);
      fprintf(stderr, "Message type is %d\n", (*msgData)->type);
    }

    /* This next segment of code deals with the Log Window. There are a
       number of options that complicate the code; the user can select
       any of the following modes:

        1) Display all lines from log file
        2) Display only lines from the log file which are relevant 
	   to messages being sent between modules (this ignores the data
	   associated with a message, among other things).
        3) Either of the above with the ability to filter out lines
	   that have activity with an ignored module. */

    if ((count) && (listbox_msgt>=0)) { 

      /* if this is the second iteration through the while loop then
	 control never returned to Tcl, therefore the listbox variables
	 were not updated so it is done here. */
      actual_listbox_update(interp);
    }

    if (regexp) { check_regexp(msg, interp); }

    if ((display_all) || (logged_message_type((*msgData)->type))) {

      /* this does not actually update the listbox widget in Tk, it merely
	 updates some global variables that the graphical update function
	 accesses. This allows the Tcl code to look at the line and determine
	 whether or not to allow the line to be displayed. This feature is
	 used in order to ignore particular messages. */
      update_listbox_vars(msg, (*msgData)->type);

    } else {
      /* no show */
      listbox_msgt=-1;
    }

    count=1;
  } while (not_processed_msg((*msgData)->type));

  return (1);
}