Example #1
0
void CDropbox::CommandShare(void *arg)
{
	CommandParam *param = (CommandParam*)arg;

	char *path = (char*)param->data;
	if (path == NULL) {
		CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share");
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
		CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());

		return;
	}

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	ptrA encodedPath(mir_utf8encode(path));
	bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0;
	ShareRequest request(token, encodedPath, useShortUrl);
	NLHR_PTR response(request.Send(param->instance->hNetlibConnection));

	if (response == NULL || response->resultCode != HTTP_STATUS_OK) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty()) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	CMStringA link = root.at("url").as_string().c_str();
	ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
	CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
}
Example #2
0
void CDropbox::CommandDelete(void *arg)
{
	CommandParam *param = (CommandParam*)arg;

	char *path = (char*)param->data;
	if (path == NULL) {
		CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete");
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
		CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer());

		return;
	}
	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	ptrA encodedPath(mir_utf8encode(path));
	DeleteRequest request(token, encodedPath);
	NLHR_PTR response(request.Send(param->instance->hNetlibConnection));

	if (response == NULL || response->resultCode != HTTP_STATUS_OK) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty()) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	bool isDeleted = root.at("is_deleted").as_bool();
	CMStringA message(FORMAT, "%s %s", path, !isDeleted ? T2Utf(TranslateT("is not deleted")) : T2Utf(TranslateT("is deleted")));
	ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
	CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
}
Example #3
0
	void OnOk(CCtrlButton*)
	{
		MCONTACT hContact = INVALID_CONTACT_ID;
		switch (m_acs.handleType) {
		case HANDLE_EVENT:
			{
				DBEVENTINFO dbei = { sizeof(dbei) };
				db_event_get(m_acs.hDbEvent, &dbei);
				hContact = (MCONTACT)CallProtoServiceInt(NULL, dbei.szModule, PS_ADDTOLISTBYEVENT, 0, (LPARAM)m_acs.hDbEvent);
			}
			break;

		case HANDLE_SEARCHRESULT:
			hContact = (MCONTACT)CallProtoServiceInt(NULL, m_acs.szProto, PS_ADDTOLIST, 0, (LPARAM)m_acs.psr);
			break;

		case HANDLE_CONTACT:
			hContact = m_acs.hContact;
			break;
		}

		if (hContact == NULL)
			return;

		ptrT szHandle(m_myHandle.GetText());
		if (mir_tstrlen(szHandle))
			db_set_ts(hContact, "CList", "MyHandle", szHandle);

		int item = m_group.GetCurSel();
		if (item > 0)
			CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, m_group.GetItemData(item));

		db_unset(hContact, "CList", "NotOnList");

		if (m_chkAdded.GetState())
			CallContactService(hContact, PSS_ADDED, 0, 0);

		if (m_chkAuth.GetState()) {
			DWORD flags = CallProtoServiceInt(NULL, m_acs.szProto, PS_GETCAPS, PFLAGNUM_4, 0);
			if (flags & PF4_NOCUSTOMAUTH)
				CallContactService(hContact, PSS_AUTHREQUEST, 0, 0);
			else
				CallContactService(hContact, PSS_AUTHREQUEST, 0, ptrT(m_authReq.GetText()));
		}

		if (m_chkOpen.GetState())
			CallService(MS_CLIST_CONTACTDOUBLECLICKED, hContact, 0);
	}
