// Adds a child tag. off is the offset of the child tag relative to the start // of the parent tag's character content. Returns the child tag. static ezxml_t ezxml_add_child(ezxml_t xml, const char *name, size_t off) { ezxml_t child; if (! xml) return NULL; child = (ezxml_t)memset(malloc(sizeof(struct ezxml)), '\0', sizeof(struct ezxml)); child->name = (char *)name; child->attr = EZXML_NIL; child->txt = ""; return ezxml_insert(child, xml, off); }
static ezxml_t _wmts_service_provider(mapcache_context *ctx, mapcache_cfg *cfg) { const char *value; ezxml_t node = ezxml_new("ows:ServiceProvider"); value = apr_table_get(cfg->metadata,"providername"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:ProviderName",0),value); value = apr_table_get(cfg->metadata,"providerurl"); if(value) ezxml_set_attr(ezxml_add_child(node,"ows:ProviderSite",0),"xlink:href",value); ezxml_insert(_wmts_service_contact(ctx,cfg),node,0); return node; }
static ezxml_t _wmts_service_contact(mapcache_context *ctx, mapcache_cfg *cfg) { const char *value; ezxml_t node = ezxml_new("ows:ServiceContact"); value = apr_table_get(cfg->metadata,"contactname"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:IndividualName",0),value); value = apr_table_get(cfg->metadata,"contactposition"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:PositionName",0),value); ezxml_insert(_wmts_service_contactinfo(ctx,cfg),node,0); return node; }
static ezxml_t _wmts_service_identification(mapcache_context *ctx, mapcache_cfg *cfg) { const char *value; ezxml_t node = ezxml_new("ows:ServiceIdentification"); value = apr_table_get(cfg->metadata,"title"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:Title",0),value); value = apr_table_get(cfg->metadata,"abstract"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:Abstract",0),value); value = apr_table_get(cfg->metadata,"keyword"); if(value) { ezxml_t nodeKeywords = ezxml_new("ows:Keywords"); /* * @todo: cfg->metadata holds only one item named keyword, * adjust configuration_xml.c */ apr_table_do(_wmts_service_identification_keywords, nodeKeywords, cfg->metadata, "keyword", NULL); ezxml_insert(nodeKeywords, node, 0); } ezxml_set_txt(ezxml_add_child(node,"ows:ServiceType",0),"OGC WMTS"); ezxml_set_txt(ezxml_add_child(node,"ows:ServiceTypeVersion",0),"1.0.0"); value = apr_table_get(cfg->metadata,"fees"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:Fees",0),value); value = apr_table_get(cfg->metadata,"accessconstraints"); if(value) ezxml_set_txt(ezxml_add_child(node,"ows:AccessConstraints",0),value); return node; }
/** * \return <si/> response to <si/> request */ static int xmlns_si_file_accept(struct x_bus *sess, ezxml_t __stnz) { char *str; int err; ezxml_t stream_job; ezxml_t _stnz1; ezxml_t _stnz2; char *fname, *siz; ENTER; _stnz1 = ezxml_child(__stnz, "file"); if (!_stnz1) goto ftexception; fname = (char *) ezxml_attr(_stnz1, "name"); siz = (char *) ezxml_attr(_stnz1, "size"); // get features for (_stnz2 = ezxml_get(__stnz, "feature", -1); _stnz2; _stnz2 = ezxml_next(_stnz2)) { str = (char *) ezxml_attr(_stnz2, "xmlns"); if (str && strstr(str, "feature-neg")) break; }; if (!_stnz2) goto ftexception; // find stream-method for (_stnz2 = ezxml_get(_stnz2, "x", 0, "field", -1); _stnz2; _stnz2 = ezxml_next(_stnz2)) { str = (char *) ezxml_attr(_stnz2, "var"); if (str && strstr(str, "stream-method")) break; }; if (!_stnz2) goto ftexception; // get all stream methods for (_stnz2 = ezxml_child(_stnz2, "option"); _stnz2; _stnz2 = ezxml_next(_stnz2)) { _stnz1 = ezxml_child(_stnz2, "value"); if (_stnz1) printf("STREAM: %s\n", _stnz1->txt); if (!strcmp(_stnz1->txt, XMLNS_BYTESTREAMS)) break; }; if (!_stnz2) goto ftexception; /* enter critical section */ pthread_mutex_lock(&sess->lock); // create new file transfer job _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); if (!_stnz2) { _stnz2 = ezxml_child(sess->dbcore, "bytestreams"); _stnz2 = ezxml_add_child(_stnz2, "pending", 0); } err = !_stnz2->child; /* if some pending job already exists */ if (err) { stream_job = ezxml_new("job"); ezxml_set_attr(stream_job, "type", "file-transfer"); ezxml_set_attr_d(stream_job, "id", ezxml_attr(__stnz,"id")); if (ezxml_attr(__stnz, "mime-type")) ezxml_set_attr_d(stream_job, "mime-type", ezxml_attr(__stnz,"mime-type")); ezxml_set_attr_d(stream_job, "profile", ezxml_attr(__stnz,"profile")); ezxml_set_attr_d(stream_job, "name", fname); ezxml_set_attr(stream_job, "source", "remote"); ezxml_set_attr(stream_job, "src_fd", "0"); ezxml_set_attr(stream_job, "dst_fd", "0"); ezxml_set_attr(stream_job, "status", "0"); _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); ezxml_insert(stream_job, _stnz2, 0); /* leave critical section */ pthread_mutex_unlock(&sess->lock); } else { /* leave critical section */ pthread_mutex_unlock(&sess->lock); goto ftexception; } // create si response _stnz1 = ezxml_new("si"); ezxml_set_attr(_stnz1, "xmlns", XMLNS_SI); _stnz2 = ezxml_add_child(_stnz1, "feature", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_FEATURE_NEG); _stnz2 = ezxml_add_child(_stnz2, "x", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_X_DATA); ezxml_set_attr(_stnz2, "type", "submit"); _stnz2 = ezxml_add_child(_stnz2, "field", 0); ezxml_set_attr(_stnz2, "var", "stream-method"); _stnz2 = ezxml_add_child(_stnz2, "value", 0); ezxml_set_txt(_stnz2, XMLNS_BYTESTREAMS); EXIT; xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1); return 0; ftexception: // create si response _stnz1 = ezxml_new("error"); ezxml_set_attr(_stnz1, "code", "400"); ezxml_set_attr_d(_stnz1,"type","cancel"); _stnz2 = ezxml_add_child(_stnz1, "bad-request", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_XMPP_STANZAS); _stnz2 = ezxml_add_child(_stnz1, "no-valid-streams", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_SI); EXIT; xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1); return -1; }
static int xmpp_send_file(struct x_bus *sess, const char *jid, const char *name) { struct stat f_stat; char ts[25]; pthread_t t; ezxml_t stream_job; ezxml_t __stnz; ezxml_t _s1; ezxml_t _s2; char *myjid = NULL; if (stat(name, &f_stat)) return -1; pthread_mutex_lock(&sess->lock); myjid = x_strdup(ezxml_attr(sess->dbcore, "jid")); pthread_mutex_unlock(&sess->lock); __stnz = ezxml_new("iq"); ezxml_set_attr(__stnz, "type", "set"); ezxml_set_attr_d(__stnz,"to",jid); ezxml_set_attr(__stnz, "from", myjid); // TODO Randomize ID ezxml_set_attr(__stnz, "id", "some-id"); _s1 = ezxml_add_child(__stnz, "si", 0); ezxml_set_attr(_s1, "xmlns", XMLNS_SI); sprintf(ts, "s5b_%x", (int) (random() + time(NULL))); ezxml_set_attr_d(_s1,"id",ts); ezxml_set_attr(_s1, "profile", XMLNS_FILE_TRANSFER); _s2 = ezxml_add_child(_s1, "file", 0); ezxml_set_attr(_s2, "xmlns", XMLNS_FILE_TRANSFER); ezxml_set_attr_d(_s2,"name",name); sprintf(ts, "%d", (int) f_stat.st_size); ezxml_set_attr_d(_s2,"size",ts); _s2 = ezxml_add_child(_s1, "feature", 0); ezxml_set_attr(_s2, "xmlns", XMLNS_FEATURE_NEG); _s2 = ezxml_add_child(_s2, "x", 0); ezxml_set_attr(_s2, "xmlns", XMLNS_X_DATA); ezxml_set_attr(_s2, "type", "form"); _s2 = ezxml_add_child(_s2, "field", 0); ezxml_set_attr(_s2, "var", "stream-method"); ezxml_set_attr(_s2, "type", "list-single"); _s2 = ezxml_add_child(_s2, "option", 0); _s2 = ezxml_add_child(_s2, "value", 0); ezxml_set_txt(_s2, XMLNS_BYTESTREAMS); /* enter critical section */ pthread_mutex_lock(&sess->lock); // create new file transfer job // this job should be created and added to // new main event loop _s2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); if (!_s2) { _s2 = ezxml_get(sess->dbcore, "bytestreams", -1); _s2 = ezxml_add_child(_s2, "pending", 0); } _s2 = ezxml_child(_s2, "job"); /* if some pending job already exists */ if (!_s2) { // create new stream job stream_job = ezxml_new("job"); ezxml_set_attr_d(stream_job, "jid", jid); ezxml_set_attr_d(stream_job, "id",ezxml_attr(_s1,"id")); ezxml_set_attr(stream_job, "type", "file-transfer"); ezxml_set_attr(stream_job, "source", "local"); ezxml_set_attr_d(stream_job, "name", name); ezxml_set_attr(stream_job, "src_fd", "0"); ezxml_set_attr(stream_job, "dst_fd", "0"); ezxml_set_attr(stream_job, "status", "0"); _s2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); ezxml_insert(stream_job, _s2, 0); xmpp_stanza2stdout(sess->dbcore); } pthread_mutex_unlock(&sess->lock); // FIXME pthread_create(&t, NULL, sock5srv, (void *) sess); sprintf(ts, "%d", (int) t); pthread_mutex_lock(&sess->lock); _s2 = ezxml_get(sess->dbcore, "threads", -1); if (_s2) { _s2 = ezxml_add_child(_s2, "thread", 0); ezxml_set_attr(_s2, "name", "socks5"); ezxml_set_attr_d(_s2,"id",ts); } pthread_mutex_unlock(&sess->lock); EXIT; xmpp_session_send_stanza(sess, __stnz); ezxml_free(__stnz); if (myjid) free(myjid); return 0; }
void _create_capabilities_wmts(mapcache_context *ctx, mapcache_request_get_capabilities *req, char *url, char *path_info, mapcache_cfg *cfg) { const char *onlineresource; mapcache_request_get_capabilities_wmts *request = (mapcache_request_get_capabilities_wmts*)req; ezxml_t caps; ezxml_t contents; ezxml_t operations_metadata; apr_hash_index_t *layer_index; apr_hash_index_t *grid_index; char *tmpcaps; apr_table_t *requiredGrids = apr_table_make(ctx->pool, apr_hash_count(cfg->grids)); #ifdef DEBUG if(request->request.request.type != MAPCACHE_REQUEST_GET_CAPABILITIES) { ctx->set_error(ctx,500,"wrong wmts capabilities request"); return; } #endif onlineresource = apr_table_get(cfg->metadata,"url"); if(!onlineresource) { onlineresource = url; } request->request.mime_type = apr_pstrdup(ctx->pool,"application/xml"); caps = _wmts_capabilities(ctx,cfg); ezxml_insert(_wmts_service_identification(ctx,cfg),caps,0); ezxml_insert(_wmts_service_provider(ctx,cfg),caps,0); operations_metadata = ezxml_add_child(caps,"ows:OperationsMetadata",0); ezxml_insert(_wmts_operations_metadata(ctx,onlineresource,"GetCapabilities"),operations_metadata,0); ezxml_insert(_wmts_operations_metadata(ctx,onlineresource,"GetTile"),operations_metadata,0); ezxml_insert(_wmts_operations_metadata(ctx,onlineresource,"GetFeatureInfo"),operations_metadata,0); /* @todo: support both, url and embed profile */ if( apr_table_get(cfg->metadata,"inspire_profile") ) ezxml_insert(_wmts_inspire_metadata(ctx,cfg),operations_metadata,0); contents = ezxml_add_child(caps,"Contents",0); layer_index = apr_hash_first(ctx->pool,cfg->tilesets); while(layer_index) { int i; mapcache_tileset *tileset; const void *key; apr_ssize_t keylen; ezxml_t layer; const char *title; const char *abstract; ezxml_t style; char *dimensionstemplate=""; ezxml_t resourceurl; apr_hash_this(layer_index,&key,&keylen,(void**)&tileset); layer = ezxml_add_child(contents,"Layer",0); title = apr_table_get(tileset->metadata,"title"); if(title) { ezxml_set_txt(ezxml_add_child(layer,"ows:Title",0),title); } else { ezxml_set_txt(ezxml_add_child(layer,"ows:Title",0),tileset->name); } abstract = apr_table_get(tileset->metadata,"abstract"); if(abstract) { ezxml_set_txt(ezxml_add_child(layer,"ows:Abstract",0),abstract); } ezxml_set_txt(ezxml_add_child(layer,"ows:Identifier",0),tileset->name); style = ezxml_add_child(layer,"Style",0); ezxml_set_attr(style,"isDefault","true"); ezxml_set_txt(ezxml_add_child(style,"ows:Identifier",0),"default"); if(tileset->format && tileset->format->mime_type) ezxml_set_txt(ezxml_add_child(layer,"Format",0),tileset->format->mime_type); else ezxml_set_txt(ezxml_add_child(layer,"Format",0),"image/unknown"); if(tileset->dimensions) { for(i=0; i<tileset->dimensions->nelts; i++) { const char **values; const char **value; mapcache_dimension *dimension = APR_ARRAY_IDX(tileset->dimensions,i,mapcache_dimension*); ezxml_t dim = ezxml_add_child(layer,"Dimension",0); ezxml_set_txt(ezxml_add_child(dim,"ows:Identifier",0),dimension->name); ezxml_set_txt(ezxml_add_child(dim,"Default",0),dimension->default_value); if(dimension->unit) { ezxml_set_txt(ezxml_add_child(dim,"UOM",0),dimension->unit); } values = dimension->print_ogc_formatted_values(ctx,dimension); value = values; while(*value) { ezxml_set_txt(ezxml_add_child(dim,"Value",0),*value); value++; } dimensionstemplate = apr_pstrcat(ctx->pool,dimensionstemplate,"{",dimension->name,"}/",NULL); } } if(tileset->source && tileset->source->info_formats) { int i; for(i=0; i<tileset->source->info_formats->nelts; i++) { char *iformat = APR_ARRAY_IDX(tileset->source->info_formats,i,char*); ezxml_set_txt(ezxml_add_child(layer,"InfoFormat",0),iformat); } } if(tileset->wgs84bbox.minx != tileset->wgs84bbox.maxx) { ezxml_t bbox = ezxml_add_child(layer,"ows:WGS84BoundingBox",0); ezxml_set_txt(ezxml_add_child(bbox,"ows:LowerCorner",0), apr_psprintf(ctx->pool,"%f %f",tileset->wgs84bbox.minx, tileset->wgs84bbox.miny)); ezxml_set_txt(ezxml_add_child(bbox,"ows:UpperCorner",0), apr_psprintf(ctx->pool,"%f %f",tileset->wgs84bbox.maxx, tileset->wgs84bbox.maxy)); } for(i=0; i<tileset->grid_links->nelts; i++) { mapcache_grid_link *grid_link = APR_ARRAY_IDX(tileset->grid_links,i,mapcache_grid_link*); ezxml_t tmsetlnk = ezxml_add_child(layer,"TileMatrixSetLink",0); ezxml_set_txt(ezxml_add_child(tmsetlnk,"TileMatrixSet",0),grid_link->grid->name); /* * remember TileMatrixSetLinks */ apr_table_setn(requiredGrids, grid_link->grid->name, "true"); if(grid_link->restricted_extent) { ezxml_t limits = ezxml_add_child(tmsetlnk,"TileMatrixSetLimits",0); int j; for(j=0; j<grid_link->grid->nlevels; j++) { ezxml_t matrixlimits = ezxml_add_child(limits,"TileMatrixLimits",0); ezxml_set_txt(ezxml_add_child(matrixlimits,"TileMatrix",0), apr_psprintf(ctx->pool,"%s:%d",grid_link->grid->name,j)); ezxml_set_txt(ezxml_add_child(matrixlimits,"MinTileRow",0), apr_psprintf(ctx->pool,"%d",grid_link->grid_limits[j].minx)); ezxml_set_txt(ezxml_add_child(matrixlimits,"MaxTileRow",0), apr_psprintf(ctx->pool,"%d",grid_link->grid_limits[j].maxx-1)); ezxml_set_txt(ezxml_add_child(matrixlimits,"MinTileCol",0), apr_psprintf(ctx->pool,"%d",grid_link->grid_limits[j].miny)); ezxml_set_txt(ezxml_add_child(matrixlimits,"MaxTileCol",0), apr_psprintf(ctx->pool,"%d",grid_link->grid_limits[j].maxy-1)); } } /* * gaia gis chokes if this is added to the capabilities doc, * so disable it for now * double *gbbox = grid_link->restricted_extent?grid_link->restricted_extent:grid_link->grid->extent; ezxml_t bbox = ezxml_add_child(layer,"ows:BoundingBox",0); ezxml_set_txt(ezxml_add_child(bbox,"ows:LowerCorner",0), apr_psprintf(ctx->pool,"%f %f",gbbox[0], gbbox[1])); ezxml_set_txt(ezxml_add_child(bbox,"ows:UpperCorner",0), apr_psprintf(ctx->pool,"%f %f",gbbox[2], gbbox[3])); ezxml_set_attr(bbox,"crs",mapcache_grid_get_crs(ctx,grid_link->grid)); */ } if(tileset->source && tileset->source->info_formats) { int i; for(i=0; i<tileset->source->info_formats->nelts; i++) { char *iformat = APR_ARRAY_IDX(tileset->source->info_formats,i,char*); ezxml_t resourceurl; resourceurl = ezxml_add_child(layer,"ResourceURL",0); ezxml_set_attr(resourceurl,"format",iformat); ezxml_set_attr(resourceurl,"resourceType","FeatureInfo"); ezxml_set_attr(resourceurl,"template", apr_pstrcat(ctx->pool,onlineresource,"wmts/1.0.0/",tileset->name,"/default/", dimensionstemplate,"{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.",apr_psprintf(ctx->pool,"%d",i),NULL)); } }
static ezxml_t _wmts_service_contactinfo(mapcache_context *ctx, mapcache_cfg *cfg) { const char *value; int addNode = 0; ezxml_t nodeAddress; ezxml_t nodeInfo = ezxml_new("ows:ContactInfo"); ezxml_t nodePhone = ezxml_new("ows:Phone"); value = apr_table_get(cfg->metadata,"contactphone"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodePhone,"ows:Voice",0),value); } value = apr_table_get(cfg->metadata,"contactfacsimile"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodePhone,"ows:Facsimile",0),value); } if( addNode == 1 ) ezxml_insert(nodePhone, nodeInfo, 0); addNode = 0; nodeAddress = ezxml_new("ows:Address"); value = apr_table_get(cfg->metadata,"contactorganization"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:DeliveryPoint",0),value); } value = apr_table_get(cfg->metadata,"contactcity"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:City",0),value); } value = apr_table_get(cfg->metadata,"contactstateorprovince"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:AdministrativeArea",0),value); } value = apr_table_get(cfg->metadata,"contactpostcode"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:PostalCode",0),value); } value = apr_table_get(cfg->metadata,"contactcountry"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:Country",0),value); } value = apr_table_get(cfg->metadata,"contactelectronicmailaddress"); if(value) { addNode = 1; ezxml_set_txt(ezxml_add_child(nodeAddress,"ows:ElectronicMailAddress",0),value); } if( addNode == 1 ) ezxml_insert(nodeAddress, nodeInfo, 0); return nodeInfo; }