Пример #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;
}
Пример #2
0
/* Generate a tag with escaped character content. */
char* xml_gen_tag(char* name, char* content)
{
    ezxml_t tag = ezxml_new(name);
    ezxml_set_txt(tag, content);
    char* ret = ezxml_toxml(tag);
    ezxml_free(tag);

    return ret;
}
Пример #3
0
/* ------------------------------------------------------------------------- */
static ezxml_t CreateTestMessage()
{
    ezxml_t message = ezxml_new("status");
    {
        ezxml_t node = ezxml_add_child_d(message, "temperature", 0);
        ezxml_set_txt_d(node, "10");
    }
    {
        ezxml_t node = ezxml_add_child_d(message, "humidity", 0);
        ezxml_set_txt_d(node, "13");
    }
    return message;
}
Пример #4
0
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;
}
Пример #5
0
/* ------------------------------------------------------------------------- */
Reg_TRegistry* Reg_Create()
{
    Reg_TRegistry *const reg = Mem_Alloc(sizeof(Reg_TRegistry));
    if (!reg)
        return NULL;
    memset(reg, 0, sizeof(*reg));

    if (!(reg->m_root = ezxml_new("registry")))
    {
        Mem_Free(reg);
        return NULL;
    }

    return reg;
}
Пример #6
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;
}
Пример #7
0
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;
}
Пример #8
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;
}
Пример #9
0
/* ------------------------------------------------------------------------- */
Reg_TRegistry* Reg_CreateFromFile(const char* file_name)
{
    Reg_TRegistry *const reg = Mem_Alloc(sizeof(Reg_TRegistry));
    if (!reg)
        return NULL;
    memset(reg, 0, sizeof(*reg));

    reg->m_file_name = strdup(file_name);
    if ((reg->m_root = ezxml_parse_file(file_name)))
        return reg;

    if (!(reg->m_root = ezxml_new("registry")))
    {
        Mem_Free(reg);
        return NULL;
    }

    return reg;
}
Пример #10
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;

}
Пример #11
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;
}
Пример #12
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;
  }
Пример #13
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;
}
Пример #14
0
/* ------------------------------------------------------------------------- */
static int OnMessageReceived(TServant *const servant, ezxml_t message)
{
    int ret = -EXIT_SUCCESS;

#ifdef UNIT_TESTS
    if (g_Servant_OnMessageReceived)
        g_Servant_OnMessageReceived(servant, message);
#endif
    assert(message);

    do
    {
        const char *req;
        const char *error;

        error = ezxml_error(message);
        if ('\0' != error[0])
        {
            LOG2_ERROR("servant", "the session (%u) received an invalid "
                "formated xml message: %s", servant->m_session.m_id, error);
            ret = -EXIT_FAILURE;
            break;
        }


        req = ezxml_name(message);
        LOG2_DEBUG("servant", "the session (%u) received '%s' request",
            servant->m_session.m_id, req);

        if (strcmp(req, "update") == 0)
        {
            if (servant->m_reg)
            {
                if ((ret = Reg_Update(servant->m_reg, message)))
                    LOG2_ERROR("servant", "the session (%u) failed to update "
                        "the registry", servant->m_session.m_id, req);
            }
        }
        else if (strcmp(req, "retrieve") == 0)
        {
            if (servant->m_reg)
            {
                ezxml_t status = ezxml_new("status");
                ret = Reg_Get(servant->m_reg, message, status);
                TxMessage(servant, status);
                ezxml_free(status);

                LOG2_DEBUG("servant", "the session (%u) replied to '%s' request",
                    servant->m_session.m_id, req);
            }
        }
        else
        {
            LOG2_WARNING("servant", "the session (%u) received an undefined "
                "request (%s)", servant->m_session.m_id, req);
            ret = -EXIT_FAILURE;
        }
    } while(0);

    ezxml_free(message);
    return ret;
}
ClParserPtrT clParserNew(const char *name)
{
    return ezxml_new(name);
}
Пример #16
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 {
Пример #17
0
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;
}
Пример #18
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;

}
Пример #19
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;
}
Пример #20
0
  ezxml_insert(_wmts_service_contactinfo(ctx,cfg),node,0);

  return node;
}

static ezxml_t _wmts_service_provider(mapcache_context *ctx, mapcache_cfg *cfg)
{
  const char *value;
=======
{
  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 )
Пример #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");
}
Пример #22
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;
}
Пример #23
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;
}