Example #4
0
void CDropbox::SendToContact(MCONTACT hContact, const TCHAR *data)
{
	if (hContact == GetDefaultContact()) {
		char *message = mir_utf8encodeT(data);
		AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, (DWORD)mir_strlen(message), (PBYTE)message);
		return;
	}

	const char *szProto = GetContactProto(hContact);
	if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) {
		ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID"));
		GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE };
		GCEVENT gce = { sizeof(gce), &gcd };
		gce.bIsMe = TRUE;
		gce.dwFlags = GCEF_ADDTOLOG;
		gce.ptszText = mir_tstrdup(data);
		gce.time = time(NULL);
		CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce);
		mir_free((void*)gce.ptszText);
		return;
	}

	char *message = mir_utf8encodeT(data);
	if (CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED)
		AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message);
}
Example #5
0
/*
*	Tread sub to ask protocol to retrieve away message
*/
static void amThreadProc(void *)
{
	Netlib_Logf(NULL, "amThreadProc thread start");

	ClcCacheEntry dnce;
	memset(&dnce, 0, sizeof(dnce));

	while (!MirandaExiting()) {
		MCONTACT hContact = amGetCurrentChain();
		while (hContact) {
			DWORD time = GetTickCount();
			if ((time - amRequestTick) < AMASKPERIOD) {
				SleepEx(AMASKPERIOD - (time - amRequestTick) + 10, TRUE);
				if (MirandaExiting())
					goto LBL_Exit;
			}
			CListSettings_FreeCacheItemData(&dnce);
			dnce.hContact = hContact;
			Sync(CLUI_SyncGetPDNCE, (WPARAM)0, (LPARAM)&dnce);

			HANDLE ACK = 0;
			if (dnce.ApparentMode != ID_STATUS_OFFLINE) //don't ask if contact is always invisible (should be done with protocol)
				ACK = (HANDLE)CallContactService(hContact, PSS_GETAWAYMSG, 0, 0);
			if (!ACK) {
				ACKDATA ack;
				ack.hContact = hContact;
				ack.type = ACKTYPE_AWAYMSG;
				ack.result = ACKRESULT_FAILED;
				if (dnce.m_cache_cszProto)
					ack.szModule = dnce.m_cache_cszProto;
				else
					ack.szModule = NULL;
				ClcDoProtoAck(hContact, &ack);
			}
			CListSettings_FreeCacheItemData(&dnce);
			amRequestTick = time;
			hContact = amGetCurrentChain();
			if (hContact) {
				DWORD i = 0;
				do {
					i++;
					SleepEx(50, TRUE);
				} while (i < AMASKPERIOD / 50 && !MirandaExiting());
			}
			else break;
			if (MirandaExiting())
				goto LBL_Exit;
		}
		WaitForSingleObjectEx(hamProcessEvent, INFINITE, TRUE);
		ResetEvent(hamProcessEvent);
		if (MirandaExiting())
			break;
	}

LBL_Exit:
	g_hAwayMsgThread = NULL;
	Netlib_Logf(NULL, "amThreadProc thread end");
}
Example #6
0
INT_PTR __cdecl CVkProto::SvcAddAsFriend(WPARAM hContact, LPARAM)
{
	debugLogA("CVkProto::SvcAddAsFriend");
	LONG userID = getDword(hContact, "ID", -1);
	if (!IsOnline() || userID == -1 || userID == VK_FEED_USER)
		return 1;
	CallContactService(hContact, PSS_AUTHREQUEST, 0, (LPARAM)TranslateT("Please authorize me to add you to my friend list."));
	return 0;
}
Example #7
0
INT_PTR __cdecl Service_DisableIM(WPARAM wParam,LPARAM lParam) {
//	WPARAM flags = 0;
//	HANDLE hMetaContact = getMetaContact((HANDLE)wParam);
//	if( hMetaContact ) {
//		wParam = (WPARAM)hMetaContact;
//		flags = PREF_METANODB;
//	}
    CallContactService((HANDLE)wParam,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)SIG_DEIN);
    return 1;
}
Example #8
0
INT_PTR CDropbox::ProtoSendMessage(WPARAM, LPARAM lParam)
{
	CCSDATA *pccsd = (CCSDATA*)lParam;

	if (!HasAccessToken())
	{
		ProtoBroadcastAck(MODULE, pccsd->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)"You cannot send messages when you are not authorized.");
		return 0;
	}

	char *szMessage = (char*)pccsd->lParam;
	if (*szMessage == '/')
	{
		// parse commands
		char *sep = strchr(szMessage, ' ');
		if (sep != NULL) *sep = 0;

		struct
		{
			const char *szCommand;
			pThreadFunc pHandler;
		}
		static commands[] =
		{
			{ "help", &CDropbox::CommandHelp },
			{ "content", &CDropbox::CommandContent },
			{ "share", &CDropbox::CommandShare },
			{ "delete", &CDropbox::CommandDelete }
		};

		for (int i = 0; i < _countof(commands); i++)
		{
			if (!mir_strcmp(szMessage+1, commands[i].szCommand))
			{
				ULONG messageId = InterlockedIncrement(&hMessageProcess);

				CommandParam *param = new CommandParam();
				param->instance = this;
				param->hContact = pccsd->hContact;
				param->hProcess = (HANDLE)messageId;
				param->data = (sep ? sep + 1 : NULL);

				mir_forkthread(commands[i].pHandler, param);

				return messageId;
			}
		}
	}

	char help[1024];
	mir_snprintf(help, Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), szMessage);
	CallContactService(GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help);
	return 0;
}
void __cdecl AutoreplyDelayThread(void *_ad)
{ // _ad must be allocated using "new CAutoreplyData()"
	CAutoreplyData *ad = (CAutoreplyData*)_ad;
	_ASSERT(ad && ad->hContact && ad->Reply.GetLen());
	char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ad->hContact, 0);
	if (!szProto)
	{
		_ASSERT(0);
		return;
	}

	int ReplyLen = (ad->Reply.GetLen() + 1) * (sizeof(char) + sizeof(WCHAR));
	PBYTE pBuf = (PBYTE)malloc(ReplyLen);
	memcpy(pBuf, TCHAR2ANSI(ad->Reply), ad->Reply.GetLen() + 1);
	memcpy(pBuf + ad->Reply.GetLen() + 1, ad->Reply, (ad->Reply.GetLen() + 1) * sizeof(WCHAR));
	CallContactService(ad->hContact, ServiceExists(CString(szProto) + PSS_MESSAGE "W") ? (PSS_MESSAGE "W") : PSS_MESSAGE, PREF_UNICODE, (LPARAM)pBuf);

	if (g_AutoreplyOptPage.GetDBValueCopy(IDC_REPLYDLG_LOGREPLY))
	{ // store in the history
		DBEVENTINFO dbeo = {0};
		dbeo.cbSize = sizeof(dbeo);
		dbeo.eventType = EVENTTYPE_MESSAGE;
		dbeo.flags = DBEF_SENT;
		dbeo.szModule = szProto;
		dbeo.timestamp = time(NULL);

		dbeo.cbBlob = ReplyLen;
		dbeo.pBlob = pBuf;

		SleepEx(1000, true); // delay before sending the reply, as we need it to be later than the message we're replying to (without this delay, srmm puts the messages in a wrong order)
		CallService(MS_DB_EVENT_ADD, (WPARAM)ad->hContact, (LPARAM)&dbeo);
	}

	free(pBuf);

