Exemplo n.º 1
0
bool CMsnProto::MSN_StoreCreateRelationships(bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("CreateRelationships", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t rels = ezxml_add_child(tbdy, "relationships", 0);
    ezxml_t rel = ezxml_add_child(rels, "Relationship", 0);
    ezxml_t node = ezxml_add_child(rel, "SourceID", 0);
    ezxml_set_txt(node, expresid);
    node = ezxml_add_child(rel, "SourceType", 0);
    ezxml_set_txt(node, "SubProfile");
    node = ezxml_add_child(rel, "TargetID", 0);
    ezxml_set_txt(node, photoid);
    node = ezxml_add_child(rel, "TargetType", 0);
    ezxml_set_txt(node, "Photo");
    node = ezxml_add_child(rel, "RelationshipName", 0);
    ezxml_set_txt(node, "ProfilePhoto");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

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

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("CreateRelationships", storeUrl);

        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_StoreCreateRelationships(false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 2
0
void CMsnProto::getMetaData(void)
{
	char* getReqHdr;
	ezxml_t reqbdy;
	ezxml_t xmlreq = oimRecvHdr("GetMetadata", reqbdy, getReqHdr);

	char* szData = ezxml_toxml(xmlreq, true);
	ezxml_free(xmlreq);

	unsigned status;
	char* url = (char*)mir_strdup(oimRecvUrl);

	char* tResult = getSslResult(&url, szData, getReqHdr, status);

	mir_free(url);
	free(szData);
	mir_free(getReqHdr);

	if (tResult != NULL && status == 200) {
		ezxml_t xmlm = ezxml_parse_str(tResult, mir_strlen(tResult));
		ezxml_t xmli = ezxml_get(xmlm, "s:Body", 0, "GetMetadataResponse", 0, "MD", -1);
		if (!xmli)
			xmli = ezxml_get(xmlm, "soap:Body", 0, "GetMetadataResponse", 0, "MD", -1);

		getOIMs(xmli);
		ezxml_free(xmlm);
	}
	mir_free(tResult);
}
Exemplo n.º 3
0
int	main(int argc, char* argv[])
{
	int i;

	if((EzxmlBase = OpenLibrary("ezxml.library", 8)))
	{
		ezxml_t xml;
		char *s;

		if (argc != 2) return Printf("usage: %s xmlfile\n", argv[0]);

		xml = ezxml_parse_file(argv[1]);
		Printf("%s\n", (s = ezxml_toxml(xml)));
		FreeVec(s);
		i = Printf("%s", ezxml_error(xml));

		ezxml_free(xml);

		CloseLibrary(EzxmlBase);
	}
	else
		PutStr("Error: Could not open ezxml.library\n");

	return (i) ? 1 : 0;
}
Exemplo n.º 4
0
bool CMsnProto::MSN_StoreCreateProfile(bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("CreateProfile", "RoamingSeed", tbdy, reqHdr);

    ezxml_t pro = ezxml_add_child(tbdy, "profile", 0);
    ezxml_t node;

    pro = ezxml_add_child(pro, "ExpressionProfile", 0);
    ezxml_add_child(pro, "PersonalStatus", 0);
    node = ezxml_add_child(pro, "RoleDefinitionName", 0);
    ezxml_set_txt(node, "ExpressionProfileDefault");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

    storeUrl = mir_strdup("https://storage.msn.com/storageservice/SchematizedStore.asmx");
    tResult = getSslResult(&storeUrl, szData, reqHdr, status);

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        if (status == 200)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            UpdateStoreCacheKey(xmlm);
            ezxml_t body = getSoapResponse(xmlm, "CreateProfile");

            MSN_StoreShareItem(ezxml_txt(body));
            MSN_SharingMyProfile();

            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_StoreCreateProfile(false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
bool CMsnProto::MSN_StoreShareItem(const char* id, bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("ShareItem", "RoamingSeed", tbdy, reqHdr);

    ezxml_t node = ezxml_add_child(tbdy, "resourceID", 0);
    ezxml_set_txt(node, id);
    node = ezxml_add_child(tbdy, "displayName", 0);
    ezxml_set_txt(node, "Messenger Roaming Identity");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

    storeUrl = mir_strdup("https://storage.msn.com/storageservice/SchematizedStore.asmx");
    tResult = getSslResult(&storeUrl, szData, reqHdr, status);

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL && 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_StoreCreateProfile(false) ? 200 : 500;
        }
        ezxml_free(xmlm);
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 7
0
/* ------------------------------------------------------------------------- */
static int TxMessage(TServant *const servant, const ezxml_t message)
{
    char* str;
    size_t len;
    TTxControl *const ctrl = &servant->m_tx;

    str = ezxml_toxml(message, false);
    if (!str)
        return -EXIT_FAILURE;
    len = strlen(str);
#if 1 /* workaround - it inserts the header */
    {
        char* tmp;

        tmp = malloc(len + MESSAGE_HEADER_LEN);
        if (!tmp)
        {
            free(str);
            return -EXIT_FAILURE;
        }
        memcpy(&tmp[MESSAGE_HEADER_LEN], str, len);
        free(str);

        tmp[0] = (len & 0xFF00) >> 8;
        tmp[1] = len & 0x00FF;

        str = tmp;
        len += MESSAGE_HEADER_LEN;
    }
#endif

    IoBuffer_Free(&ctrl->m_buffer);
    IoBuffer_TakeOwnership(&ctrl->m_buffer, str, len);
    ctrl->m_n_to_send = len;
    if (StartTx(servant))
        return -EXIT_FAILURE;

    return -EXIT_SUCCESS;
}
Exemplo n.º 8
0
/* ------------------------------------------------------------------------- */
int Reg_ExportToFile(Reg_TRegistry* reg, const char* file_name)
{
    char *xml;
    FILE *file;

    assert(reg);

    file = fopen(file_name, "w");
    if (!file)
        return -EXIT_FAILURE;

    xml = ezxml_toxml(reg->m_root, true);
    if (!xml)
    {
        fclose(file);
        return -EXIT_FAILURE;
    }
    fputs(xml, file);
    free(xml);

    fclose(file);
    return -EXIT_SUCCESS;
}
Exemplo n.º 9
0
bool CMsnProto::MSN_StoreDeleteRelationships(bool tile, bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("DeleteRelationships", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t srch = ezxml_add_child(tbdy, "sourceHandle", 0);

    ezxml_t node;
    if (tile)
    {
        node = ezxml_add_child(srch, "RelationshipName", 0);
        ezxml_set_txt(node, "/UserTiles");

        ezxml_t alias = ezxml_add_child(srch, "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");
    }
    else
    {
        node = ezxml_add_child(srch, "ResourceID", 0);
        ezxml_set_txt(node, expresid);
    }

    node = ezxml_add_child(tbdy, "targetHandles", 0);
    node = ezxml_add_child(node, "ObjectHandle", 0);
    node = ezxml_add_child(node, "ResourceID", 0);
    ezxml_set_txt(node, photoid);

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

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

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("DeleteRelationships", storeUrl);
        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_StoreDeleteRelationships(tile, false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 10
0
/* ------------------------------------------------------------------------- */
int main(int argc, char* argv[])
{
    int ret;
    ezxml_t xml;
    bool retrieve;
    TMessage message;
    int connection;

    if (argc < 2)
    {
        printf("usage: %s <xml file>\n", argv[0]);
        return -EXIT_FAILURE;
    }

    xml = ezxml_parse_file(argv[1]);
    if (!xml)
    {
        printf("Failed to parse the file '%s'.\n", argv[1]);
        return -EXIT_FAILURE;
    }
    message.m_body = ezxml_toxml(xml, false);
    message.m_len = strlen(message.m_body);
    {
        const char *const name = ezxml_name(xml);
        retrieve = (0 == strcmp("retrieve", name));
    }
    ezxml_free(xml);


    ret = -EXIT_FAILURE;
    do
    {
        if (-1 == (connection = Connect(SERVER_IP, SERVER_PORT)))
            break;

        if (SendMessage(connection, &message))
        {
            printf("Failed to send the message.\n");
            break;
        }

        if (!retrieve)
        {
            ret = -EXIT_SUCCESS;
            break;
        }

        if (ReceiveMessage(connection, &message))
        {
            printf("Failed to receive the reply message.\n");
            break;
        }

        xml = ezxml_parse_str(message.m_body, message.m_len);
        if (xml)
        {
            const char *const str = ezxml_toxml(xml, true);
            if (str)
            {
                puts(str);
                free((char*)str);
            }
            ezxml_free(xml);
        }
        else
        {
            printf("Failed to parse the reply message.\n");
            break;
        }

        ret = -EXIT_SUCCESS;
    } while(0);

    free(message.m_body);
    close(connection);
    return ret;
}
char *clParserToXml(ClParserPtrT xml)
{
    return ezxml_toxml(xml);
}
Exemplo n.º 12
0
Arquivo: cgi_user.c Projeto: LinLL/ipc
int CGI_user_set_password(HTTPD_SESSION_t* http_session)
{
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC(""), av_content = AVC("");
	USRM_I_KNOW_U_t* i_m = NULL;
	bool checkin_success = false;
	bool set_success = false;
	ezxml_t output_xml = NULL;
	char* response_xml = NULL;
	
	char query_string[2048] = {""};
	
	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, &av_content);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		ezxml_t input_xml = NULL;
		checkin_success = true;

		APP_TRACE("Login success! Query string = \"%s\"", query_string);

		input_xml = ezxml_parse_str(av_content.av_val, av_content.av_len);
		if(input_xml){
			USRM_HOW_ABOUT_t how_about = USRM_GREAT;
			ezxml_t add_node = ezxml_child(input_xml, "set_pass");
			if(add_node){
				const char* attr_old_pass = ezxml_attr(add_node, "old_pass");
				const char* attr_new_pass = ezxml_attr(add_node, "new_pass");

				how_about = i_m->set_password(i_m, attr_old_pass, attr_new_pass);
				if(USRM_GREAT == how_about){
					set_success = true;
					APP_TRACE("Set user \"%s\" password success!", AVAL_STRDUPA(av_username));
					USRM_store();
				}else{
					// FIXME:
				}
			}

			ezxml_free(input_xml);
			input_xml = NULL;
		}

		// check out
		USRM_logout(i_m);
		i_m = NULL;
	}

	// make the xml content
	output_xml = ezxml_new_d("user");
	ezxml_set_attr_d(output_xml, "ver", CGI_USER_VERSION);
	ezxml_set_attr_d(output_xml, "you", AVAL_STRDUPA(av_username));
	ezxml_set_attr_d(output_xml, "ret", "success");
	if(!STR_CASE_THE_SAME(ezxml_attr(output_xml, "ret"), "success")){
		ezxml_set_attr_d(output_xml, "mesg", "");
	}
	response_xml = ezxml_toxml(output_xml);
	ezxml_free(output_xml);
	output_xml = NULL;

	// response
	cgi_user_http_response(http_session, response_xml);
	
	free(output_xml);
	output_xml = NULL;
	
	return 0;
}
Exemplo n.º 13
0
Arquivo: cgi_user.c Projeto: LinLL/ipc
int CGI_edit_user(HTTPD_SESSION_t* http_session)
{
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC(""), av_content = AVC("");

	USRM_I_KNOW_U_t* i_m = NULL;
	bool check_in = false;
	bool add_success = false;
	ezxml_t output_xml = NULL;
	const char* xml_text = NULL;

	char query_string[2048] = {""};

	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, &av_content);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		ezxml_t input_xml = NULL;
		ezxml_t add_node = NULL;

		APP_TRACE("Login success! Query string = \"%s\"", query_string);
		
		// check in success
		check_in = true;

		input_xml = ezxml_parse_str(av_content.av_val, av_content.av_len);
		if(input_xml){
			USRM_HOW_ABOUT_t how_about = USRM_GREAT;
			ezxml_t edit_node = ezxml_child(input_xml, "edit_user");
			if(add_node){
				const char* attr_name = ezxml_attr(edit_node, "name");
				const char* attr_admin = ezxml_attr(edit_node, "admin");
				const char* attr_permit_live = ezxml_attr(edit_node, "permit_live");
				const char* attr_permit_setting = ezxml_attr(edit_node, "permit_setting");
				const char* attr_permit_playback = ezxml_attr(edit_node, "permit_playback");

				bool const is_admin = attr_admin ? (STR_CASE_THE_SAME(attr_admin, "yes")) : false;
				uint32_t permit_flag = 0; // clear flag

				if(attr_permit_live ? (STR_CASE_THE_SAME(attr_permit_live, "permit_live")) : false){
					permit_flag |= USRM_PERMIT_LIVE;
				}
				if(attr_permit_setting ? (STR_CASE_THE_SAME(attr_permit_setting, "permit_setting")) : false){
					permit_flag |= USRM_PERMIT_SETTING;
				}
				if(attr_permit_playback ? (STR_CASE_THE_SAME(attr_permit_playback, "permit_playback")) : false){
					permit_flag |= USRM_PERMIT_PLAYBACK;
				}

				how_about = i_m->edit_user(i_m, attr_name, is_admin, permit_flag);
				if(USRM_GREAT == how_about){
					add_success = true;
					APP_TRACE("Edit user \"%s\" success!", attr_name);
					USRM_store();
				}else{
					// FIXME:

					
				}
			}

			ezxml_free(input_xml);
			input_xml = NULL;
		}

		// check out
		USRM_logout(i_m);
		i_m = NULL;
	}

	// make the xml content
	output_xml = ezxml_new_d("user");
	ezxml_set_attr_d(output_xml, "ver", CGI_USER_VERSION);
	ezxml_set_attr_d(output_xml, "you", AVAL_STRDUPA(av_username));
	ezxml_set_attr_d(output_xml, "ret", "success");
	if(!STR_CASE_THE_SAME(ezxml_attr(output_xml, "ret"), "success")){
		ezxml_set_attr_d(output_xml, "mesg", "");
	}
	xml_text = ezxml_toxml(output_xml);
	ezxml_free(output_xml);
	output_xml = NULL;

	// response
	cgi_user_http_response(http_session, xml_text);
	
	free(output_xml);
	output_xml = NULL;
	
	return 0;
}
Exemplo n.º 14
0
Arquivo: cgi_user.c Projeto: LinLL/ipc
int CGI_user_list(HTTPD_SESSION_t* http_session)
{
	int i = 0;
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC("");
	
	char query_string[2048] = {""};
	
	USRM_I_KNOW_U_t* i_m = NULL;
	ezxml_t user_xml = NULL;
	const char* xml_text = NULL;
	
	int user_backlog = 0;

	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, NULL);

	// xml root node
	user_xml = ezxml_new_d("user");
	ezxml_set_attr_d(user_xml, "ver", CGI_USER_VERSION);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		lpINI_PARSER user_ini = NULL;
		
		// attribute count
		ezxml_set_attr_d(user_xml, "you", i_m->username);
		// attribute 'add user' permit
		ezxml_set_attr_d(user_xml, "add_user", i_m->is_admin ? "yes" : "no");
		
		// open the ini file
		user_ini = OpenIniFile(USR_MANGER_TMP_FILE);
		APP_ASSERT(NULL != user_ini, "File not existed? it's impossible");

		// put the user list to xml
		user_list_xml(i_m, user_xml, user_ini);

		// close the ini file
		CloseIniFile(user_ini);
		user_ini = NULL;

		// add return
		ezxml_set_attr_d(user_xml, "ret", "success");
		ezxml_set_attr_d(user_xml, "mesg", "check in success");

		USRM_logout(i_m);
		i_m = NULL;

	}else{
		// add return
		ezxml_set_attr_d(user_xml, "ret", "sorry");
		ezxml_set_attr_d(user_xml, "mesg", "check in falied");
	
	}

	// make the xml text
	xml_text = ezxml_toxml(user_xml);
	ezxml_free(user_xml);
	user_xml = NULL;

	// response
	cgi_user_http_response(http_session, xml_text);

	// free the xml text
	free(xml_text);
	xml_text = NULL;

	return 0;
}
Exemplo 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;
}
Exemplo n.º 16
0
bool CMsnProto::MSN_StoreFindDocuments(bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("FindDocuments", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t srch = ezxml_add_child(tbdy, "objectHandle", 0);
    ezxml_t node = ezxml_add_child(srch, "RelationshipName", 0);
    ezxml_set_txt(node, "/UserTiles");

    ezxml_t alias = ezxml_add_child(srch, "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, "documentAttributes", 0);
    node = ezxml_add_child(doc, "ResourceID", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(doc, "Name", 0);
    ezxml_set_txt(node, "true");

    doc = ezxml_add_child(tbdy, "documentFilter", 0);
    node = ezxml_add_child(doc, "FilterAttributes", 0);
    ezxml_set_txt(node, "None");

    doc = ezxml_add_child(tbdy, "documentSort", 0);
    node = ezxml_add_child(doc, "SortBy", 0);
    ezxml_set_txt(node, "DateModified");

    doc = ezxml_add_child(tbdy, "findContext", 0);
    node = ezxml_add_child(doc, "FindMethod", 0);
    ezxml_set_txt(node, "Default");
    node = ezxml_add_child(doc, "ChunkSize", 0);
    ezxml_set_txt(node, "25");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

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

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("FindDocuments", storeUrl);
        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_StoreFindDocuments(false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 17
0
/* ------------------------------------------------------------------------- */
char* Reg_Export(Reg_TRegistry* reg, bool pretty)
{
    assert(reg);
    return ezxml_toxml(reg->m_root, pretty);
}
Exemplo n.º 18
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");
}
Exemplo n.º 19
0
void CMsnProto::getOIMs(ezxml_t xmli)
{
	ezxml_t toki = ezxml_child(xmli, "M");
	if (toki == NULL) return;

	char* getReqHdr;
	ezxml_t reqmsg;
	ezxml_t xmlreq = oimRecvHdr("GetMessage", reqmsg, getReqHdr);

	ezxml_t reqmid = ezxml_add_child(reqmsg, "messageId", 0);
	ezxml_t reqmrk = ezxml_add_child(reqmsg, "alsoMarkAsRead", 0);
	ezxml_set_txt(reqmrk, "false");

	char* delReqHdr;
	ezxml_t delmsg;
	ezxml_t xmldel = oimRecvHdr("DeleteMessages", delmsg, delReqHdr);
	ezxml_t delmids = ezxml_add_child(delmsg, "messageIds", 0);

	while (toki != NULL) {
		const char* szId = ezxml_txt(ezxml_child(toki, "I"));
		const char* szEmail = ezxml_txt(ezxml_child(toki, "E"));

		ezxml_set_txt(reqmid, szId);
		char* szData = ezxml_toxml(xmlreq, true);

		unsigned status;
		char* url = (char*)mir_strdup(oimRecvUrl);

		char* tResult = getSslResult(&url, szData, getReqHdr, status);

		free(szData);
		mir_free(url);

		if (tResult != NULL && status == 200) {
			ezxml_t xmlm = ezxml_parse_str(tResult, mir_strlen(tResult));
			ezxml_t body = getSoapResponse(xmlm, "GetMessage");

			MimeHeaders mailInfo;
			const char* mailbody = mailInfo.readFromBuffer((char*)ezxml_txt(body));

			time_t evtm = time(NULL);
			const char* arrTime = mailInfo["X-OriginalArrivalTime"];
			if (arrTime != NULL) {
				char szTime[32], *p;
				txtParseParam(arrTime, "FILETIME", "[", "]", szTime, sizeof(szTime));

				unsigned filetimeLo = strtoul(szTime, &p, 16);
				if (*p == ':') {
					unsigned __int64 filetime = strtoul(p + 1, &p, 16);
					filetime <<= 32;
					filetime |= filetimeLo;
					filetime /= 10000000;
#ifndef __GNUC__
					filetime -= 11644473600ui64;
#else
					filetime -= 11644473600ull;
#endif
					evtm = (time_t)filetime;
				}
			}

			PROTORECVEVENT pre = { 0 };
			pre.szMessage = mailInfo.decodeMailBody((char*)mailbody);
			pre.timestamp = evtm;
			ProtoChainRecvMsg(MSN_HContactFromEmail(szEmail), &pre);
			mir_free(pre.szMessage);

			ezxml_t delmid = ezxml_add_child(delmids, "messageId", 0);
			ezxml_set_txt(delmid, szId);

			ezxml_free(xmlm);
		}
		mir_free(tResult);
		toki = ezxml_next(toki);
	}
	ezxml_free(xmlreq);
	mir_free(getReqHdr);

	if (ezxml_child(delmids, "messageId") != NULL) {
		char* szData = ezxml_toxml(xmldel, true);

		unsigned status;
		char* url = (char*)mir_strdup(oimRecvUrl);

		char* tResult = getSslResult(&url, szData, delReqHdr, status);

		mir_free(url);
		mir_free(tResult);
		free(szData);
	}
	ezxml_free(xmldel);
	mir_free(delReqHdr);
}
Exemplo n.º 20
0
bool CMsnProto::MSN_StoreUpdateProfile(const char* szNick, const char* szStatus, bool lock, bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("UpdateProfile", "RoamingIdentityChanged", tbdy, reqHdr);

    ezxml_t pro = ezxml_add_child(tbdy, "profile", 0);
    ezxml_t node = ezxml_add_child(pro, "ResourceID", 0);
    ezxml_set_txt(node, proresid);

    ezxml_t expro = ezxml_add_child(pro, "ExpressionProfile", 0);
    node = ezxml_add_child(expro, "FreeText", 0);
    ezxml_set_txt(node, "Update");
    if (szNick)
    {
        node = ezxml_add_child(expro, "DisplayName", 0);
        ezxml_set_txt(node, szNick);
    }
    if (szStatus)
    {
        node = ezxml_add_child(expro, "PersonalStatus", 0);
        ezxml_set_txt(node, szStatus);
    }
    node = ezxml_add_child(expro, "Flags", 0);
    ezxml_set_txt(node, lock ? "1" : "0");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

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

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        UpdateStoreHost("UpdateProfile", storeUrl);
        if (status == 200)
        {
            replaceStr(msnLastStatusMsg, szStatus);
            MSN_ABUpdateDynamicItem();
        }
        else 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_StoreUpdateProfile(szNick, szStatus, lock, false) ? 200 : 500;
            }
            ezxml_free(xmlm);
        }
    }

    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 21
0
bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse)
{
    char* reqHdr;
    ezxml_t tbdy;
    ezxml_t xmlp = storeSoapHdr("GetProfile", "Initial", tbdy, reqHdr);

    ezxml_t prohndl = ezxml_add_child(tbdy, "profileHandle", 0);

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

    node = ezxml_add_child(prohndl, "RelationshipName", 0);
    ezxml_set_txt(node, "MyProfile");

    ezxml_t proattr = ezxml_add_child(tbdy, "profileAttributes", 0);
    node = ezxml_add_child(proattr, "ResourceID", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(proattr, "DateModified", 0);
    ezxml_set_txt(node, "true");

    ezxml_t exproattr = ezxml_add_child(proattr, "ExpressionProfileAttributes", 0);
    node = ezxml_add_child(exproattr, "ResourceID", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DateModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DisplayName", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "DisplayNameLastModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "PersonalStatus", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "PersonalStatusLastModified", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "StaticUserTilePublicURL", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "Photo", 0);
    ezxml_set_txt(node, "true");
    node = ezxml_add_child(exproattr, "Flags", 0);
    ezxml_set_txt(node, "true");

    char* szData = ezxml_toxml(xmlp, true);

    ezxml_free(xmlp);

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

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

    mir_free(reqHdr);
    free(szData);

    if (tResult != NULL)
    {
        if (status == 200)
        {
            ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult));
            ezxml_t body = getSoapResponse(xmlm, "GetProfile");

            UpdateStoreHost("GetProfile", body ? storeUrl : NULL);

            mir_snprintf(proresid, sizeof(proresid), "%s", ezxml_txt(ezxml_child(body, "ResourceID")));

            ezxml_t expr = ezxml_child(body, "ExpressionProfile");
            if (expr == NULL)
            {
                MSN_StoreShareItem(proresid);
                MSN_SharingMyProfile();
                if (allowRecurse) MSN_StoreGetProfile(false);
            }
            else
            {
                const char* szNick = ezxml_txt(ezxml_child(expr, "DisplayName"));
                setStringUtf(NULL, "Nick", (char*)szNick);

                const char* szStatus = ezxml_txt(ezxml_child(expr, "PersonalStatus"));
                replaceStr(msnLastStatusMsg, szStatus);

                mir_snprintf(expresid, sizeof(expresid), "%s", ezxml_txt(ezxml_child(expr, "ResourceID")));

                ezxml_t photo = ezxml_child(expr, "Photo");
                mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(ezxml_child(photo, "ResourceID")));

                ezxml_t docstr = ezxml_get(photo, "DocumentStreams", 0, "DocumentStream", -1);
                while (docstr)
                {
                    const char *docname = ezxml_txt(ezxml_child(docstr, "DocumentStreamName"));
                    if (!strcmp(docname, "UserTileStatic"))
                    {
                        getMyAvatarFile(ezxml_txt(ezxml_child(docstr, "PreAuthURL")), _T("miranda_avatar.tmp"));
                        break;
                    }
                    docstr = ezxml_next(docstr);
                }
            }
            ezxml_free(xmlm);
        }
        else 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();
                MSN_StoreGetProfile(false);
            }
            else
            {
                MSN_StoreCreateProfile();
                if (MSN_StoreGetProfile(false)) status = 200;
            }
            ezxml_free(xmlm);
        }
        else
            UpdateStoreHost("GetProfile", NULL);

    }
    mir_free(tResult);
    mir_free(storeUrl);

    return status == 200;
}
Exemplo n.º 22
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;
}
Exemplo n.º 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;
}