コード例 #1
0
ファイル: share.cpp プロジェクト: nianhuaxpj/ipmsg
/*
	ファイル共有(添付)情報をエンコード
*/
BOOL EncodeShareMsg(ShareInfo *info, char *buf, int bufsize, BOOL incMem)
{
	int		offset=0;
	char	fname[MAX_PATH_U8];
	int		id_base = 0;

	TGenRandom(&id_base, sizeof(id_base));
	id_base &= 0x3fffffff; // 負数になるのを防ぐ

	*buf = 0;
	for (int i=0; i < info->fileCnt; i++)
	{
		char	addition[100] = "";
		if (GET_MODE(info->fileInfo[i]->Attr()) == IPMSG_FILE_CLIPBOARD) {
			if (!incMem) continue;
			sprintf(addition, ":%x=%x", IPMSG_FILE_CLIPBOARDPOS, info->fileInfo[i]->Pos());
		}
		ForcePathToFname(info->fileInfo[i]->Fname(), fname);
		info->fileInfo[i]->SetId(id_base + i);

		offset += sprintf(buf + offset, "%d:%s:%I64x:%x:%x%s:%c",
					info->fileInfo[i]->Id(), fname, info->fileInfo[i]->Size(),
					info->fileInfo[i]->Mtime(), info->fileInfo[i]->Attr(),
					addition, FILELIST_SEPARATOR);

		if (offset + MAX_BUF > bufsize)
			break;
	}
	return	TRUE;
}
コード例 #2
0
ファイル: share.cpp プロジェクト: nianhuaxpj/ipmsg
BOOL TShareStatDlg::SetAllList(void)
{
	shareListView.DeleteAllItems();

	int		i=0, j=0, len=0;
	char	buf[MAX_BUF_EX];

	for (ShareInfo *info=shareMng->Top(); info; info=shareMng->Next(info))
	{
		if (info->hostCnt == 0)
			continue;

		sprintf(buf, "%d", i);
		shareListView.InsertItem(i, buf);

		len = 0;
		*buf = 0;
		for (j=0; j < info->fileCnt && len < sizeof(buf); j++) {
			ForcePathToFname(info->fileInfo[j]->Fname(), buf + len);
			strcat(buf + len, " ");
			len += strlen(buf + len);
			if (len + MAX_PATH_U8 >= sizeof(buf)) break;
		}
		shareListView.SetSubItem(i, 1, buf);

		ShareCntInfo	cntInfo;
		shareMng->GetShareCntInfo(&cntInfo, info);
		MakeSizeString(buf, cntInfo.totalSize, MSS_SPACE);
		if (cntInfo.dirCnt) wsprintf(buf + strlen(buf), "/%dDIR", cntInfo.dirCnt);
		shareListView.SetSubItem(i, 2, buf);

		shareMng->GetShareCntInfo(&cntInfo, info);
		wsprintf(buf, "%d / %d/ %d", cntInfo.fileCnt, cntInfo.doneCnt, cntInfo.transferCnt);
		shareListView.SetSubItem(i, 3, buf);

		len = 0;
		*buf = 0;
		for (j=0; j < info->hostCnt && len + 30 < sizeof(buf); j++) {
			Host *host = info->host[j];
			len += _snprintf(buf + len, sizeof(buf)-len-1, "%.14s(%.10s) ",
							*host->nickName ? host->nickName : host->hostSub.userName,
							host->hostSub.hostName);
		}
		shareListView.SetSubItem(i, 4, buf);
		i++;
	}
	return	TRUE;
}
コード例 #3
0
ファイル: LOGMNG.CPP プロジェクト: SongJLG/johan-doc
BOOL LogMng::WriteMsg(LPCSTR msg, ULONG command, ShareInfo *shareInfo)
{
	char	buf[MAX_BUF * 2] = "  at ";

	strcat(buf, Ctime()); 
	strcat(buf, " ");

	if (command & IPMSG_BROADCASTOPT)
		strcat(buf, BROADCASTLOG_MSGSTR);

	if (command & IPMSG_AUTORETOPT)
		strcat(buf, AUTORETLOG_MSGSTR);

	if (command & IPMSG_MULTICASTOPT)
		strcat(buf, MULTICASTLOG_MSGSTR);

	if (command & IPMSG_ENCRYPTOPT)
		strcat(buf, ENCRYPT_MSGSTR);

	if (command & IPMSG_SECRETOPT)
	{
		if (command & IPMSG_PASSWORDOPT)
			strcat(buf, PASSWDLOG_MSGSTR);
		else
			strcat(buf, SECRETLOG_MSGSTR);
	}

	if (shareInfo && (command & IPMSG_FILEATTACHOPT))
	{
		strcat(buf, "\r\n  " FILEATTACH_MSGSTR " ");
		char	fname[MAX_PATH], *ptr = buf + strlen(buf);

		for (int cnt=0; cnt < shareInfo->fileCnt && ptr-buf < sizeof(buf)-MAX_PATH; cnt++)
		{
			ForcePathToFname(shareInfo->fileInfo[cnt]->Fname(), fname);
			ptr += wsprintf(ptr, "%s%s", fname, cnt+1 == shareInfo->fileCnt ? "" : ", ");
		}
	}
	strcat(buf, "\r\n-------------------------------------\r\n");

	if (Write(buf) && Write(msg) && Write("\r\n\r\n"))
		return	TRUE;
	else
		return	FALSE;
}
コード例 #4
0
ファイル: share.cpp プロジェクト: nianhuaxpj/ipmsg
BOOL TShareDlg::AddList(int idx)
{
	char	buf[MAX_BUF_EX];

	ForcePathToFname(shareInfo->fileInfo[idx]->Fname(), buf);
	shareListView.InsertItem(idx, buf);

	if (GET_MODE(shareInfo->fileInfo[idx]->Attr()) == IPMSG_FILE_DIR)
		strcpy(buf, "(DIR)");
	else
		MakeSizeString(buf, shareInfo->fileInfo[idx]->Size(), MSS_SPACE);
	shareListView.SetSubItem(idx, 1, buf);

	PathToDir(shareInfo->fileInfo[idx]->Fname(), buf);
	shareListView.SetSubItem(idx, 2, buf);

	return	TRUE;
}
コード例 #5
0
ファイル: miscfunc.cpp プロジェクト: nianhuaxpj/ipmsg
BOOL SetFileButton(TDlg *dlg, int buttonID, ShareInfo *info)
{
    char	buf[MAX_BUF] = "", fname[MAX_PATH_U8];
    int		offset = 0;
    for (int cnt=0; cnt < info->fileCnt; cnt++)
    {
        if (dlg->ResId() == SEND_DIALOG)
            ForcePathToFname(info->fileInfo[cnt]->Fname(), fname);
        else
            strncpyz(fname, info->fileInfo[cnt]->Fname(), MAX_PATH_U8);
        offset += wsprintf(buf + offset, "%s ", fname);
        if (offset + MAX_PATH_U8 >= sizeof(buf))
            break;
    }
    dlg->SetDlgItemTextU8(buttonID, buf);
    ::ShowWindow(dlg->GetDlgItem(buttonID), info->fileCnt ? SW_SHOW : SW_HIDE);
    ::EnableWindow(dlg->GetDlgItem(buttonID), info->fileCnt ? TRUE : FALSE);
    return	TRUE;
}
コード例 #6
0
ファイル: share.cpp プロジェクト: nianhuaxpj/ipmsg
int TSaveCommonDlg::Exec(void)
{
	modalFlg = TRUE;

	char	fname[MAX_BUF], last_dir[MAX_BUF], buf[MAX_BUF], *ext;

	// 最終保存ディレクトリが無くなっている場合、少しさかのぼる
	for (int i=0; i < 5; i++) {
		if (*cfg->lastSaveDir && GetFileAttributesU8(cfg->lastSaveDir) == 0xffffffff)
			if (!PathToDir(cfg->lastSaveDir, cfg->lastSaveDir))
				break;
	}

	strcpy(last_dir, *cfg->lastSaveDir ? cfg->lastSaveDir : ".");

	while (1) {
		FileInfo	*fileInfo = shareInfo->fileInfo[offset];

		MakePath(fname, last_dir, fileInfo->Fname());

	// ファイルダイアログ
		TApp::GetApp()->AddWin(this);
		BOOL	ret = OpenFileDlg(parentWin, OpenFileDlg::NODEREF_SAVE, (LPOFNHOOKPROC)TApp::WinProc).Exec(fname, GetLoadStrU8(IDS_SAVEFILE), GetLoadStrAsFilterU8(IDS_OPENFILEALLFLTR), last_dir);
		TApp::GetApp()->DelWin(this);
		hWnd = NULL;

		if (!ret)
			return	FALSE;

	// shortcut の場合は、リンク先に飛ぶ
		if (!isLinkFile && (ext = strrchr(fname, '.')) && stricmp(ext, ".lnk") == 0) {
			char	arg[MAX_BUF];
			if (ReadLinkU8(fname, last_dir, arg)) {
				if ((GetFileAttributesU8(last_dir) & FILE_ATTRIBUTE_DIRECTORY) == 0)
					GetParentDir(last_dir, last_dir);
			}
			continue;
		}

		fileInfo = shareInfo->fileInfo[offset];

		PathToDir(fname, last_dir);
		ForcePathToFname(fname, fname);
		fileInfo->SetSelected(TRUE);

	// 上書き確認
		for (int i=0; i < shareInfo->fileCnt; i++)
		{
			if (!shareInfo->fileInfo[i]->IsSelected())
				continue;
			MakePath(buf, last_dir, offset == i ? fname : shareInfo->fileInfo[i]->Fname());
			if (GetFileAttributesU8(buf) != 0xffffffff)
			{
				ret = parentWin->MessageBoxU8(GetLoadStrU8(IDS_OVERWRITE), GetLoadStrU8(IDS_ATTENTION), MB_OKCANCEL|MB_ICONEXCLAMATION);
				if (ret != IDOK) {
					for (int j=0; j < shareInfo->fileCnt; j++)
						shareInfo->fileInfo[j]->SetSelected(FALSE);
				}
				break;
			}
		}
		if (ret) {
			fileInfo->SetFname(fname);
			strcpy(cfg->lastSaveDir, last_dir);
			cfg->WriteRegistry(CFG_GENERAL);
			return	TRUE;
		}
	}
	// not reach
}
コード例 #7
0
ファイル: logmng.cpp プロジェクト: shirouzu/ipmsg
BOOL LogMng::WriteMsg(ULONG packetNo, LPCSTR msg, ULONG command, int opt, time_t t,
	ShareInfo *shareInfo, int64 *msg_id)
{
	U8str	buf(MAX_UDPBUF);
	char	*p = buf.Buf();

	if (msg_id) {
		*msg_id = 0;
	}

	p += strcpyz(p, LOGMSG_AT);
	p += strcpyz(p, Ctime(&t)); 
	p += strcpyz(p, " ");

	logMsg->packet_no = packetNo;
	logMsg->date = t;

	if (command & IPMSG_BROADCASTOPT) {
		p += strcpyz(p, LoadStrU8(IDS_BROADCASTLOG));
	}

	if (command & IPMSG_AUTORETOPT) {
		p += strcpyz(p, LoadStrU8(IDS_AUTORETLOG));
		logMsg->flags |= DB_FLAG_AUTOREP;
	}

	if (command & IPMSG_MULTICASTOPT) {
		p += strcpyz(p, LoadStrU8(IDS_MULTICASTLOG));
		logMsg->flags |= DB_FLAG_MULTI;
	}

	if (command & IPMSG_ENCRYPTOPT) {
		int		id = 0;
		if (opt & LOG_SIGN2_OK) {
			id = IDS_ENCRYPT2_SIGNED2;
			logMsg->flags |= DB_FLAG_SIGNED2|DB_FLAG_RSA2;
		}
		else if (opt & LOG_SIGN_OK) {
			id = IDS_ENCRYPT2_SIGNED;
			logMsg->flags |= DB_FLAG_SIGNED|DB_FLAG_RSA2;
		}
		else if (opt & LOG_SIGN_ERR) {
			id = IDS_ENCRYPT2_ERROR;
			logMsg->flags |= DB_FLAG_SIGNERR|DB_FLAG_RSA2;
		}
		else if (opt & LOG_ENC2) {
			id = IDS_ENCRYPT2;
			logMsg->flags |= DB_FLAG_RSA2;
		}
		else {
			id = IDS_ENCRYPT;
			logMsg->flags |= DB_FLAG_RSA;
		}
		p += strcpyz(p, LoadStrU8(id));
	}
	else if (opt & LOG_UNAUTH) {
		p += strcpyz(p, LoadStrU8(IDS_UNAUTHORIZED));
		logMsg->flags |= DB_FLAG_UNAUTH;
	}

	if (command & IPMSG_SECRETOPT)
	{
		if (command & IPMSG_PASSWORDOPT) {
			p += strcpyz(p, LoadStrU8(IDS_PASSWDLOG));
		}
		else {
			p += strcpyz(p, LoadStrU8(IDS_SECRETLOG));
		}
		logMsg->flags |= DB_FLAG_SEAL;

		// 未開封フラグのセット
		for (auto itr=logMsg->host.begin(); itr != logMsg->host.end(); itr++) {
			if ((logMsg->flags & DB_FLAG_FROM) == 0 || itr == logMsg->host.begin()) {
				itr->flags = DB_FLAGMH_UNOPEN;
			}
		}
		if ((logMsg->flags & DB_FLAG_FROM)) {
			logMsg->flags |= DB_FLAG_UNOPENR;
		}
	}
	if (opt & LOG_DELAY) {
		p += strcpyz(p, LoadStrU8(IDS_DELAYSEND));
		logMsg->flags |= DB_FLAG_DELAY;
	}

	if (shareInfo && (command & IPMSG_FILEATTACHOPT))
	{
		int	clip_num = 0;
		int	noclip_num = 0;

		for (int i=0; i < shareInfo->fileCnt; i++) {
			if (GET_MODE(shareInfo->fileInfo[i]->Attr()) == IPMSG_FILE_CLIPBOARD) {
				clip_num++;
			}
			else {
				noclip_num++;
			}
		}
		p += strcpyz(p, "\r\n  ");
		if (clip_num || noclip_num) {
			int id = clip_num ? noclip_num ? IDS_FILEWITHCLIP : IDS_WITHCLIP : IDS_FILEATTACH;
			p += strcpyz(p, LoadStrU8(id));
			p += strcpyz(p, " ");
		}

		for (int i=0; i < shareInfo->fileCnt && p - buf.Buf() < MAX_BUF; i++)
		{
			char	fname[MAX_PATH_U8];
			ForcePathToFname(shareInfo->fileInfo[i]->Fname(), fname);
			p += snprintfz(p, MAX_BUF, "%s%s", fname, i+1 == shareInfo->fileCnt ? "" : ", ");

			if (GET_MODE(shareInfo->fileInfo[i]->Attr()) == IPMSG_FILE_CLIPBOARD) {
				LogClip	clip;
				clip.fname = fname;
				SetClipDimension(cfg, &clip);
				logMsg->clip.push_back(clip);
				logMsg->flags |= DB_FLAG_CLIP;
			}
			else {
				logMsg->files.push_back(fname);
				logMsg->flags |= DB_FLAG_FILE;
			}
		}
	}
	p += strcpyz(p, "\r\n");
	p += strcpyz(p, LOGMSG_HEAD_END);

	Wstr	wmsg(msg);
	LocalNewLineToUnixW(wmsg.s(), wmsg.Buf(), wmsg.Len()+1);
	logMsg->body = wmsg;
	logMsg->lines = get_linenum_n(logMsg->body.s(), logMsg->body.StripLen());

	BOOL ret = Write(buf.s()) && Write(msg) && Write("\r\n\r\n");

#ifdef IPMSG_PRO
#define LOGMNG_WRITEMSG
#include "miscext.dat"
#undef  LOGMNG_WRITEMSG
#endif


	if (logDb && cfg->LogCheck) {
		logDb->InsertOneData(logMsg);
		PostMessage(GetMainWnd(), WM_LOGVIEW_UPDATE,
			MakeMsgIdHigh(logMsg->msg_id), MakeMsgIdLow(logMsg->msg_id));
		if (msg_id) {
			*msg_id = logMsg->msg_id;
		}
	}
	logMsg->Init();

	return	ret;
}
コード例 #8
0
ファイル: logmng.cpp プロジェクト: shirouzu/ipmsg
BOOL LogMng::GetRecvMsg(MsgBuf *msg, int opt, THosts *hosts, ShareInfo *shareInfo,
	const std::vector<HostSub> *recvList, U8str *u)
{
	U8str	buf(MAX_UDPBUF);
	char	*p = buf.Buf();

	p += strcpyz(p, LOGMSG_HEAD_TOP);
	p += strcpyz(p, LOGMSG_FROM);
	p += MakeListString(cfg, &msg->hostSub, hosts, p, TRUE);
	p += strcpyz(p, "\r\n");

	if (recvList && recvList->size() >= 1) {
		for (auto &h: *recvList) {
			p += strcpyz(p, LOGMSG_CC);
			p += MakeListString(cfg, (HostSub *)&h, hosts, p, TRUE);
			p += strcpyz(p, "\r\n");
		}
	}

	p += strcpyz(p, LOGMSG_AT);
	p += strcpyz(p, Ctime(&msg->timestamp)); 
	p += strcpyz(p, " ");

	int	command = msg->command;

	if (command & IPMSG_BROADCASTOPT) {
		p += strcpyz(p, LoadStrU8(IDS_BROADCASTLOG));
	}
	if (command & IPMSG_AUTORETOPT) {
		p += strcpyz(p, LoadStrU8(IDS_AUTORETLOG));
	}
	if (command & IPMSG_MULTICASTOPT) {
		p += strcpyz(p, LoadStrU8(IDS_MULTICASTLOG));
	}
	if (command & IPMSG_ENCRYPTOPT) {
		int	id = 0;
		if (opt & LOG_SIGN2_OK) {
			id = IDS_ENCRYPT2_SIGNED2;
		}
		else if (opt & LOG_SIGN_OK) {
			id = IDS_ENCRYPT2_SIGNED;
		}
		else if (opt & LOG_SIGN_ERR) {
			id = IDS_ENCRYPT2_ERROR;
		}
		else if (opt & LOG_ENC2) {
			id = IDS_ENCRYPT2;
		}
		else {
			id = IDS_ENCRYPT;
		}
		p += strcpyz(p, LoadStrU8(id));
	}
	else if (opt & LOG_UNAUTH) {
		p += strcpyz(p, LoadStrU8(IDS_UNAUTHORIZED));
	}

	if (command & IPMSG_SECRETOPT) {
		if (command & IPMSG_PASSWORDOPT)
			p += strcpyz(p, LoadStrU8(IDS_PASSWDLOG));
		else
			p += strcpyz(p, LoadStrU8(IDS_SECRETLOG));
	}

	if (shareInfo && (command & IPMSG_FILEATTACHOPT)) {
		int	clip_num = 0;
		int	noclip_num = 0;

		for (int i=0; i < shareInfo->fileCnt; i++) {
			if (GET_MODE(shareInfo->fileInfo[i]->Attr()) == IPMSG_FILE_CLIPBOARD) {
				clip_num++;
			}
			else {
				noclip_num++;
			}
		}
		p += strcpyz(p, "\r\n  ");
		if (clip_num || noclip_num) {
			int id = clip_num ? noclip_num ? IDS_FILEWITHCLIP : IDS_WITHCLIP : IDS_FILEATTACH;
			p += strcpyz(p, LoadStrU8(id));
			p += strcpyz(p, " ");
		}

		for (int i=0; i < shareInfo->fileCnt && p - buf.Buf() < MAX_BUF; i++)
		{
			char	fname[MAX_PATH_U8];
			ForcePathToFname(shareInfo->fileInfo[i]->Fname(), fname);
			p += snprintfz(p, MAX_BUF, "%s%s", fname, i+1 == shareInfo->fileCnt ? "" : ", ");

			if (GET_MODE(shareInfo->fileInfo[i]->Attr()) == IPMSG_FILE_CLIPBOARD) {
				LogClip	clip;
				clip.fname = fname;
				SetClipDimension(cfg, &clip);
			}
		}
	}
	p += strcpyz(p, "\r\n");
	p += strcpyz(p, LOGMSG_HEAD_END);
	p += strcpyz(p, msg->msgBuf.s());
	p += strcpyz(p, "\r\n\r\n");

	*u = buf.s();
	return	TRUE;
}