/*
	char *utf8Reply = mir_utf8encodeT(ad->Reply); // todo: use this instead of the code above, when 0.7 will be released
	if (g_AutoreplyOptPage.GetDBValueCopy(IDC_REPLYDLG_LOGREPLY))
	{ // store in the history
		DBEVENTINFO dbeo = {0};
		dbeo.cbSize = sizeof(dbeo);
		dbeo.eventType = EVENTTYPE_MESSAGE;
		dbeo.flags = DBEF_SENT | DBEF_UTF;
		dbeo.szModule = szProto;
		dbeo.timestamp = time(NULL);
		dbeo.cbBlob = strlen(utf8Reply);
		dbeo.pBlob = utf8Reply;
		CallService(MS_DB_EVENT_ADD, (WPARAM)ad->hContact, (LPARAM)&dbeo);
	}
	CallContactService(ad->hContact, ServiceExists(CString(szProto) + PSS_MESSAGE "W") ? (PSS_MESSAGE "W") : PSS_MESSAGE, PREF_UTF, (LPARAM)utf8Reply);
	mir_free(utf8Reply);
*/
	delete ad;
}
Example #10
0
INT_PTR __cdecl Service_CreateIM(WPARAM wParam,LPARAM lParam) {
    if (!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)wParam, (LPARAM)szModuleName))
        CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)wParam, (LPARAM)szModuleName);
