/* * Retrieve a srs from a srid */ buffer *ows_srs_get_from_a_srid(ows * o, int srid) { buffer *b; buffer *sql; PGresult *res; assert(o); sql = buffer_init(); buffer_add_str(sql, "SELECT auth_name||':'||auth_srid AS srs "); buffer_add_str(sql, "FROM spatial_ref_sys "); buffer_add_str(sql, "WHERE srid="); buffer_add_int(sql, srid); res = ows_psql_exec(o, sql->buf); buffer_free(sql); b = buffer_init(); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return b; } buffer_add_str(b, PQgetvalue(res, 0, 0)); PQclear(res); return b; }
/* * Return the column's name matching the specified number from table * (Only use in specific FE position function, so not directly inside * storage handle mechanism) */ buffer *ows_psql_column_name(ows * o, buffer * layer_name, int number) { buffer *sql; PGresult *res; buffer *column; assert(o); assert(layer_name); sql = buffer_init(); column = buffer_init(); buffer_add_str(sql, "SELECT a.attname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname ='"); buffer_copy(sql, layer_name); buffer_add_str(sql, "' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid AND a.attnum = "); buffer_add_int(sql, number); res = ows_psql_exec(o, sql->buf); buffer_free(sql); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return column; } buffer_add_str(column, PQgetvalue(res, 0, 0)); PQclear(res); return column; }
/* * Transform a bbox from initial srid to another srid passed in parameter */ bool ows_bbox_transform(ows * o, ows_bbox * bb, int srid) { buffer *sql; PGresult *res; assert(o); assert(bb); sql = buffer_init(); buffer_add_str(sql, "SELECT xmin(g), ymin(g), xmax(g), ymax(g) FROM (SELECT ST_Transform("); ows_bbox_to_query(o, bb, sql); buffer_add_str(sql, ")) AS g ) AS foo"); res = ows_psql_exec(o, sql->buf); buffer_free(sql); if (PQresultStatus(res) != PGRES_TUPLES_OK) { PQclear(res); return false; } bb->xmin = strtod(PQgetvalue(res, 0, 0), NULL); bb->ymin = strtod(PQgetvalue(res, 0, 1), NULL); bb->xmax = strtod(PQgetvalue(res, 0, 2), NULL); bb->ymax = strtod(PQgetvalue(res, 0, 3), NULL); /* TODO Error Handling */ return ows_srs_set_from_srid(o, bb->srs, srid); }
/* * Returns the list of possible values for a column according to the constraint value. * Used to return enumeration constraints in describe feature type request. */ list *ows_psql_column_check_constraint(ows * o, buffer * constraint_name) { buffer *sql; PGresult *res; list *intermediate_constraints; list *constraints; buffer *constraint_value; buffer *buf; size_t i; list_node *ln; constraints = list_init(); intermediate_constraints = list_init(); constraint_value = buffer_init(); assert(o); assert(constraint_name); sql = buffer_init(); buffer_add_str(sql, "SELECT check_clause FROM information_schema.check_constraints WHERE constraint_name = '"); buffer_add_str(sql, constraint_name->buf); buffer_add_str(sql, "'"); res = ows_psql_exec(o, sql->buf); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return constraints; } buffer_add_str(constraint_value, PQgetvalue(res, 0, 0)); PQclear(res); intermediate_constraints = list_explode(' ', constraint_value); for (ln = intermediate_constraints->first ; ln ; ln = ln->next) { if(ln->value->buf[0] == '\'') { buf = buffer_init(); for (i = 1; ln->value->buf[i] != '\0'; i++) { if(ln->value->buf[i] == '\'') break; else buffer_add(buf, ln->value->buf[i]); } list_add(constraints, buf); } } return constraints; }
/* * Add to the array the sortby element */ static array *cgi_add_sortby(array * arr, xmlNodePtr n) { buffer *key, *val; xmlNodePtr elemt, node; xmlChar *content; assert(arr); assert(n); content = NULL; key = buffer_init(); buffer_add_str(key, (char *) n->name); val = buffer_init(); elemt = n->children; if (elemt->type != XML_ELEMENT_NODE) elemt = elemt->next; /* parse the properties to sort */ for ( /* empty */ ; elemt ; elemt = elemt->next) { if (elemt->type == XML_ELEMENT_NODE) { node = elemt->children; if (node->type != XML_ELEMENT_NODE) node = node->next; /* add the property name */ content = xmlNodeGetContent(node); buffer_add_str(val, (char *) content); xmlFree(content); buffer_add_str(val, " "); node = node->next; if (node->type != XML_ELEMENT_NODE) node = node->next; /* add the order */ content = xmlNodeGetContent(node); buffer_add_str(val, (char *) content); xmlFree(content); } if (elemt->next && elemt->next->type == XML_ELEMENT_NODE) buffer_add_str(val, ","); } array_add(arr, key, val); return arr; }
/* * Add element into the buffer */ static buffer *cgi_add_into_buffer(buffer * b, xmlNodePtr n, bool need_comma) { xmlChar *content; assert(b); assert(n); if (need_comma) buffer_add_str(b, ","); content = xmlNodeGetContent(n); buffer_add_str(b, (char *) content); xmlFree(content); return b; }
void ows_layers_storage_fill(ows * o) { PGresult *res, *res_g; ows_layer_node *ln; bool filled; buffer *sql; int i, end; assert(o); assert(o->layers); sql = buffer_init(); buffer_add_str(sql, "SELECT DISTINCT f_table_schema, f_table_name FROM geometry_columns"); res = ows_psql_exec(o, sql->buf); buffer_empty(sql); buffer_add_str(sql, "SELECT DISTINCT f_table_schema, f_table_name FROM geography_columns"); res_g = ows_psql_exec(o, sql->buf); buffer_free(sql); for (ln = o->layers->first ; ln ; ln = ln->next) { filled = false; for (i = 0, end = PQntuples(res); i < end; i++) { if ( buffer_cmp(ln->layer->storage->schema, (char *) PQgetvalue(res, i, 0)) && buffer_cmp(ln->layer->storage->table, (char *) PQgetvalue(res, i, 1))) { ows_layer_storage_fill(o, ln->layer, true); filled = true; } } for (i = 0, end = PQntuples(res_g); i < end; i++) { if ( buffer_cmp(ln->layer->storage->schema, (char *) PQgetvalue(res_g, i, 0)) && buffer_cmp(ln->layer->storage->table, (char *) PQgetvalue(res_g, i, 1))) { ows_layer_storage_fill(o, ln->layer, false); filled = true; } } if (!filled) { if (ln->layer->storage) ows_layer_storage_free(ln->layer->storage); ln->layer->storage = NULL; } } PQclear(res); PQclear(res_g); }
/* * Copy data from a buffer to an another */ void buffer_copy(buffer * dest, const buffer * src) { assert(dest); assert(src); buffer_add_str(dest, src->buf); }
/* * Add a given buffer to the end of a list * Careful buffer is passed by reference, * and must be free with list_free() */ void list_add_str(list * l, char *value) { list_node *ln; assert(l); assert(value); assert(l->size < UINT_MAX); ln = list_node_init(); ln->value = buffer_init(); buffer_add_str(ln->value, value); if (!l->first) { ln->prev = NULL; l->first = ln; } else { ln->prev = l->last; l->last->next = ln; } l->last = ln; l->last->next = NULL; l->size++; }
/* * Set projection value into srs structure */ bool ows_srs_set(ows * o, ows_srs * c, const buffer * auth_name, int auth_srid) { PGresult *res; buffer *sql; assert(o); assert(c); assert(o->pg); assert(auth_name); sql = buffer_init(); buffer_add_str(sql, "SELECT srid, position('+units=m ' in proj4text)"); buffer_add_str(sql, ", (position('AXIS[\"X\",NORTH]]' in srtext) + position('AXIS[\"Northing\",NORTH]]' in srtext))"); buffer_add_str(sql, " FROM spatial_ref_sys WHERE auth_name='"); buffer_copy(sql, auth_name); buffer_add_str(sql, "' AND auth_srid="); buffer_add_int(sql, auth_srid); res = ows_psql_exec(o, sql->buf); buffer_free(sql); /* If query dont return exactly 1 result, it means projection is not handled */ if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return false; } buffer_empty(c->auth_name); buffer_copy(c->auth_name, auth_name); c->auth_srid = auth_srid; c->srid = atoi(PQgetvalue(res, 0, 0)); /* Such a way to know if units is meter or degree */ if (atoi(PQgetvalue(res, 0, 1)) == 0) c->is_degree = true; else c->is_degree = false; /* Is easting-northing SRID ? */ if (atoi(PQgetvalue(res, 0, 2)) != 0) c->is_eastern_axis = true; PQclear(res); return true; }
bool SSLConnection::negotiate () { int err; const char *errmsg; buffer_t msg; buffer_init(&msg); #if OPENSSL_VERSION_NUMBER >= 0x00906000L /* This only exists in 0.9.6 and above. Without it we may get interrupted * reads or writes. Bummer. */ SSL_set_mode (ssl, SSL_MODE_AUTO_RETRY); #endif if ((err = SSL_connect (ssl)) != 1) { switch (SSL_get_error (ssl, err)) { case SSL_ERROR_SYSCALL: errmsg = _("I/O error"); break; case SSL_ERROR_SSL: errmsg = ERR_error_string (ERR_get_error (), NULL); break; default: errmsg = _("unknown error"); } buffer_shrink(&msg,0); buffer_add_str(&msg,(_("OpenSSL's connect() failed: ")),-1); buffer_add_str(&msg,errmsg,-1); displayError.emit(&msg); buffer_free(&msg); return false; } if (!(cert = SSL_get_peer_certificate (ssl))) { buffer_shrink(&msg,0); buffer_add_str(&msg,_("Unable to get certificate from peer"),-1); displayError.emit(&msg); buffer_free(&msg); return false; } if (!checkCert()) return false; return true; }
/* * Describe functions supported by the wfs */ static void fe_functions_capabilities(const ows * o) { int version; buffer *fct_name; assert(o); version = ows_version_get(o->request->version); fct_name = buffer_init(); if (version == 100) buffer_add_str(fct_name, "Function_Name"); else buffer_add_str(fct_name, "FunctionName"); fprintf(o->output, " <ogc:Functions>\n"); fprintf(o->output, " <ogc:%ss>\n", fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>abs</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>acos</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>asin</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>atan</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>avg</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>cbrt</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>ceil</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>ceiling</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>cos</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>cot</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>count</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>degrees</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>exp</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>floor</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>length</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>ln</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>log</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>min</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>max</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>radians</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>round</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>sin</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>sqrt</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>tan</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " <ogc:%s nArgs='1'>trunc</ogc:%s>\n", fct_name->buf, fct_name->buf); fprintf(o->output, " </ogc:%ss>\n", fct_name->buf); fprintf(o->output, " </ogc:Functions>\n"); buffer_free(fct_name); }
bool SSLConnection::checkCertDigest() { unsigned char peermd[EVP_MAX_MD_SIZE]; unsigned int peermdlen; X509 *c = NULL; bool pass = false; FILE *fp; buffer_t msg; buffer_init(&msg); /* expiration check */ if (X509_cmp_current_time (X509_get_notBefore (cert)) >= 0) { buffer_shrink(&msg,0); buffer_add_str(&msg,_("Server certificate is not yet valid."),-1); displayError.emit(&msg); buffer_free(&msg); return 0; } if (X509_cmp_current_time (X509_get_notAfter (cert)) <= 0) { buffer_shrink(&msg,0); buffer_add_str(&msg,_("Server certificate has expired."),-1); displayError.emit(&msg); buffer_free(&msg); return 0; } buffer_free(&msg); if ((fp = fopen (SSLCertFile, "rt")) == NULL) return false; if (!X509_digest (cert, EVP_sha1 (), peermd, &peermdlen)) { fclose (fp); return false; } while ((c = READ_X509_KEY (fp, &c)) != NULL) { pass = X509_cmp (c, peermd, peermdlen); if (pass) break; } X509_free(c); fclose (fp); return pass; }
void SSLConnection::init () { did_init = false; buffer_t path; buffer_init(&path); buffer_grow(&path,_POSIX_PATH_MAX+1); if (!HAVE_ENTROPY ()) { /* load entropy from files */ if (SSLEntropyFile) add_entropy (SSLEntropyFile); add_entropy (RAND_file_name (path.str,path.size)); /* load entropy from egd sockets */ #ifdef HAVE_RAND_EGD add_entropy (getenv ("EGDSOCKET")); buffer_shrink(&path,0); buffer_add_str(&path,NONULL(Homedir),-1); buffer_add_str(&path,"/.entropy",9); add_entropy (path.str); add_entropy ("/tmp/entropy"); #endif /* shuffle $RANDFILE (or ~/.rnd if unset) */ RAND_write_file (RAND_file_name (path.str,path.size)); if (!HAVE_ENTROPY ()) { buffer_t msg; buffer_init(&msg); buffer_add_str(&msg,_("Failed to find enough entropy on your system"),-1); displayError.emit(&msg); buffer_free(&msg); buffer_free(&path); return; } } /* * I don't think you can do this just before reading the error. * The call itself might clobber the last SSL error. */ SSL_load_error_strings (); SSL_library_init (); did_init = true; buffer_free(&path); }
/* * 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; }
buffer *buffer_from_str(const char *str) { buffer *b; assert(str); b = buffer_init(); buffer_add_str(b, str); return b; }
bool SSLConnection::getVersion (buffer_t* dst) { if (!dst) return true; buffer_add_str(dst,"openssl ",8); buffer_add_snum(dst,(OPENSSL_VERSION_NUMBER>>28)&0xf,-1);buffer_add_ch(dst,'.'); buffer_add_snum(dst,(OPENSSL_VERSION_NUMBER>>20)&0xff,-1);buffer_add_ch(dst,'.'); buffer_add_snum(dst,(OPENSSL_VERSION_NUMBER>>12)&0xff,-1); buffer_add_ch(dst,pl(((OPENSSL_VERSION_NUMBER>>4)&0xff)%27)); return true; }
/* * Parse the configuration file's metadata element */ static void ows_parse_config_metadata(ows * o, xmlTextReaderPtr r) { xmlChar *a; assert(o); assert(r); o->metadata = ows_metadata_init(); a = xmlTextReaderGetAttribute(r, (xmlChar *) "name"); if (a) { o->metadata->name = buffer_init(); buffer_add_str(o->metadata->name, (char *) a); xmlFree(a); } a = xmlTextReaderGetAttribute(r, (xmlChar *) "title"); if (a) { o->metadata->title = buffer_init(); buffer_add_str(o->metadata->title, (char *) a); xmlFree(a); } a = xmlTextReaderGetAttribute(r, (xmlChar *) "keywords"); if (a) { o->metadata->keywords = list_explode_str(',', (char *) a); xmlFree(a); } a = xmlTextReaderGetAttribute(r, (xmlChar *) "fees"); if (a) { o->metadata->fees = buffer_init(); buffer_add_str(o->metadata->fees, (char *) a); xmlFree(a); } a = xmlTextReaderGetAttribute(r, (xmlChar *) "access_constraints"); if (a) { o->metadata->access_constraints = buffer_init(); buffer_add_str(o->metadata->access_constraints, (char *) a); xmlFree(a); } }
/* * Add to the array : node name and content element */ static array *cgi_add_node(array * arr, xmlNodePtr n) { buffer *key, *val; xmlChar *content; assert(arr); assert(n); key = buffer_init(); val = buffer_init(); buffer_add_str(key, (char *) n->name); content = xmlNodeGetContent(n); buffer_add_str(val, (char *) content); xmlFree(content); array_add(arr, key, val); return arr; }
/* * Add to the array : attribute name and content attribute */ static array *cgi_add_att(array * arr, xmlAttr * att) { buffer *key, *val; xmlChar *content; assert(arr); assert(att); key = buffer_init(); val = buffer_init(); buffer_add_str(key, (char *) att->name); content = xmlNodeGetContent(att->children); buffer_add_str(val, (char *) content); xmlFree(content); array_add(arr, key, val); return arr; }
/* * Returns the column character_maximum_length value from the database * information schema. * Used to return maxLenght constraint in describe feature type request. */ buffer *ows_psql_column_character_maximum_length(ows * o, buffer * column_name, buffer * table_name) { buffer *sql; PGresult *res; buffer *character_maximum_length; character_maximum_length = buffer_init(); assert(o); assert(column_name); assert(table_name); sql = buffer_init(); buffer_add_str(sql, "SELECT character_maximum_length FROM information_schema.columns WHERE table_name = '"); buffer_add_str(sql, table_name->buf); buffer_add_str(sql, "' and column_name = '"); buffer_add_str(sql, column_name->buf); buffer_add_str(sql, "'"); res = ows_psql_exec(o, sql->buf); buffer_free(sql); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return character_maximum_length; } buffer_add_str(character_maximum_length, PQgetvalue(res, 0, 0)); PQclear(res); return character_maximum_length; }
/* * Return the number of rows returned by the specified requests */ int ows_psql_number_features(ows * o, list * from, list * where) { buffer *sql; PGresult *res; list_node *ln_from, *ln_where; int nb; assert(o); assert(from); assert(where); nb = 0; /* checks if from list and where list have the same size */ if (from->size != where->size) return nb; for (ln_from = from->first, ln_where = where->first; ln_from; ln_from = ln_from->next, ln_where = ln_where->next) { sql = buffer_init(); /* execute the request */ buffer_add_str(sql, "SELECT count(*) FROM \""); buffer_copy(sql, ln_from->value); buffer_add_str(sql, "\" "); buffer_copy(sql, ln_where->value); res = ows_psql_exec(o, sql->buf); buffer_free(sql); if (PQresultStatus(res) != PGRES_TUPLES_OK) { PQclear(res); return -1; } nb = nb + atoi(PQgetvalue(res, 0, 0)); PQclear(res); } return nb; }
/* * Returns the constraint name for a table column. * Used to return enumeration constraints in describe feature type request. */ buffer *ows_psql_column_constraint_name(ows * o, buffer * column_name, buffer * table_name) { buffer *sql; PGresult *res; buffer *constraint_name; constraint_name = buffer_init(); assert(o); assert(column_name); assert(table_name); sql = buffer_init(); buffer_add_str(sql, "SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = '"); buffer_add_str(sql, table_name->buf); buffer_add_str(sql, "' AND column_name='"); buffer_add_str(sql, column_name->buf); buffer_add_str(sql, "'"); res = ows_psql_exec(o, sql->buf); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) { PQclear(res); return constraint_name; } buffer_add_str(constraint_name, PQgetvalue(res, 0, 0)); PQclear(res); return constraint_name; }
/* * Parse the configuration file's pg element about connection information */ static void ows_parse_config_pg(ows * o, xmlTextReaderPtr r) { xmlChar *a, *v; assert(o); assert(r); if (xmlTextReaderMoveToFirstAttribute(r) != 1) return; do { a = xmlTextReaderName(r); if ( !strcmp((char *) a, "host") || !strcmp((char *) a, "user") || !strcmp((char *) a, "password") || !strcmp((char *) a, "dbname") || !strcmp((char *) a, "port")) { v = xmlTextReaderValue(r); buffer_add_str(o->pg_dsn, (char *) a); buffer_add_str(o->pg_dsn, "="); buffer_add_str(o->pg_dsn, (char *) v); buffer_add_str(o->pg_dsn, " "); xmlFree(v); } else if (!strcmp((char *) a, "encoding")) { v = xmlTextReaderValue(r); buffer_add_str(o->db_encoding, (char *) v); xmlFree(v); } xmlFree(a); } while (xmlTextReaderMoveToNextAttribute(r) == 1); if (!o->db_encoding->use) buffer_add_str(o->db_encoding, OWS_DEFAULT_DB_ENCODING); }
/* * Modify string to replace encoded characters by their true value * Function originaly written by Assefa * * The replacements performed are: * & -> & * " -> " * < -> < * > -> > */ buffer *buffer_encode_xml_entities_str(const char * str) { buffer *buf; assert(str); buf = buffer_init(); for( /* empty */ ; *str ; str++) { if ((int) *str < 32 && (*str != '\n' && *str != '\r' && *str != ' ')) break; switch(*str) { case '&': buffer_add_str(buf, "&"); break; case '<': buffer_add_str(buf, "<"); break; case '>': buffer_add_str(buf, ">"); break; case '"': buffer_add_str(buf, """); break; case '\'': buffer_add_str(buf, "'"); break; default: buffer_add(buf, *str); } } return buf; }
bool SSLConnection::doOpen() { if (!did_init) return false; ctx = SSL_CTX_new (SSLv23_client_method ()); /* disable SSL protocols as needed */ if (!UseTLS1) { SSL_CTX_set_options (ctx, SSL_OP_NO_TLSv1); } if (!UseSSL3) { SSL_CTX_set_options (ctx, SSL_OP_NO_SSLv3); } if (!UseTLS1 && !UseSSL3) return false; getClientCert (); ssl = SSL_new (ctx); SSL_set_fd (ssl,fd); if (!negotiate ()) return false; int maxbits; ssf = SSL_CIPHER_get_bits (SSL_get_current_cipher (ssl),&maxbits); buffer_t msg; buffer_init(&msg); buffer_add_str(&msg,_("SSL/TLS connection using "),-1); buffer_add_str(&msg,SSL_get_cipher_version(ssl),-1); buffer_add_str(&msg," (",2); buffer_add_str(&msg,SSL_get_cipher_name(ssl),-1); buffer_add_ch(&msg,')'); displayProgress.emit(&msg); buffer_free(&msg); return true; }
/* * Check if a given WKT geometry is or not valid */ bool ows_psql_is_geometry_valid(ows * o, buffer * geom) { buffer *sql; PGresult *res; bool ret = false; assert(o); assert(geom); sql = buffer_init(); buffer_add_str(sql, "SELECT ST_isvalid(ST_geometryfromtext('"); buffer_copy(sql, geom); buffer_add_str(sql, "', -1));"); res = ows_psql_exec(o, sql->buf); buffer_free(sql); if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1 && (char) PQgetvalue(res, 0, 0)[0] == 't') ret = true; PQclear(res); return ret; }
/** get info about host */ static void get_hostinfo() { struct utsname utsname; char* p; buffer_t domain; uname(&utsname); buffer_init(&domain); buffer_init(&Fqdn); OSName = str_dup(utsname.sysname); if ((p = strchr(utsname.nodename,'.'))) { Hostname = str_substrdup(utsname.nodename,p++); buffer_add_str(&domain,p,-1); } else Hostname = str_dup(utsname.nodename); #ifndef LIBMUTTNG_DOMAIN #define LIBMUTTNG_DOMAIN domain.str if (!p && !net_dnsdomainname(&domain)) { Fqdn.size = 2; Fqdn.len = 1; Fqdn.str = (char*)mem_malloc(2); Fqdn.str[0] = '@'; Fqdn.str[1] = '\0'; } else #endif if (*LIBMUTTNG_DOMAIN != '@') { buffer_add_str(&Fqdn,NONULL(Hostname),-1); buffer_add_ch(&Fqdn,'.'); buffer_add_str(&Fqdn,NONULL(LIBMUTTNG_DOMAIN),-1); } else buffer_add_str(&Fqdn,NONULL(Hostname),-1); buffer_free(&domain); }
/** * Detect charset from locale. If it's not possible due to missing * nl_langinfo(), use @c iso-8859-1. * @return Charset */ static const char* get_charset() { #ifdef LIBMUTTNG_HAVE_LANGINFO_CODESET buffer_t tmp; buffer_init(&tmp); buffer_add_str(&tmp,nl_langinfo(CODESET),-1); conv_charset_normal(&tmp); if (tmp.len) str_replace(&Charset,tmp.str); buffer_free(&tmp); #else Charset = str_dup("iso-8859-1"); #endif intl_encoding(Charset); return (const char*)Charset; }
/* * Return SRID from a given geometry */ int ows_psql_geometry_srid(ows *o, const char *geom) { int srid; buffer *sql; PGresult *res; assert(o); assert(o->pg); assert(geom); sql = buffer_from_str("SELECT ST_SRID('"); buffer_add_str(sql, geom); buffer_add_str(sql, "'::geometry)"); res = ows_psql_exec(o, sql->buf); if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) srid = -1; else srid = atoi((char *) PQgetvalue(res, 0, 0)); buffer_free(sql); PQclear(res); return srid; }