Ejemplo n.º 1
0
ezxml_t CMsnProto::oimRecvHdr(const char* service, ezxml_t& tbdy, char*& httphdr)
{
	ezxml_t xmlp = ezxml_new("soap:Envelope");
	ezxml_set_attr(xmlp, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
	ezxml_set_attr(xmlp, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
	ezxml_set_attr(xmlp, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");

	ezxml_t hdr = ezxml_add_child(xmlp, "soap:Header", 0);
	ezxml_t cook = ezxml_add_child(hdr, "PassportCookie", 0);
	ezxml_set_attr(cook, "xmlns", "http://www.hotmail.msn.com/ws/2004/09/oim/rsi");
	ezxml_t tcook = ezxml_add_child(cook, "t", 0);
	ezxml_set_txt(tcook, tAuthToken ? tAuthToken : "");
	ezxml_t pcook = ezxml_add_child(cook, "p", 0);
	ezxml_set_txt(pcook, pAuthToken ? pAuthToken : "");

	ezxml_t bdy = ezxml_add_child(xmlp, "soap:Body", 0);

	tbdy = ezxml_add_child(bdy, service, 0);
	ezxml_set_attr(tbdy, "xmlns", "http://www.hotmail.msn.com/ws/2004/09/oim/rsi");

	size_t hdrsz = mir_strlen(service) + sizeof(mailReqHdr) + 20;
	httphdr = (char*)mir_alloc(hdrsz);

	mir_snprintf(httphdr, hdrsz, mailReqHdr, service);

	return xmlp;
}
Ejemplo n.º 2
0
/* Find boolean attribute matching Name in XML tag Parent and return it if exists.  
Removes attribute from Parent */
extern boolean GetBooleanProperty(INP ezxml_t Parent,
				 INP const char *Name,
				 INP boolean Required,
				 INP boolean default_value)
{
	
	const char * Prop;
	boolean property_value;

	property_value = default_value;
	Prop = FindProperty(Parent, Name, Required);
    if(Prop)
	{
	    if((strcmp(Prop, "false") == 0) ||
			(strcmp(Prop, "FALSE") == 0) ||
			(strcmp(Prop, "False") == 0)) {
			property_value = FALSE;
		} else if ((strcmp(Prop, "true") == 0) ||
			(strcmp(Prop, "TRUE") == 0) ||
			(strcmp(Prop, "True") == 0)) {
			property_value = TRUE;
		} else {
			printf(ERRTAG "[LINE %d] Unknown value %s for boolean attribute %s in %s", Parent->line,
				Prop, Name, Parent->name);
			exit(1);
		}
	    ezxml_set_attr(Parent, Name, NULL);
	}
	return property_value;
}
Ejemplo n.º 3
0
static ezxml_t _wmts_operations_metadata(mapcache_context *ctx, const char *onlineresource, const char *operationstr)
{
  ezxml_t http;
  ezxml_t dcp;
  ezxml_t get;
  ezxml_t constraint;
  ezxml_t allowedvalues;
  ezxml_t operation = ezxml_new("ows:Operation");
  ezxml_set_attr(operation,"name",operationstr);
  dcp = ezxml_add_child(operation,"ows:DCP",0);
  http = ezxml_add_child(dcp,"ows:HTTP",0);
  get = ezxml_add_child(http,"ows:Get",0);
  ezxml_set_attr(get,"xlink:href",apr_pstrcat(ctx->pool,onlineresource,"wmts?",NULL));
  constraint = ezxml_add_child(get,"ows:Constraint",0);
  ezxml_set_attr(constraint,"name","GetEncoding");
  allowedvalues = ezxml_add_child(constraint,"ows:AllowedValues",0);
  ezxml_set_txt(ezxml_add_child(allowedvalues,"ows:Value",0),"KVP");
  return operation;

}
Ejemplo n.º 4
0
static ezxml_t _wmts_capabilities(mapcache_context *ctx, mapcache_cfg *cfg)
{
  char *schemaLocation = "http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd";

  ezxml_t node = ezxml_new("Capabilities");
  ezxml_set_attr(node,"xmlns","http://www.opengis.net/wmts/1.0");
  ezxml_set_attr(node,"xmlns:ows","http://www.opengis.net/ows/1.1");
  ezxml_set_attr(node,"xmlns:xlink","http://www.w3.org/1999/xlink");
  ezxml_set_attr(node,"xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
  ezxml_set_attr(node,"xmlns:gml","http://www.opengis.net/gml");

  if( apr_table_get(cfg->metadata,"inspire_profile") ) {
    ezxml_set_attr(node,"xmlns:inspire_common","http://inspire.ec.europa.eu/schemas/common/1.0");
    ezxml_set_attr(node,"xmlns:inspire_vs","http://inspire.ec.europa.eu/schemas/inspire_vs_ows11/1.0");
    schemaLocation = apr_pstrcat(ctx->pool,schemaLocation," http://inspire.ec.europa.eu/schemas/inspire_vs_ows11/1.0 http://inspire.ec.europa.eu/schemas/inspire_vs_ows11/1.0/inspire_vs_ows_11.xsd",NULL);
  }

  ezxml_set_attr(node,"xsi:schemaLocation",schemaLocation);
  ezxml_set_attr(node,"version","1.0.0");

  return node;
}
Ejemplo n.º 5
0
ezxml_t CMsnProto::storeSoapHdr(const char* service, const char* scenario, ezxml_t& tbdy, char*& httphdr)
{
    ezxml_t xmlp = ezxml_new("soap:Envelope");
    ezxml_set_attr(xmlp, "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");
    ezxml_set_attr(xmlp, "xmlns:xsi",  "http://www.w3.org/2001/XMLSchema-instance");
    ezxml_set_attr(xmlp, "xmlns:xsd",  "http://www.w3.org/2001/XMLSchema");
    ezxml_set_attr(xmlp, "xmlns:soapenc", "http://schemas.xmlsoap.org/soap/encoding/");

    ezxml_t hdr = ezxml_add_child(xmlp, "soap:Header", 0);

    if (storageCacheKey)
    {
        ezxml_t cachehdr = ezxml_add_child(hdr, "AffinityCacheHeader", 0);
        ezxml_set_attr(cachehdr, "xmlns", "http://www.msn.com/webservices/storage/2008");
        ezxml_t node = ezxml_add_child(cachehdr, "CacheKey", 0);
        ezxml_set_txt(node, storageCacheKey);
    }

    ezxml_t apphdr = ezxml_add_child(hdr, "StorageApplicationHeader", 0);
    ezxml_set_attr(apphdr, "xmlns", "http://www.msn.com/webservices/storage/2008");
    ezxml_t node = ezxml_add_child(apphdr, "ApplicationID", 0);
    ezxml_set_txt(node, "Messenger Client 9.0");
    node = ezxml_add_child(apphdr, "Scenario", 0);
    ezxml_set_txt(node, scenario);

    ezxml_t authhdr = ezxml_add_child(hdr, "StorageUserHeader", 0);
    ezxml_set_attr(authhdr, "xmlns", "http://www.msn.com/webservices/storage/2008");
    node = ezxml_add_child(authhdr, "Puid", 0);
    ezxml_set_txt(node, mypuid);
    node = ezxml_add_child(authhdr, "TicketToken", 0);
    if (authStorageToken) ezxml_set_txt(node, authStorageToken);

    ezxml_t bdy = ezxml_add_child(xmlp, "soap:Body", 0);

    tbdy = ezxml_add_child(bdy, service, 0);
    ezxml_set_attr(tbdy, "xmlns", "http://www.msn.com/webservices/storage/2008");

    size_t hdrsz = strlen(service) + sizeof(storeReqHdr) + 20;
    httphdr = (char*)mir_alloc(hdrsz);

    mir_snprintf(httphdr, hdrsz, storeReqHdr, service);

    return xmlp;
}
Ejemplo n.º 6
0
/* Find integer attribute matching Name in XML tag Parent and return it if exists.  
Removes attribute from Parent */
extern int GetIntProperty(INP ezxml_t Parent,
				 INP const char *Name,
				 INP boolean Required,
				 INP int default_value)
{
	const char * Prop;
	int property_value;

	property_value = default_value;
	Prop = FindProperty(Parent, Name, Required);
    if(Prop)
	{
	    property_value = my_atoi(Prop);
	    ezxml_set_attr(Parent, Name, NULL);
	}
	return property_value;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
/* Find floating-point attribute matching Name in XML tag Parent and return it if exists.  
Removes attribute from Parent */
extern float GetFloatProperty(INP ezxml_t Parent,
				 INP const char *Name,
				 INP boolean Required,
				 INP float default_value)
{
	
	const char * Prop;
	float property_value;

	property_value = default_value;
	Prop = FindProperty(Parent, Name, Required);
    if(Prop)
	{
	    property_value = atof(Prop);
	    ezxml_set_attr(Parent, Name, NULL);
	}
	return property_value;
}
Ejemplo n.º 9
0
static ezxml_t _wmts_inspire_metadata(mapcache_context *ctx, mapcache_cfg *cfg)
{
  ezxml_t extended = ezxml_new("inspire_vs:ExtendedCapabilities");
  ezxml_t metadata;
  ezxml_t metadataurl;
  ezxml_t metadatatype;
  ezxml_t langsupported;
  ezxml_t langsupporteddefault;
  ezxml_t langsupporteddefaultlang;
  ezxml_t langresponse;
  const char *value;

  metadata = ezxml_add_child(extended,"inspire_common:MetadataUrl",0);
  ezxml_set_attr(metadata,"xsi:type","inspire_common:resourceLocatorType");
  metadataurl = ezxml_add_child(metadata, "inspire_common:URL", 0);

  value = apr_table_get(cfg->metadata, "inspire_metadataurl");
  if(value)
    ezxml_set_txt(metadataurl, value);
 
  metadatatype = ezxml_add_child(metadata, "inspire_common:MediaType", 0);
  ezxml_set_txt(metadatatype, "application/vnd.iso.19139+xml");

  langsupported = ezxml_add_child(extended, "inspire_common:SupportedLanguages", 0);
  langsupporteddefault = ezxml_add_child(langsupported, "inspire_common:DefaultLanguage", 0);
  langsupporteddefaultlang = ezxml_add_child(langsupporteddefault, "inspire_common:Language", 0);

  value = apr_table_get(cfg->metadata, "defaultlanguage");
  if(value)
    ezxml_set_txt(langsupporteddefaultlang, apr_table_get(cfg->metadata, "defaultlanguage"));

  langresponse = ezxml_add_child(extended, "inspire_common:ResponseLanguage", 0);
  apr_table_do(_wmts_inspire_metadata_responselanguages, langresponse, cfg->metadata, "language", NULL);

  return extended;
}
Ejemplo n.º 10
0
static void ___send_test_cmd(struct x_bus *sess, ezxml_t _from)
  {
    ezxml_t _s = NULL;
    ezxml_t __stnz = NULL;
    ezxml_t _stnz1 = NULL;
    ezxml_t _stnz2 = NULL;

    ENTER;

    __stnz = xmpp_stanza_get_root(_from);
    if (!__stnz)
    return;

    _stnz1 = ezxml_new("message");
    _s = _stnz1;
    ezxml_set_attr_d(_s,"to",ezxml_attr(__stnz,"from"));
    ezxml_set_attr(_s, "from", sess->jid);
    //	ezxml_set_attr(_stnz1,"xmlns","http://jabber.org/protocol/feature-neg");

    // add xforms
    _stnz2 = ezxml_add_child(_stnz1, "x",0);
    ezxml_set_attr(_stnz2,"xmlns","jabber:x:data");
    ezxml_set_attr(_stnz2,"type","form");

    _stnz2 = ezxml_add_child(_stnz2, "field",0);
    ezxml_set_attr(_stnz2,"var","fname");
    ezxml_set_attr(_stnz2,"type","text-single");
    ezxml_set_attr(_stnz2,"label","Select filename");

    // ezxml_insert(_stnz1, _s, 0);
    xmpp_session_send_stanza(sess, _s);
    ezxml_free(_s);

    EXIT;

    return;
  }
Ejemplo n.º 11
0
/**
 * \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;

}
void clParserSetAttr(ClParserPtrT xml, const char *name, const char *value)
{
    ezxml_set_attr(xml, name, value);
}
Ejemplo n.º 13
0
/**
 * Reads the transistor properties from the .xml file
 */
void power_tech_load_xml_file(char * cmos_tech_behavior_filepath) {
	ezxml_t cur, child, prev;
	const char * prop;
	char msg[BUFSIZE];

	if (!file_exists(cmos_tech_behavior_filepath)) {
		/* .xml transistor characteristics is missing */
		sprintf(msg,
				"The CMOS technology behavior file ('%s') does not exist.  No power information will be calculated.",
				cmos_tech_behavior_filepath);
		power_log_msg(POWER_LOG_ERROR, msg);

		g_power_tech->NMOS_inf.num_size_entries = 0;
		g_power_tech->NMOS_inf.long_trans_inf = NULL;
		g_power_tech->NMOS_inf.size_inf = NULL;

		g_power_tech->PMOS_inf.num_size_entries = 0;
		g_power_tech->PMOS_inf.long_trans_inf = NULL;
		g_power_tech->PMOS_inf.size_inf = NULL;

		g_power_tech->Vdd = 0.;
		g_power_tech->temperature = 85;
		g_power_tech->PN_ratio = 1.;
		return;
	}
	cur = ezxml_parse_file(cmos_tech_behavior_filepath);

	prop = FindProperty(cur, "file", TRUE);
	ezxml_set_attr(cur, "file", NULL);

	prop = FindProperty(cur, "size", TRUE);
	g_power_tech->tech_size = atof(prop);
	ezxml_set_attr(cur, "size", NULL);

	child = FindElement(cur, "operating_point", TRUE);
	g_power_tech->temperature = GetFloatProperty(child, "temperature", TRUE, 0);
	g_power_tech->Vdd = GetFloatProperty(child, "Vdd", TRUE, 0);
	FreeNode(child);

	child = FindElement(cur, "p_to_n", TRUE);
	g_power_tech->PN_ratio = GetFloatProperty(child, "ratio", TRUE, 0);
	FreeNode(child);

	/* Transistor Information */
	child = FindFirstElement(cur, "transistor", TRUE);
	process_tech_xml_load_transistor_info(child);

	prev = child;
	child = child->next;
	FreeNode(prev);

	process_tech_xml_load_transistor_info(child);
	FreeNode(child);

	/* Multiplexer Voltage Information */
	child = FindElement(cur, "multiplexers", TRUE);
	power_tech_xml_load_multiplexer_info(child);
	FreeNode(child);

	/* Vds Leakage Information */
	child = FindElement(cur, "nmos_leakages", TRUE);
	power_tech_xml_load_nmos_st_leakages(child);
	FreeNode(child);

	/* Buffer SC Info */
	child = FindElement(cur, "buffer_sc", TRUE);
	power_tech_xml_load_sc(child);
	FreeNode(child);

	/* Components */
	child = FindElement(cur, "components", TRUE);
	power_tech_xml_load_components(child);
	FreeNode(child);

	FreeNode(cur);
}
Ejemplo n.º 14
0
bool CMsnProto::MSN_StoreCreateDocument(const TCHAR *sztName, const char *szMimeType, const char *szPicData, bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    char* szName = mir_utf8encodeT(sztName);
    ezxml_t xmlp = storeSoapHdr("CreateDocument", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t hndl = ezxml_add_child(tbdy, "parentHandle", 0);
    ezxml_t node = ezxml_add_child(hndl, "RelationshipName", 0);
    ezxml_set_txt(node, "/UserTiles");

    ezxml_t alias = ezxml_add_child(hndl, "Alias", 0);
    node = ezxml_add_child(alias, "Name", 0);
    ezxml_set_txt(node, mycid);
    node = ezxml_add_child(alias, "NameSpace", 0);
    ezxml_set_txt(node, "MyCidStuff");

    ezxml_t doc = ezxml_add_child(tbdy, "document", 0);
    ezxml_set_attr(doc, "xsi:type", "Photo");
    node = ezxml_add_child(doc, "Name", 0);
    ezxml_set_txt(node, szName);

    doc = ezxml_add_child(doc, "DocumentStreams", 0);
    doc = ezxml_add_child(doc, "DocumentStream", 0);
    ezxml_set_attr(doc, "xsi:type", "PhotoStream");
    node = ezxml_add_child(doc, "DocumentStreamType", 0);

    ezxml_set_txt(node, "UserTileStatic");
    node = ezxml_add_child(doc, "MimeType", 0);
    ezxml_set_txt(node, szMimeType);
    node = ezxml_add_child(doc, "Data", 0);
    ezxml_set_txt(node, szPicData);
    node = ezxml_add_child(doc, "DataSize", 0);
    ezxml_set_txt(node, "0");

    node = ezxml_add_child(tbdy, "relationshipName", 0);
    ezxml_set_txt(node, "Messenger User Tile");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);
    mir_free(szName);

    unsigned status = 0;
    char *storeUrl = NULL, *tResult = NULL;

    for (int k = 4; --k;)
    {
        mir_free(storeUrl);
        storeUrl = GetStoreHost("CreateDocument");
        tResult = getSslResult(&storeUrl, szData, reqHdr, status);
        if (tResult == NULL) UpdateStoreHost("CreateDocument", NULL);
        else break;
    }

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("CreateDocument", storeUrl);
        if (status == 200)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            ezxml_t bdy = getSoapResponse(xmlm, "CreateDocument");
            mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(bdy));
            ezxml_free(xmlm);
        }
        else if (status == 500)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            const char* szErr = ezxml_txt(getSoapFault(xmlm, true));
            if (strcmp(szErr, "PassportAuthFail") == 0 && allowRecurse)
            {
                MSN_GetPassportAuth();
                status = MSN_StoreCreateDocument(sztName, szMimeType, szPicData, false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Ejemplo n.º 15
0
bool CMsnProto::MSN_StoreUpdateDocument(const TCHAR *sztName, const char *szMimeType, const char *szPicData, bool allowRecurse)
{
    char* reqHdr;
    char* szName = mir_utf8encodeT(sztName);
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("UpdateDocument", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t doc = ezxml_add_child(tbdy, "document", 0);
    ezxml_set_attr(doc, "xsi:type", "Photo");
    ezxml_t node = ezxml_add_child(doc, "ResourceID", 0);
    ezxml_set_txt(node, photoid);
    node = ezxml_add_child(doc, "Name", 0);
    ezxml_set_txt(node, szName);

    doc = ezxml_add_child(doc, "DocumentStreams", 0);
    doc = ezxml_add_child(doc, "DocumentStream", 0);
    ezxml_set_attr(doc, "xsi:type", "PhotoStream");

    node = ezxml_add_child(doc, "MimeType", 0);
    ezxml_set_txt(node, szMimeType);
    node = ezxml_add_child(doc, "Data", 0);
    ezxml_set_txt(node, szPicData);
    node = ezxml_add_child(doc, "DataSize", 0);
    ezxml_set_txt(node, "0");
    node = ezxml_add_child(doc, "DocumentStreamType", 0);
    ezxml_set_txt(node, "UserTileStatic");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);
    mir_free(szName);

    unsigned status = 0;
    char *storeUrl = NULL, *tResult = NULL;

    for (int k = 4; --k;)
    {
        mir_free(storeUrl);
        storeUrl = GetStoreHost("UpdateDocument");
        tResult = getSslResult(&storeUrl, szData, reqHdr, status);
        if (tResult == NULL) UpdateStoreHost("UpdateDocument", NULL);
        else break;
    }

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("UpdateDocument", storeUrl);
        if (status == 500 && allowRecurse)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            const char* szErr = ezxml_txt(getSoapFault(xmlm, true));
            if (strcmp(szErr, "PassportAuthFail") == 0)
            {
                MSN_GetPassportAuth();
                status = MSN_StoreUpdateDocument(sztName, szMimeType, szPicData, false) ? 200 : 500;
            }
            else if (szErr[0])
            {
                MSN_StoreDeleteRelationships(true);
                MSN_StoreDeleteRelationships(false);

                MSN_StoreCreateDocument(sztName, szMimeType, szPicData);
                MSN_StoreCreateRelationships();
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Ejemplo n.º 16
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));
      }
    }
Ejemplo n.º 17
0
void _create_capabilities_tms(mapcache_context *ctx, mapcache_request_get_capabilities *req, char *url, char *path_info, mapcache_cfg *cfg) {
  ezxml_t caps;
  char *tmpcaps;
  const char *onlineresource;
   mapcache_request_get_capabilities_tms *request = (mapcache_request_get_capabilities_tms*)req;
#ifdef DEBUG
   if(request->request.request.type != MAPCACHE_REQUEST_GET_CAPABILITIES) {
      ctx->set_error(ctx,500,"wrong tms capabilities request");
      return;
   }
#endif

   onlineresource = apr_table_get(cfg->metadata,"url");
   if(!onlineresource) {
      onlineresource = url;
   }

   request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
   if(!request->version) {
      ezxml_t TileMapService;
      char* serviceurl;
      caps = ezxml_new("Services");
      TileMapService = ezxml_add_child(caps,"TileMapService",0);
      ezxml_set_attr(TileMapService,"version","1.0");
      serviceurl = apr_pstrcat(ctx->pool,onlineresource,"tms/1.0.0/",NULL);
      ezxml_set_attr(TileMapService,"href",serviceurl);
   } else {
      if(!request->tileset) {
         apr_hash_index_t *tileindex_index;
         ezxml_t tilemaps;
         caps = ezxml_new("TileMapService");
         ezxml_set_attr(caps,"version",request->version);
         tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
         tilemaps = ezxml_add_child(caps,"TileMaps",0);
         while(tileindex_index) {
            mapcache_tileset *tileset;
            int j;
            const void *key; apr_ssize_t keylen;
            const char *title;
            apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
            title = apr_table_get(tileset->metadata,"title");
            if(!title) {
               title = "no title set, add some in metadata";
            }
            for(j=0;j<tileset->grid_links->nelts;j++) {
               ezxml_t tilemap;
               char *href;
               mapcache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,j,mapcache_grid_link*)->grid;
               const char *profile = apr_table_get(grid->metadata,"profile");
               if(!profile) profile = "none";
               tilemap = ezxml_add_child(tilemaps,"TileMap",0);
               ezxml_set_attr(tilemap,"title",title);
               ezxml_set_attr(tilemap,"srs",grid->srs);
               if(profile)
                  ezxml_set_attr(tilemap,"profile",profile);
               href = apr_pstrcat(ctx->pool,onlineresource,"tms/1.0.0/",tileset->name,"@",grid->name,NULL);
               ezxml_set_attr(tilemap,"href",href);
            }
            tileindex_index = apr_hash_next(tileindex_index);
         }
      } else {
Ejemplo n.º 18
0
static void
xmlns_si_file_send(struct x_bus *sess, ezxml_t __stnz)
{
  ezxml_t _stnz;
  ezxml_t _s, _s1;
  int status;
  int has_proxy = 0;
  char *proxy = NULL;
  char *myjid = NULL;
  char *myip = NULL;

  ENTER;

  pthread_mutex_lock(&sess->lock);
  myjid = x_strdup(ezxml_attr(sess->dbcore, "jid"));
  _s = ezxml_get(sess->dbcore, "interfaces", 0, "iface", -1);
  myip = x_strdup(ezxml_attr(_s, "addr"));
  pthread_mutex_unlock(&sess->lock);

  _s = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
  if (_s)
    _s = ezxml_child(_s, "job");

  _stnz = ezxml_get(sess->dbcore, "ftproxy", -1);
  proxy = (char *) ezxml_attr(_stnz, "jid");
  if (proxy)
    has_proxy++;

  sscanf(ezxml_attr(_s, "status"), "%d", &status);

  if (status < 2 && has_proxy)
    {
      // _s = xmpp_stanza_get_root(_from);
      // first send request to proxy
      _stnz = ezxml_new("iq");
      ezxml_set_attr(_stnz, "id", "6756756");
      ezxml_set_attr(_stnz, "type", "get");
      ezxml_set_attr(_stnz, "from", myjid);
      ezxml_set_attr_d(_stnz,"to",proxy);

      _s1 = ezxml_add_child(_stnz, "query", 0);
      ezxml_set_attr(_s1, "xmlns", XMLNS_BYTESTREAMS);

    }
  else if (myip)
    {
      _stnz = ezxml_new("iq");
      ezxml_set_attr(_stnz, "id", "6756756");
      ezxml_set_attr(_stnz, "type", "set");
      ezxml_set_attr(_stnz, "from", myjid);
      ezxml_set_attr_d(_stnz,"to",ezxml_attr(_s,"jid"));

      // FIXME Correct random values
      _s1 = ezxml_add_child(_stnz, "query", 0);
      ezxml_set_attr(_s1, "xmlns", XMLNS_BYTESTREAMS);
      ezxml_set_attr(_s1, "mode", "tcp");

      ezxml_set_attr_d(_s1,"sid",ezxml_attr(_s,"id"));

      // FIXME Correct ip
      _s1 = ezxml_add_child(_s1, "streamhost", 0);
      ezxml_set_attr(_s1, "jid", myjid);
      ezxml_set_attr_d(_s1,"host",myip);
      ezxml_set_attr(_s1, "port", "5277");
    }
  else
    {
      /* TODO Clean file atrsnfer job */
      // ERROR
    }

  EXIT;
  xmpp_session_send_stanza(sess, _stnz);
  ezxml_free(_stnz);
  if (myjid)
    free(myjid);
  if (myip)
    free(myip);
  return;
}
Ejemplo n.º 19
0
/**
 * Read the transistor information from the .xml transistor characteristics.
 * For each transistor size, it extracts the:
 * - transistor node capacitances
 * - subthreshold leakage
 * - gate leakage
 */
static void process_tech_xml_load_transistor_info(ezxml_t parent) {
	t_transistor_inf * trans_inf;
	const char * prop;
	ezxml_t child, prev, grandchild;
	int i;

	/* Get transistor type: NMOS or PMOS */
	prop = FindProperty(parent, "type", TRUE);
	if (strcmp(prop, "nmos") == 0) {
		trans_inf = &g_power_tech->NMOS_inf;
	} else if (strcmp(prop, "pmos") == 0) {
		trans_inf = &g_power_tech->PMOS_inf;
	} else {
		assert(0);
	}
	ezxml_set_attr(parent, "type", NULL);

	/* Get long transistor information (W=1,L=2) */
	trans_inf->long_trans_inf = (t_transistor_size_inf*) my_malloc(
			sizeof(t_transistor_size_inf));

	child = FindElement(parent, "long_size", TRUE);
	assert(GetIntProperty(child, "L", TRUE, 0) == 2);
	trans_inf->long_trans_inf->size = GetFloatProperty(child, "W", TRUE, 0);

	grandchild = FindElement(child, "leakage_current", TRUE);
	trans_inf->long_trans_inf->leakage_subthreshold = GetFloatProperty(
			grandchild, "subthreshold", TRUE, 0);
	FreeNode(grandchild);

	grandchild = FindElement(child, "capacitance", TRUE);
	trans_inf->long_trans_inf->C_g = GetFloatProperty(grandchild, "C_g", TRUE,
			0);
	trans_inf->long_trans_inf->C_d = GetFloatProperty(grandchild, "C_d", TRUE,
			0);
	trans_inf->long_trans_inf->C_s = GetFloatProperty(grandchild, "C_s", TRUE,
			0);
	FreeNode(grandchild);

	/* Process all transistor sizes */
	trans_inf->num_size_entries = CountChildren(parent, "size", 1);
	trans_inf->size_inf = (t_transistor_size_inf*) my_calloc(
			trans_inf->num_size_entries, sizeof(t_transistor_size_inf));
	FreeNode(child);

	child = FindFirstElement(parent, "size", TRUE);
	i = 0;
	while (child) {
		assert(GetIntProperty(child, "L", TRUE, 0) == 1);

		trans_inf->size_inf[i].size = GetFloatProperty(child, "W", TRUE, 0);

		/* Get leakage currents */
		grandchild = FindElement(child, "leakage_current", TRUE);
		trans_inf->size_inf[i].leakage_subthreshold = GetFloatProperty(
				grandchild, "subthreshold", TRUE, 0);
		trans_inf->size_inf[i].leakage_gate = GetFloatProperty(grandchild,
				"gate", TRUE, 0);
		FreeNode(grandchild);

		/* Get node capacitances */
		grandchild = FindElement(child, "capacitance", TRUE);
		trans_inf->size_inf[i].C_g = GetFloatProperty(grandchild, "C_g", TRUE,
				0);
		trans_inf->size_inf[i].C_s = GetFloatProperty(grandchild, "C_s", TRUE,
				0);
		trans_inf->size_inf[i].C_d = GetFloatProperty(grandchild, "C_d", TRUE,
				0);
		FreeNode(grandchild);

		prev = child;
		child = child->next;
		FreeNode(prev);
		i++;
	}
}
Ejemplo n.º 20
0
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;
}
Ejemplo n.º 21
0
void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabilities *req, char *guessed_url, char *path_info, mapcache_cfg *cfg)
{
  ezxml_t caps, tmpxml;
  const char *title;
  const char *url;
  ezxml_t capxml;
  ezxml_t reqxml;
  ezxml_t vendorxml;
  ezxml_t toplayer;
  apr_hash_index_t *grid_index;
  apr_hash_index_t *tileindex_index;
  char *tmpcaps;
  static char *capheader;
  mapcache_request_get_capabilities_wms *request = (mapcache_request_get_capabilities_wms*)req;
#ifdef DEBUG
  if(request->request.request.type != MAPCACHE_REQUEST_GET_CAPABILITIES) {
    ctx->set_error(ctx,400,"wrong wms capabilities request");
    return;
  }
#endif

  url = apr_table_get(cfg->metadata,"url");
  if(!url) {
    url = guessed_url;
  }

  url = apr_pstrcat(ctx->pool,url,req->request.service->url_prefix,"?",NULL);
  caps = ezxml_new("WMT_MS_Capabilities");
  ezxml_set_attr(caps,"version","1.1.1");
  /*
            "<Service>\n"
              "<Name>OGC:WMS</Name>\n"
              "<Title>%s</Title>\n"
              "<OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"%s/wms?\"/>\n"
            "</Service>\n"
  */
  tmpxml = ezxml_add_child(caps,"Service",0);
  ezxml_set_txt(ezxml_add_child(tmpxml,"Name",0),"OGC:WMS");
  title = apr_table_get(cfg->metadata,"title");
  if(!title) {
    title = "no title set, add some in metadata";
  }
  ezxml_set_txt(ezxml_add_child(tmpxml,"Title",0),title);
  tmpxml = ezxml_add_child(tmpxml,"OnlineResource",0);
  ezxml_set_attr(tmpxml,"xmlns:xlink","http://www.w3.org/1999/xlink");
  ezxml_set_attr(tmpxml,"xlink:href",url);
  /*

     "<Capability>\n"
     "<Request>\n"
  */
  capxml = ezxml_add_child(caps,"Capability",0);
  reqxml = ezxml_add_child(capxml,"Request",0);
  /*
     "<GetCapabilities>\n"
     " <Format>application/vnd.ogc.wms_xml</Format>\n"
     " <DCPType>\n"
     "  <HTTP>\n"
     "   <Get><OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"%s/wms?\"/></Get>\n"
     "  </HTTP>\n"
     " </DCPType>\n"
     "</GetCapabilities>\n"
     */
  tmpxml = ezxml_add_child(reqxml,"GetCapabilities",0);
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"application/vnd.ogc.wms_xml");
  tmpxml = ezxml_add_child(tmpxml,"DCPType",0);
  tmpxml = ezxml_add_child(tmpxml,"HTTP",0);
  tmpxml = ezxml_add_child(tmpxml,"Get",0);
  tmpxml = ezxml_add_child(tmpxml,"OnlineResource",0);
  ezxml_set_attr(tmpxml,"xmlns:xlink","http://www.w3.org/1999/xlink");
  ezxml_set_attr(tmpxml,"xlink:href",url);

  /*
                "<GetMap>\n"
                  "<Format>image/png</Format>\n"
                  "<Format>image/jpeg</Format>\n"
                  "<DCPType>\n"
                    "<HTTP>\n"
                      "<Get><OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"%s/wms?\"/></Get>\n"
                    "</HTTP>\n"
                  "</DCPType>\n"
                "</GetMap>\n"
  */
  tmpxml = ezxml_add_child(reqxml,"GetMap",0);
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"image/png");
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"image/jpeg");
  tmpxml = ezxml_add_child(tmpxml,"DCPType",0);
  tmpxml = ezxml_add_child(tmpxml,"HTTP",0);
  tmpxml = ezxml_add_child(tmpxml,"Get",0);
  tmpxml = ezxml_add_child(tmpxml,"OnlineResource",0);
  ezxml_set_attr(tmpxml,"xmlns:xlink","http://www.w3.org/1999/xlink");
  ezxml_set_attr(tmpxml,"xlink:href",url);


  /*
                "<GetFeatureInfo>\n"
                  "<Format>text/plain</Format>\n"
                  "<Format>application/vnd.ogc.gml</Format>\n"
                  "<DCPType>\n"
                    "<HTTP>\n"
                      "<Get>\n"
                        "<OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"%s/wms?\" />\n"
                      "</Get>\n"
                    "</HTTP>\n"
                  "</DCPType>\n"
                "</GetFeatureInfo>\n"
  */
  tmpxml = ezxml_add_child(reqxml,"GetFeatureInfo",0);
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"text/plain");
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"application/vnd.ogc.gml");
  tmpxml = ezxml_add_child(tmpxml,"DCPType",0);
  tmpxml = ezxml_add_child(tmpxml,"HTTP",0);
  tmpxml = ezxml_add_child(tmpxml,"Get",0);
  tmpxml = ezxml_add_child(tmpxml,"OnlineResource",0);
  ezxml_set_attr(tmpxml,"xmlns:xlink","http://www.w3.org/1999/xlink");
  ezxml_set_attr(tmpxml,"xlink:href",url);

  /*
              "<Exception>\n"
                "<Format>text/plain</Format>\n"
              "</Exception>\n"
  */

  tmpxml = ezxml_add_child(capxml,"Exceptions",0);
  ezxml_set_txt(ezxml_add_child(tmpxml,"Format",0),"text/plain");

  vendorxml = ezxml_add_child(capxml,"VendorSpecificCapabilities",0);
  toplayer = ezxml_add_child(capxml,"Layer",0);
  tmpxml = ezxml_add_child(toplayer,"Title",0);
  ezxml_set_txt(tmpxml,title);

  /*
   * announce all layer srs's in the root layer. This part of the wms spec we
   * cannot respect with a caching solution, as each tileset can only be served
   * under a specified number of projections.
   *
   * TODO: check for duplicates in gris srs
   */
  grid_index = apr_hash_first(ctx->pool,cfg->grids);
  while(grid_index) {
    const void *key;
    apr_ssize_t keylen;
    mapcache_grid *grid = NULL;
    apr_hash_this(grid_index,&key,&keylen,(void**)&grid);
    ezxml_set_txt(ezxml_add_child(toplayer,"SRS",0),grid->srs);
    grid_index = apr_hash_next(grid_index);
  }


  tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);

  while(tileindex_index) {
    mapcache_tileset *tileset;
    ezxml_t layerxml;
    ezxml_t tsxml;
    const void *key;
    apr_ssize_t keylen;
    const char *title;
    const char *abstract;
    int i;
    apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);

    layerxml = ezxml_add_child(toplayer,"Layer",0);
    ezxml_set_attr(layerxml, "cascaded", "1");
    ezxml_set_attr(layerxml, "queryable", (tileset->source && tileset->source->info_formats)?"1":"0");
    
    ezxml_set_txt(ezxml_add_child(layerxml,"Name",0),tileset->name);
    tsxml = ezxml_add_child(vendorxml, "TileSet",0);

    /*optional layer title*/
    title = apr_table_get(tileset->metadata,"title");
    if(title) {
      ezxml_set_txt(ezxml_add_child(layerxml,"Title",0),title);
    } else {
      ezxml_set_txt(ezxml_add_child(layerxml,"Title",0),tileset->name);
    }

    /*optional layer abstract*/
    abstract = apr_table_get(tileset->metadata,"abstract");
    if(abstract) {
      ezxml_set_txt(ezxml_add_child(layerxml,"Abstract",0),abstract);
    }

    if(tileset->wgs84bbox.minx != tileset->wgs84bbox.maxx) {
      ezxml_t wgsxml = ezxml_add_child(layerxml,"LatLonBoundingBox",0);
      ezxml_set_attr(wgsxml,"minx",apr_psprintf(ctx->pool,"%f",tileset->wgs84bbox.minx));
      ezxml_set_attr(wgsxml,"miny",apr_psprintf(ctx->pool,"%f",tileset->wgs84bbox.miny));
      ezxml_set_attr(wgsxml,"maxx",apr_psprintf(ctx->pool,"%f",tileset->wgs84bbox.maxx));
      ezxml_set_attr(wgsxml,"maxy",apr_psprintf(ctx->pool,"%f",tileset->wgs84bbox.maxy));
    }

    if(tileset->dimensions) {
      for(i=0; i<tileset->dimensions->nelts; i++) {
        const char **value;
        char *dimval;
        mapcache_dimension *dimension = APR_ARRAY_IDX(tileset->dimensions,i,mapcache_dimension*);
        ezxml_t dimxml = ezxml_add_child(layerxml,"Dimension",0);
        ezxml_set_attr(dimxml,"name",dimension->name);
        ezxml_set_attr(dimxml,"default",dimension->default_value);

        if(dimension->unit) {
          ezxml_set_attr(dimxml,"units",dimension->unit);
        }
        value = dimension->print_ogc_formatted_values(ctx,dimension);
        dimval = apr_pstrdup(ctx->pool,*value);
        value++;
        while(*value) {
          dimval = apr_pstrcat(ctx->pool,dimval,",",*value,NULL);
          value++;
        }
        ezxml_set_txt(dimxml,dimval);
      }
    }


    for(i=0; i<tileset->grid_links->nelts; i++) {
      int j;
      ezxml_t bboxxml;
      mapcache_grid_link *gridlink = APR_ARRAY_IDX(tileset->grid_links,i,mapcache_grid_link*);
      mapcache_grid *grid = gridlink->grid;
      mapcache_extent *extent = &(grid->extent);
      if(gridlink->restricted_extent)
        extent = gridlink->restricted_extent;
      bboxxml = ezxml_add_child(layerxml,"BoundingBox",0);
      ezxml_set_attr(bboxxml,"SRS", grid->srs);
      ezxml_set_attr(bboxxml,"minx",apr_psprintf(ctx->pool,"%f",extent->minx));
      ezxml_set_attr(bboxxml,"miny",apr_psprintf(ctx->pool,"%f",extent->miny));
      ezxml_set_attr(bboxxml,"maxx",apr_psprintf(ctx->pool,"%f",extent->maxx));
      ezxml_set_attr(bboxxml,"maxy",apr_psprintf(ctx->pool,"%f",extent->maxy));
      ezxml_set_txt(ezxml_add_child(layerxml,"SRS",0),grid->srs);

      for(j=0; j<gridlink->grid->srs_aliases->nelts; j++) {
        bboxxml = ezxml_add_child(layerxml,"BoundingBox",0);
        ezxml_set_attr(bboxxml,"SRS", APR_ARRAY_IDX(gridlink->grid->srs_aliases,j,char*));
        ezxml_set_attr(bboxxml,"minx",apr_psprintf(ctx->pool,"%f",extent->minx));
        ezxml_set_attr(bboxxml,"miny",apr_psprintf(ctx->pool,"%f",extent->miny));
        ezxml_set_attr(bboxxml,"maxx",apr_psprintf(ctx->pool,"%f",extent->maxx));
        ezxml_set_attr(bboxxml,"maxy",apr_psprintf(ctx->pool,"%f",extent->maxy));
        ezxml_set_txt(ezxml_add_child(layerxml,"SRS",0),APR_ARRAY_IDX(gridlink->grid->srs_aliases,j,char*));
      }


      if(i==0) {
        char *resolutions;
        int i;
        /*wms-c only supports one grid per layer, so we use the first of the tileset's grids */
        ezxml_set_txt(ezxml_add_child(tsxml,"SRS",0),grid->srs);
        tmpxml = ezxml_add_child(tsxml,"BoundingBox",0);
        ezxml_set_attr(tmpxml,"SRS",grid->srs);
        ezxml_set_attr(tmpxml,"minx",apr_psprintf(ctx->pool,"%f",grid->extent.minx));
        ezxml_set_attr(tmpxml,"miny",apr_psprintf(ctx->pool,"%f",grid->extent.miny));
        ezxml_set_attr(tmpxml,"maxx",apr_psprintf(ctx->pool,"%f",grid->extent.maxx));
        ezxml_set_attr(tmpxml,"maxy",apr_psprintf(ctx->pool,"%f",grid->extent.maxy));

        resolutions="";

        for(i=gridlink->minz; i<gridlink->maxz; i++) {
          resolutions = apr_psprintf(ctx->pool,"%s%.20f ",resolutions,grid->levels[i]->resolution);
        }
        ezxml_set_txt(ezxml_add_child(tsxml,"Resolutions",0),resolutions);
        ezxml_set_txt(ezxml_add_child(tsxml,"Width",0),apr_psprintf(ctx->pool,"%d",grid->tile_sx));
        ezxml_set_txt(ezxml_add_child(tsxml,"Height",0),apr_psprintf(ctx->pool,"%d", grid->tile_sy));
      }
    }
    if(tileset->format && tileset->format->mime_type) {
      ezxml_set_txt(ezxml_add_child(tsxml,"Format",0),tileset->format->mime_type);
    } else {
      ezxml_set_txt(ezxml_add_child(tsxml,"Format",0),"image/unknown");
    }
    ezxml_set_txt(ezxml_add_child(tsxml,"Layers",0),tileset->name);
    ezxml_set_txt(ezxml_add_child(tsxml,"Styles",0),"");
    tileindex_index = apr_hash_next(tileindex_index);
  }


  tmpcaps = ezxml_toxml(caps);
  ezxml_free(caps);
  capheader=
    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\
