Beispiel #1
0
BOOL LogMng::WriteRecvMsg(MsgBuf *msg, int opt, THosts *hosts, ShareInfo *shareInfo,
	const std::vector<HostSub> *recvList, int64 *msg_id)
{
	if (msg->command & IPMSG_NOLOGOPT)
		return	FALSE;

	WriteStart();
	logMsg->flags |= DB_FLAG_FROM;
	SetLogMsgUser(cfg, &msg->hostSub, hosts, logMsg);

	char	buf[MAX_PATH_U8];
	char	*p = buf;

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

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

			SetLogMsgUser(cfg, (HostSub *)&h, hosts, logMsg);
		}
	}

	return	WriteMsg(msg->packetNo, msg->msgBuf.s(), msg->command, opt, msg->timestamp,
		shareInfo, msg_id);
}
Beispiel #2
0
BOOL LogMng::WriteSendHead(Host *host)
{
	char	buf[MAX_BUF];
	char	*p = buf;

	p += strcpyz(p, LOGMSG_TO);
	p += MakeListString(cfg, host, p, TRUE);
	p += strcpyz(p, "\r\n");

	BOOL ret = Write(buf);

	SetLogMsgUser(host, logMsg);

	return	ret;
}
Beispiel #3
0
inline int reg_info_core(char *buf, const u_char *s, int size, const char *name)
{
	const u_char	*e = s + size;
	int				len = strcpyz(buf, name);

	for ( ; s < e; s+=4) {
		if (!::IsBadReadPtr(s, 4)) {
			len += sprintf(buf+len, " %02x%02x%02x%02x", s[0], s[1], s[2], s[3]);
		}
	}
	if (len < 10) len += strcpyz(buf+len, " ........"); // nameしか出力がない場合

	len += strcpyz(buf+len, "\r\n");
	return	len;
}
Beispiel #4
0
/*=========================================================================
	パス合成(ANSI 版)
=========================================================================*/
int MakePath(char *dest, const char *dir, const char *file, int max_len)
{
	if (!dir) {
		dir = dest;
	}

	int	len;
	if (dest == dir) {
		len = (int)strlen(dir);
	} else {
		len = strcpyz(dest, dir);
	}

	if (len > 0) {
		bool	need_sep = (dest[len -1] != '\\');

		if (len >= 2 && !need_sep) {	// 表などで終端の場合は sep必要
			BYTE	*p = (BYTE *)dest;
			while (*p) {
				if (IsDBCSLeadByte(*p) && *(p+1)) {
					p += 2;
					if (!*p) {
						need_sep = true;
					}
				} else {
					p++;
				}
			}
		}
		if (need_sep) {
			dest[len++] = '\\';
		}
	}
	return	len + strncpyz(dest + len, file, max_len - len);
}
Beispiel #5
0
inline int reg_info(char *buf, DWORD_PTR target, const char *name)
{
	int len = 0;

	len += reg_info_core(buf+len, (const u_char *)target - 32, 32, "   ");
	len += reg_info_core(buf+len, (const u_char *)target -  0, 32, name);
	len += reg_info_core(buf+len, (const u_char *)target + 32, 32, "   ");
	len += strcpyz(buf+len, "\r\n");

	return	len < 50 ? 0 : len;	// target データがない場合は 0 に
}
Beispiel #6
0
/*=========================================================================
	パス合成(UTF-8 版)
=========================================================================*/
int MakePathU8(char *dest, const char *dir, const char *file, int max_len)
{
	if (!dir) {
		dir = dest;
	}

	int	len;

	if (dest == dir) {
		len = (int)strlen(dir);
	} else {
		len = strcpyz(dest, dir);
	}
	if (len > 0 && dest[len -1] != '\\') {
		dest[len++] = '\\';
	}
	return	len + strncpyz(dest + len, file, max_len - len);
}
Beispiel #7
0
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;
}
Beispiel #8
0
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;
}