//	WPARAM flags = 0;
//	HANDLE hMetaContact = getMetaContact((HANDLE)wParam);
//	if( hMetaContact ) {
//		wParam = (WPARAM)hMetaContact;
//		flags = PREF_METANODB;
//	}
    CallContactService((HANDLE)wParam,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)SIG_INIT);
    return 1;
}
int AskStatusMessageThread(HWND hwnd)
{
  DWORD time;
  HANDLE h;
  HANDLE ACK=0;
  pdisplayNameCacheEntry pdnce=NULL;
  h=GetCurrChain(); 
  if (!h) return 0;

  ISTREADSTARTED=1;
  while (h)
  { 
    time=GetTickCount();
    if ((time-RequestTick)<ASKPERIOD)
    {
            SleepEx(ASKPERIOD-(time-RequestTick)+10,TRUE);
            if (Miranda_Terminated()) 
            {
              ISTREADSTARTED=0;
              return 0; 
            }
    }

	{
		pdnce = GetDisplayNameCacheEntry((HANDLE)h);
		if (pdnce->ApparentMode!=ID_STATUS_OFFLINE) //don't ask if contact is always invisible (should be done with protocol)
			ACK=(HANDLE)CallContactService(h,PSS_GETAWAYMSG,0,0);
	}   
    if (!ACK)
    {
      ACKDATA ack;
      ack.hContact=h;
      ack.type=ACKTYPE_AWAYMSG;
      ack.result=ACKRESULT_FAILED;
      if (pdnce)
        ack.szModule=pdnce->szProto;
      else
        ack.szModule=NULL;
      ClcProtoAck((WPARAM)h,(LPARAM) &ack);
    }
    RequestTick=time;
    h=GetCurrChain();
    if (h) SleepEx(ASKPERIOD,TRUE); else break;
    if (Miranda_Terminated()) 
    {
      ISTREADSTARTED=0;
      return 0; 
    }

  }
  ISTREADSTARTED=0;
  return 1;
}
Example #12
0
// отправляет сообщение, если надо то разбивает на части
int splitMessageSend(pUinKey ptr, LPSTR szMsg)
{
	int len = (int)strlen(szMsg);
	int par = (getContactStatus(ptr->hContact) == ID_STATUS_OFFLINE) ? ptr->proto->split_off : ptr->proto->split_on;
	if (par && len > par) {
		int ret;
		LPSTR msg = splitMsg(szMsg, par);
		LPSTR buf = msg;
		while (*buf) {
			len = (int)strlen(buf);
			LPSTR tmp = mir_strdup(buf);
			ret = CallContactService(ptr->hContact, PSS_MESSAGE, (WPARAM)PREF_METANODB, (LPARAM)tmp);
			mir_free(tmp);
			buf += len + 1;
		}
		SAFE_FREE(msg);
		return ret;
	}
	
	return (int)CallContactService(ptr->hContact, PSS_MESSAGE, (WPARAM)PREF_METANODB, (LPARAM)szMsg);
}
Example #13
0
MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, hContact, hDbEvent)
{
	DBEVENTINFO dbei = { sizeof(dbei) };
	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	if (dbei.cbBlob == -1)
		return 0;

	dbei.pBlob = (BYTE*)alloca(dbei.cbBlob);
	db_event_get(hDbEvent, &dbei);

	// if event is in protocol that is not despammed
	if (!ProtoInList(dbei.szModule))
		return 0;

	// event is an auth request
	if (gbHandleAuthReq) {
		if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
			MCONTACT hcntct = DbGetAuthEventContact(&dbei);

			// if request is from unknown or not marked Answered contact
			int a = db_get_b(hcntct, "CList", "NotOnList", 0);
			int b = !db_get_b(hcntct, pluginName, "Answered", 0);

			if (a && b) {
				// ...send message

				if (gbHideContacts)
					db_set_b(hcntct, "CList", "Hidden", 1);
				if (gbSpecialGroup)
					db_set_ws(hcntct, "CList", "Group", gbSpammersGroup.c_str());
				BYTE msg = 1;
				if (gbIgnoreURL) {
					TCHAR* EventText = ReqGetText(&dbei); //else return NULL
					msg = !IsUrlContains(EventText);
					mir_free(EventText);
				}
				if (gbInvisDisable) {
					if (CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
						msg = 0;
					else if (db_get_w(hContact, dbei.szModule, "ApparentMode", 0) == ID_STATUS_OFFLINE)
						msg = 0; //is it useful ?
				}
				if (msg) {
					ptrA buff(mir_utf8encodeW(variables_parse(gbAuthRepl, hcntct).c_str()));
					CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM)buff);
				}
				return 1;
			}
		}
	}
	return 0;
}
// remove all secureim connections on subcontacts
void DeinitMetaContact(HANDLE hContact) {

	HANDLE hMetaContact = isProtoMetaContacts(hContact) ? hContact : getMetaContact(hContact);

	if( hMetaContact ) {
		for(int i=0;i<CallService(MS_MC_GETNUMCONTACTS,(WPARAM)hMetaContact,0);i++) {
			HANDLE hSubContact = (HANDLE)CallService(MS_MC_GETSUBCONTACT,(WPARAM)hMetaContact,(LPARAM)i);
			if( hSubContact && isContactSecured(hSubContact)&SECURED ) {
				CallContactService(hSubContact,PSS_MESSAGE,(WPARAM)PREF_METANODB,(LPARAM)SIG_DEIN);
			}
		}
	}
}
Example #15
0
void CSend::svcSendFileExit()
{
	//szMessage should be encoded as the File followed by the description, the
	//separator being a single nul (\0). If there is no description, do not forget
	//to end the File with two nuls.
	if (m_bSilent) {
		Exit(ACKRESULT_SUCCESS); return;
	}
	if (!m_hContact) {
		Error(LPGENT("%s requires a valid contact!"), m_pszSendTyp);
		Exit(ACKRESULT_FAILED); return;
	}
	mir_freeAndNil(m_szEventMsg);
	char* szFile = mir_t2a(m_pszFile);
	m_cbEventMsg = (DWORD)mir_strlen(szFile) + 2;
	m_szEventMsg = (char*)mir_realloc(m_szEventMsg, (sizeof(char) * m_cbEventMsg));
	memset(m_szEventMsg, 0, (sizeof(char) * m_cbEventMsg));
	mir_strcpy(m_szEventMsg, szFile);
	if (m_pszFileDesc && m_pszFileDesc[0] != NULL) {
		char* temp = mir_t2a(m_pszFileDesc);
		m_cbEventMsg += (DWORD)mir_strlen(temp);
		m_szEventMsg = (char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg);
		mir_strcpy(m_szEventMsg + mir_strlen(szFile) + 1, temp);
		m_szEventMsg[m_cbEventMsg - 1] = 0;
		mir_free(temp);
	}
	mir_free(szFile);

	//create a HookEventObj on ME_PROTO_ACK
	if (!m_hOnSend) {
		m_hOnSend = HookEventObj(ME_PROTO_ACK, OnSend, this);
	}

	// Start miranda PSS_FILE based on mir ver (T)
	TCHAR* ppFile[2] = { 0, 0 };
	TCHAR* pDesc = mir_tstrdup(m_pszFileDesc);
	ppFile[0] = mir_tstrdup(m_pszFile);
	ppFile[1] = NULL;
	m_hSend = (HANDLE)CallContactService(m_hContact, PSS_FILE, (WPARAM)pDesc, (LPARAM)ppFile);
	mir_free(pDesc);
	mir_free(ppFile[0]);

	// check we actually got an ft handle back from the protocol
	if (!m_hSend) {
		Unhook();
		Error(SS_ERR_INIT, m_pszSendTyp);
		Exit(ACKRESULT_FAILED); return;
	}
}
Example #16
0
void __cdecl RefreshUserDetailsWorkerThread(void *param)
{
	ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Starting to refresh user details"), hRefreshUserDetails);
	int delay = db_get_w(NULL, ModuleName, "UpdateDelay", REFRESH_DETAILS_DELAY);
	int res;

	MCONTACT hContact = db_find_first();
	while (hContact != NULL) {
		res = CallContactService(hContact, PSS_GETINFO, 0, 0);
		hContact = db_find_next(hContact);
		if (hContact)
			Sleep(delay); //sleep for a few seconds between requests
	}
	ShowPopupMessage(TranslateT("WhenWasIt"), TranslateT("Done refreshing user details"), hRefreshUserDetails);
}
Example #17
0
void CDropbox::CommandHelp(void *arg)
{
	CommandParam *param = (CommandParam*)arg;

	CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:"));
	help += "\n";
	help += "\"/content [dir]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"dir\" (\"dir\" can be omitted for root folder)"));
	help += "\n";
	help += "\"/share <path>\" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)"));
	help += "\n";
	help += "\"/delete <path>\" \t- "; help += T2Utf(TranslateT("deletes file or folder with specified path (\"path\" is relative from root folder)"));

	ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
	CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer());
}
Example #18
0
void QueryAwayMessage(HWND hWnd, PLUGINDATA *pdp) 
{
	HANDLE hContact = PUGetContact(hWnd);
	char *szProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
	if (szProto) 
	{
		if ((CallProtoService(szProto, PS_GETCAPS,PFLAGNUM_1, 0) & PF1_MODEMSGRECV) &&
			(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(pdp->newStatus))) 
		{
			//The following HookEventMessage will hook the ME_PROTO_ACK event and send a WM_AWAYMSG to hWnd when the hooks get notified.
			pdp->hAwayMsgHook = HookEventMessage(ME_PROTO_ACK, hWnd, WM_AWAYMSG);
			//The following instruction asks Miranda to retrieve the away message and associates a hProcess (handle) to this request. This handle will appear in the ME_PROTO_ACK event.
			pdp->hAwayMsgProcess = (HANDLE)CallContactService(hContact, PSS_GETAWAYMSG, 0, 0);
		}
	}
}
Example #19
0
static int SendChunkW(WCHAR *chunk, HANDLE hContact, char *szSvc, DWORD dwFlags)
{
	BYTE	*pBuf = NULL;
	int		wLen = lstrlenW(chunk), id;
	DWORD	memRequired = (wLen + 1) * sizeof(WCHAR);
	DWORD	codePage = DBGetContactSettingDword(hContact, SRMSGMOD_T, "ANSIcodepage", CP_ACP);
	int		mbcsSize = WideCharToMultiByte(codePage, 0, chunk, -1, (char *)pBuf, 0, 0, 0);

	memRequired += mbcsSize;
	pBuf = (BYTE *)mir_alloc(memRequired);
	WideCharToMultiByte(codePage, 0, chunk, -1, (char *)pBuf, mbcsSize, 0, 0);
	CopyMemory(&pBuf[mbcsSize], chunk, (wLen + 1) * sizeof(WCHAR));
	id = CallContactService(hContact, szSvc, dwFlags, (LPARAM)pBuf);
	mir_free(pBuf);
	return id;
}
Example #20
0
void CDropbox::CommandContent(void *arg)
{
	CommandParam *param = (CommandParam*)arg;

	char *path = (char*)param->data;
	if (path == NULL)
		path = "";

	ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
	ptrA encodedPath(mir_utf8encode(path));
	GetMetadataRequest request(token, encodedPath);
	NLHR_PTR response(request.Send(param->instance->hNetlibConnection));

	if (response == NULL || response->resultCode != HTTP_STATUS_OK) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	JSONNode root = JSONNode::parse(response->pData);
	if (root.empty()) {
		ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
		return;
	}

	CMStringA message;
	bool isDir = root.at("is_dir").as_bool();
	if (!isDir)
		message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is file")));
	else {
		JSONNode content = root.at("contents").as_array();
		for (size_t i = 0; i < content.size(); i++) {
			JSONNode item = content[i];
			if (item.empty()) {
				if (i == 0)
					message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is empty")));
				break;
			}

			CMStringA subName(item.at("path").as_string().c_str());
			message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName);
		}
	}

	ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
	CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
}
Example #21
0
MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
{
	UNREFERENCED_PARAMETER(wParam);
	MEVENT hDbEvent = (MEVENT)lParam;

	DBEVENTINFO dbei = { 0 };
	dbei.cbSize = sizeof(dbei);
	dbei.cbBlob = db_event_getBlobSize(hDbEvent);
	if (-1 == dbei.cbBlob)
		return 0;

	mir_ptr<BYTE> blob((LPBYTE)mir_alloc(dbei.cbBlob));
	dbei.pBlob = blob;
	db_event_get(hDbEvent, &dbei);

	// if event is in protocol that is not despammed
	if (plSets->ProtoDisabled(dbei.szModule))
		return 0;

	// event is an auth request
	if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
		MCONTACT hcntct = DbGetAuthEventContact(&dbei);

		// if request is from unknown or not marked Answered contact
		//and if I don't sent message to this contact
		if (db_get_b(hcntct, "CList", "NotOnList", 0) && !db_get_b(hcntct, pluginName, answeredSetting, 0) && !IsExistMyMessage(hcntct)) {
			if (!plSets->HandleAuthReq.Get()) {
				char *buf = mir_utf8encodeW(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str());
				CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM)buf);
				mir_free(buf);
			}

			// ...send message
			char *AuthRepl = mir_u2a(variables_parse(plSets->AuthRepl.Get(), hcntct).c_str());
			CallProtoService(dbei.szModule, PS_AUTHDENY, hDbEvent, (LPARAM)AuthRepl);
			mir_free(AuthRepl);

			db_set_b(hcntct, "CList", "NotOnList", 1);
			db_set_b(hcntct, "CList", "Hidden", 1);
			if (!plSets->HistLog.Get())
				db_event_delete(0, hDbEvent);
			return 1;
		}
	}
	return 0;
}
Example #22
0
INT_PTR Meta_FileSend(WPARAM wParam, LPARAM lParam)
{
	CCSDATA *ccs = (CCSDATA*)lParam;
	DBCachedContact *cc = CheckMeta(ccs->hContact);
	if (cc == NULL || cc->nDefault == -1)
		return 0;

	MCONTACT hMostOnline = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, PF1_FILESEND);
	if (!hMostOnline)
		return 0;

	char *proto = GetContactProto(hMostOnline);
	if (proto)
		return CallContactService(hMostOnline, PSS_FILE, ccs->wParam, ccs->lParam);

	return 0; // fail
}
Example #23
0
INT_PTR Meta_GetAwayMsg(WPARAM wParam, LPARAM lParam)
{
	CCSDATA *ccs = (CCSDATA*)lParam;
	DBCachedContact *cc = CheckMeta(ccs->hContact);
	if (cc == NULL || cc->nDefault == -1)
		return 0;

	MCONTACT hMostOnline = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_1, PF1_MODEMSGRECV);
	if (!hMostOnline)
		return 0;

	char *proto = GetContactProto(hMostOnline);
	if (!proto)
		return 0;

	ccs->hContact = hMostOnline;
	return CallContactService(ccs->hContact, PSS_GETAWAYMSG, ccs->wParam, ccs->lParam);
}
Example #24
0
int TSendContactsData::SendContactsPacket(HWND hwndDlg, HANDLE *phContacts, int nContacts)
{
	HANDLE hProcc = (HANDLE)CallContactService(hContact, PSS_CONTACTS, MAKEWPARAM(0, nContacts), (LPARAM)phContacts);
	if (!hProcc) {
		// on trivial error - do not close dialog
		ShowErrorDlg(hwndDlg, "Contacts transfer failed!", FALSE);
		return FALSE; // Failure
	}
	
	TAckData *ackData = gaAckData.Add(hProcc, new TAckData(hContact));
	uacklist.Add(hProcc);
	ackData->nContacts = nContacts;
	ackData->aContacts = (HANDLE*)mir_alloc(nContacts*sizeof(HANDLE));
	memmove(ackData->aContacts, phContacts, nContacts*sizeof(HANDLE)); // copy the array of hContact for ack array
	EnableDlgItem(hwndDlg, IDOK, FALSE);
	EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
	return TRUE; // Success
}
Example #25
0
void SendSendQueueItem(MessageSendQueueItem* item)
{
	mir_cslockfull lock(queueMutex);
	item->timeout = 0;

	if (item->prev != NULL) {
		item->prev->next = item->next;
		if (item->next != NULL)
			item->next->prev = item->prev;

		item->next = global_sendQueue;
		item->prev = NULL;
		if (global_sendQueue != NULL)
			global_sendQueue->prev = item;

		global_sendQueue = item;
	}
	lock.unlock();

	item->hSendId = (HANDLE)CallContactService(item->hContact, PSS_MESSAGE, item->flags, (LPARAM)item->sendBuffer);
}
Example #26
0
void FreeFileDlgData(FileDlgData* dat)
{
	if (dat == NULL)
		return;

	if (dat->fs)
		CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0);
	if (dat->hPreshutdownEvent)
		UnhookEvent(dat->hPreshutdownEvent);
	if (dat->hNotifyEvent)
		UnhookEvent(dat->hNotifyEvent);

	FreeProtoFileTransferStatus(&dat->transferStatus);
	FreeFilesMatrix(&dat->files);

	mir_free(dat->fileVirusScanned);
	if (dat->hIcon)
		DestroyIcon(dat->hIcon);
	if (dat->hIconFolder)
		DestroyIcon(dat->hIconFolder);
	mir_free(dat);
}
Example #27
0
INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam)
{
	CCSDATA *ccs = (CCSDATA*)lParam;

	// This is a simple contact
	// (this should normally not happen, since linked contacts do not appear on the list.)
	DBCachedContact *cc = CheckMeta(ccs->hContact);
	if (cc == NULL || cc->nDefault == -1)
		return 0;

	MCONTACT hMostOnline = Meta_GetMostOnlineSupporting(cc, PFLAGNUM_4, PF4_AVATARS);
	if (!hMostOnline)
		return 0;

	char *proto = GetContactProto(hMostOnline);
	if (!proto)
		return 0;

	PROTO_AVATAR_INFORMATIONT AI;
	AI.cbSize = sizeof(AI);
	AI.hContact = ccs->hContact;
	AI.format = PA_FORMAT_UNKNOWN;
	_tcscpy(AI.filename, _T("X"));
	if (CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS)
		db_set_ts(ccs->hContact, "ContactPhoto", "File", AI.filename);

	hMostOnline = Meta_GetMostOnline(cc);
	Meta_CopyContactNick(cc, hMostOnline);

	if (!hMostOnline)
		return 0;

	ccs->hContact = hMostOnline;
	if (!ProtoServiceExists(proto, PSS_GETINFO))
		return 0; // fail

	return CallContactService(ccs->hContact, PSS_GETINFO, ccs->wParam, ccs->lParam);
}
Example #28
0
void StatusUpdaterThread(HWND hwndDlg)
{
	int i,curdelay,lastcheck=0;
	HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);

	SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST);

	while (!stopStatusUpdater) {
		curdelay=DBGetContactSettingByte(hContact,"CList","StatusMsgAutoDelay",15000);
		if (curdelay<5000) curdelay=5000;

		if ((int)(GetTickCount()-lastcheck)>curdelay)
		{
			lastcheck=GetTickCount();
			if (DBGetContactSettingByte(hContact,"CList","StatusMsgAuto",0)) {
				for (i=0; i<5; i++) {
					if (hContact!=NULL) {
						pdisplayNameCacheEntry pdnce =(pdisplayNameCacheEntry)pcli->pfnGetCacheEntry((HANDLE)hContact);
						if (pdnce && !pdnce->protoNotExists && pdnce->szProto)
						{			
							CallContactService(hContact, PSS_GETAWAYMSG, 0, 0);
						}
						hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0);
					}
					if (hContact==NULL) {
						hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
						if (hContact==NULL) break;
					}
					Sleep(500);
				}
			}
		}
		//Sleep(DBGetContactSettingByte(hContact,"CList","StatusMsgAutoDelay",100));
		Sleep(200);
	}
}
Example #29
0
INT_PTR Meta_SendMessage(WPARAM wParam,LPARAM lParam)
{
	CCSDATA *ccs = (CCSDATA*)lParam;

	DBCachedContact *cc = CheckMeta(ccs->hContact);
	if (cc == NULL || cc->nDefault == -1) {
		// This is a simple contact, let through the stack of protocols
		// (this should normally not happen, since linked contacts do not appear on the list.)
		return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
	}

	MCONTACT hMostOnline = db_mc_getSrmmSub(cc->contactID);
	if (!hMostOnline) {
		// send failure to notify user of reason
		HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

		TFakeAckParams *tfap = (TFakeAckParams *)mir_alloc(sizeof(TFakeAckParams));
		tfap->hContact = ccs->hContact;
		tfap->hEvent = hEvent;
		tfap->id = 10;
		strcpy(tfap->msg, Translate("No online contacts found."));

		DWORD dwThreadId;
		CloseHandle(CreateThread(NULL, 0, sttFakeAckFail, tfap, 0, &dwThreadId));
		SetEvent(hEvent);
		return 10;
	}

	Meta_CopyContactNick(cc, hMostOnline);

	ccs->hContact = hMostOnline;
	char *proto = GetContactProto(hMostOnline);
	Meta_SetNick(proto);	// (no matter what was there before)

	return CallContactService(ccs->hContact, PSS_MESSAGE, ccs->wParam, ccs->lParam);
}
Example #30
0
INT addEvent(WPARAM hContact, LPARAM hDBEvent)
{
	BOOL fEnabled = db_get_b(NULL, protocolname, KEY_ENABLED, 1);
	if (!fEnabled || !hContact || !hDBEvent)
		return FALSE;	/// unspecifyed error

	char* pszProto = GetContactProto(hContact);
	int status = CallProtoService(pszProto, PS_GETSTATUS, 0, 0);
	if (status == ID_STATUS_ONLINE || status == ID_STATUS_FREECHAT || status == ID_STATUS_INVISIBLE)
		return FALSE;

	DBEVENTINFO dbei = {sizeof(dbei)};
	db_event_get(hDBEvent, &dbei); /// detect size of msg

	if ((dbei.eventType != EVENTTYPE_MESSAGE) || (dbei.flags == DBEF_READ))
		return FALSE; /// we need EVENTTYPE_MESSAGE event..
	else
	{	/// needed event has occured..
		DBVARIANT dbv;

		if (!dbei.cbBlob)	/// invalid size
			return FALSE;

		if (db_get_ts(hContact,"Protocol","p",&dbv))
			// Contact with no protocol ?!!
			return FALSE;
		else
			db_free(&dbv);

		if(db_get_b(hContact, "CList", "NotOnList", 0))
			return FALSE;

		if(db_get_b(hContact, protocolname, "TurnedOn", 0))
			return FALSE;

		if (!( dbei.flags & DBEF_SENT))
		{
			int timeBetween=time(NULL)-db_get_dw(hContact,protocolname,"LastReplyTS",0);
			if (timeBetween>interval || db_get_w(hContact,protocolname,"LastStatus",0)!=status)
			{
				char szStatus[6]={0};
				int msgLen=1;
				int isQun=db_get_b(hContact,pszProto,"IsQun",0);
				if (isQun)
					return FALSE;

				mir_snprintf(szStatus,_countof(szStatus),"%d",status);
				if (!db_get_ts(NULL,protocolname,szStatus,&dbv))
				{
					if (*dbv.ptszVal)
					{
						DBVARIANT dbvHead={0}, dbvNick={0};
						CMString ptszTemp;
						TCHAR *ptszTemp2;

						db_get_ts(hContact,pszProto,"Nick",&dbvNick);
						if (mir_tstrcmp(dbvNick.ptszVal, NULL) == 0)
						{
							db_free(&dbvNick);
							return FALSE;
						}

						msgLen += (int)mir_tstrlen(dbv.ptszVal);
						if (!db_get_ts(NULL,protocolname,KEY_HEADING,&dbvHead))
						{
							ptszTemp = dbvHead.ptszVal;
							ptszTemp.Replace(_T("%user%"), dbvNick.ptszVal);
							msgLen += (int)(mir_tstrlen(ptszTemp));
						}
						ptszTemp2 = (TCHAR*)mir_alloc(sizeof(TCHAR) * (msgLen+5));
						mir_sntprintf(ptszTemp2, msgLen+5, _T("%s\r\n\r\n%s"), ptszTemp.c_str(), dbv.ptszVal);
						if (ServiceExists(MS_VARS_FORMATSTRING))
						{
							FORMATINFO fi = { 0 };
							fi.cbSize = sizeof(fi);
							fi.flags = FIF_TCHAR;
							fi.tszFormat = ptszTemp2;
							ptszTemp = (TCHAR*)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
						}
						else ptszTemp = Utils_ReplaceVarsT(ptszTemp2);
						
						T2Utf pszUtf(ptszTemp);
						CallContactService(hContact, PSS_MESSAGE, 0, pszUtf);

						dbei.cbSize = sizeof(dbei);
						dbei.eventType = EVENTTYPE_MESSAGE;
						dbei.flags = DBEF_UTF | DBEF_SENT; //DBEF_READ;
						dbei.szModule = pszProto;
						dbei.timestamp = time(NULL);
						dbei.cbBlob = (int)mir_strlen(pszUtf) + 1;
						dbei.pBlob = (PBYTE)pszUtf;
						db_event_add(hContact, &dbei);

						mir_free(ptszTemp2);
						if (dbvNick.ptszVal)
							db_free(&dbvNick);
						if (dbvHead.ptszVal)
							db_free(&dbvHead);
					}
					db_free(&dbv);
				}
			}
		}

		db_set_dw(hContact,protocolname,"LastReplyTS",time(NULL));
		db_set_w(hContact,protocolname,"LastStatus",status);
	}
	return 0;
}