<!DOCTYPE WMT_MS_Capabilities SYSTEM \"http://schemas.opengis.net/wms/1.1.0/capabilities_1_1_0.dtd\"\
[\
 <!ELEMENT VendorSpecificCapabilities EMPTY>\
]>\n";
  request->request.capabilities = apr_pstrcat(ctx->pool,capheader,tmpcaps,NULL);
  free(tmpcaps);
  request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
}
Ejemplo n.º 22
0
int CMsnProto::MSN_SetMyAvatar(const TCHAR* sztFname, void* pData, size_t cbLen)
{
	mir_sha1_ctx sha1ctx;
	BYTE sha1c[MIR_SHA1_HASH_SIZE], sha1d[MIR_SHA1_HASH_SIZE];

	char *szFname = mir_utf8encodeT(sztFname);

	mir_sha1_init(&sha1ctx);
	mir_sha1_append(&sha1ctx, (BYTE*)pData, (int)cbLen);
	mir_sha1_finish(&sha1ctx, sha1d);

	ptrA szSha1d( mir_base64_encode((PBYTE)sha1d, sizeof(sha1d)));

	mir_sha1_init(&sha1ctx);
	ezxml_t xmlp = ezxml_new("msnobj");

	mir_sha1_append(&sha1ctx, (PBYTE)"Creator", 7);
	mir_sha1_append(&sha1ctx, (PBYTE)MyOptions.szEmail, (int)strlen(MyOptions.szEmail));
	ezxml_set_attr(xmlp, "Creator", MyOptions.szEmail);

	char szFileSize[20];
	_ultoa((unsigned)cbLen, szFileSize, 10);
	mir_sha1_append(&sha1ctx, (PBYTE)"Size", 4);
	mir_sha1_append(&sha1ctx, (PBYTE)szFileSize, (int)strlen(szFileSize));
	ezxml_set_attr(xmlp, "Size", szFileSize);

	mir_sha1_append(&sha1ctx, (PBYTE)"Type", 4);
	mir_sha1_append(&sha1ctx, (PBYTE)"3", 1);  // MSN_TYPEID_DISPLAYPICT
	ezxml_set_attr(xmlp, "Type", "3");

	mir_sha1_append(&sha1ctx, (PBYTE)"Location", 8);
	mir_sha1_append(&sha1ctx, (PBYTE)szFname, (int)strlen(szFname));
	ezxml_set_attr(xmlp, "Location", szFname);

	mir_sha1_append(&sha1ctx, (PBYTE)"Friendly", 8);
	mir_sha1_append(&sha1ctx, (PBYTE)"AAA=", 4);
	ezxml_set_attr(xmlp, "Friendly", "AAA=");

	mir_sha1_append(&sha1ctx, (PBYTE)"SHA1D", 5);
	mir_sha1_append(&sha1ctx, (PBYTE)(char*)szSha1d, (int)strlen(szSha1d));
	ezxml_set_attr(xmlp, "SHA1D", szSha1d);

	mir_sha1_finish(&sha1ctx, sha1c);

	ptrA szSha1c( mir_base64_encode((PBYTE)sha1c, sizeof(sha1c)));

	//	ezxml_set_attr(xmlp, "SHA1C", szSha1c);

	char* szBuffer = ezxml_toxml(xmlp, false);
	ezxml_free(xmlp);
	mir_free(szFname);
	ptrA szEncodedBuffer(mir_urlEncode(szBuffer));
	free(szBuffer);

	const TCHAR *szExt;
	int fmt = ProtoGetBufferFormat(pData, &szExt);
	if (fmt == PA_FORMAT_UNKNOWN)
		return fmt;

	TCHAR szFileName[MAX_PATH];
	MSN_GetAvatarFileName(NULL, szFileName, SIZEOF(szFileName), NULL);
	_tremove(szFileName);

	MSN_GetAvatarFileName(NULL, szFileName, SIZEOF(szFileName), szExt);

	int fileId = _topen(szFileName, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE);
	if (fileId >= 0) {
		_write(fileId, pData, (unsigned)cbLen);
		_close(fileId);

		char szAvatarHashdOld[41] = "";
		db_get_static(NULL, m_szModuleName, "AvatarHash", szAvatarHashdOld, sizeof(szAvatarHashdOld));
		char *szAvatarHash = arrayToHex(sha1d, sizeof(sha1d));
		if (strcmp(szAvatarHashdOld, szAvatarHash)) {
			setString("PictObject", szEncodedBuffer);
			setString("AvatarHash", szAvatarHash);
		}
		mir_free(szAvatarHash);
	}
	else MSN_ShowError("Cannot set avatar. File '%s' could not be created/overwritten", szFileName);

	return fmt;
}