Skip to content

Commit 7eedfa0

Browse files
committed
update:Docment
fix:crashed when multiple times upload file on the socket fix:sqlite query file list problem
1 parent a2a2785 commit 7eedfa0

File tree

11 files changed

+63
-36
lines changed

11 files changed

+63
-36
lines changed

README.en.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ This repository has a development and master branch. If you want to use it, plea
1414
feature list:
1515
1. support file http upload and download(use put and get method)
1616
2. support http api notify of event and management api interface
17-
3. support http encrypt and cert data transimission(planning) \
18-
4. support mysql record infomation.
17+
3. support http encrypt and cert data transimission(planning)
18+
4. support database(mysql and sqlite) record infomation.
1919
5. support load banace
2020
6. supprot http auth
2121
7. support log and config
@@ -90,6 +90,9 @@ The realization of downloading second transmission is to first query the local f
9090
- XEngine_Source code directory
9191
- XEngine_APPClient client code dir
9292

93+
## now task
94+
P2P
95+
9396
## other problems
9497
You can refer to the document under the docment directory. It contains API protocol and service description.
9598

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ c c++ file storage service
1414
1. 支持HTTP协议上传和下载(采用PUT和GET)
1515
2. 支持HTTP API接口事件通知与管理
1616
3. 支持HTTP加密与证书(规划中)
17-
4. 采用MYSQL记录信息
17+
4. 采用数据库(MYSQL和SQLITE)记录信息
1818
5. 支持分布式
1919
6. 支持HTTP验证
2020
7. 支持详尽的日志和配置信息
@@ -88,6 +88,9 @@ make FLAGS=CleanAll 清理编译
8888
上传秒传的实现是先通过HASH查询文件是否在服务器,如果存在就不上传直接提示客户端上传成功.
8989
下载秒传的实现是先通过HASH查询本地文件保存路径,如果存在就直接下载完成.
9090

91+
## 当前任务
92+
实现P2P
93+
9194
## 其他问题
9295
你可以参考docment目录下的文档.里面包含了API协议和服务说明.
9396

XEngine_Docment/Docment_en.docx

175 Bytes
Binary file not shown.

XEngine_Docment/Docment_zh.docx

181 Bytes
Binary file not shown.

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"LogLeave": 32
2626
},
2727
"XSql": {
28+
"SQLType": 1,
29+
"SQLFile": "./XEngine_SQL/SQLFile.db",
2830
"SQLAddr": "192.168.1.9",
2931
"SQLPort": 3306,
3032
"SQLUser": "root",

XEngine_Release/XEngine_SQL/.gitignore

Whitespace-only changes.

XEngine_Source/StorageModule_Config/Config_Define.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ typedef struct tag_XEngine_ServerConfig
4949
}st_XLog;
5050
struct
5151
{
52-
TCHAR tszSQLFile[MAX_PATH];
5352
TCHAR tszSQLAddr[128];
5453
TCHAR tszSQLUser[128];
5554
TCHAR tszSQLPass[128];
5655
TCHAR tszDBName[128];
5756
int nSQLPort;
5857
int nSQLType;
58+
TCHAR tszSQLFile[MAX_PATH];
5959
}st_XSql;
6060
struct
6161
{

XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
115115
}
116116
if (nMsgLen <= 0)
117117
{
118+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("上传客户端:%s,用户数据大小为0?"), lpszClientAddr);
118119
return TRUE;
119120
}
120121
Session_UPStroage_Write(lpszClientAddr, lpszMsgBuffer, nMsgLen);
121122
RfcComponents_HttpServer_GetRecvModeEx(xhUPHttp, lpszClientAddr, &nRVMode, &nRVCount, &nHDSize);
122123
if (nHDSize >= nRVCount)
123124
{
125+
int nHashLen = 0;
124126
UCHAR tszHashStr[MAX_PATH];
125127
XSTORAGECORE_DBFILE st_ProtocolFile;
126128

@@ -132,9 +134,8 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
132134
_tcscpy(st_ProtocolFile.st_ProtocolFile.tszFileName, pSt_HTTPParam->tszHttpUri + 1);
133135
st_ProtocolFile.st_ProtocolFile.nFileSize = nRVCount;
134136

135-
136-
OPenSsl_Api_Digest(tszFileDir, tszHashStr, NULL, TRUE, st_ServiceCfg.st_XStorage.nHashMode);
137-
BaseLib_OperatorString_StrToHex((char*)tszHashStr, 20, st_ProtocolFile.st_ProtocolFile.tszFileHash);
137+
OPenSsl_Api_Digest(tszFileDir, tszHashStr, &nHashLen, TRUE, st_ServiceCfg.st_XStorage.nHashMode);
138+
BaseLib_OperatorString_StrToHex((char*)tszHashStr, nHashLen, st_ProtocolFile.st_ProtocolFile.tszFileHash);
138139
//验证HASH值
139140
if (XEngine_APPHelp_VerHash(lpszClientAddr, tszFileDir, st_ProtocolFile.st_ProtocolFile.tszFileHash, pptszListHdr, nHdrCount))
140141
{
@@ -166,15 +167,15 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
166167
APIHelp_HttpRequest_Post(st_ServiceCfg.st_XProxy.st_XProxyPass.tszUPPass, tszProxyStr, &nHttpCode);
167168
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_NOTICE, _T("上传客户端:%s,请求完成通知返回值:%d,文件:%s,地址:%s"), lpszClientAddr, nHttpCode, st_StorageInfo.tszFileDir, st_ServiceCfg.st_XProxy.st_XProxyPass.tszUPPass);
168169
}
169-
st_HDRParam.bIsClose = FALSE;
170+
st_HDRParam.bIsClose = TRUE;
170171
st_HDRParam.nHttpCode = 200;
171172
RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
172173
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER);
173174
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求上传文件成功,文件名:%s,大小:%d"), lpszClientAddr, tszFileDir, nRVCount);
174175
}
175176
else
176177
{
177-
st_HDRParam.bIsClose = FALSE;
178+
st_HDRParam.bIsClose = TRUE;
178179
st_HDRParam.nHttpCode = 403;
179180
RfcComponents_HttpServer_SendMsgEx(xhUPHttp, tszSDBuffer, &nSDLen, &st_HDRParam);
180181
XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER);
@@ -190,7 +191,8 @@ BOOL XEngine_Task_HttpUPLoader(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in
190191
}
191192
else
192193
{
193-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("上传客户端:%s,请求上传文件中,文件名:%s,大小:%d"), lpszClientAddr, tszFileDir, nMsgLen);
194+
_stprintf(tszFileDir, _T("%s%s"), st_ServiceCfg.st_XStorage.tszFileDir, pSt_HTTPParam->tszHttpUri);
195+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("上传客户端:%s,请求上传文件中,文件名:%s,大小:%d"), lpszClientAddr, tszFileDir, nMsgLen);
194196
}
195197

196198
return TRUE;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4-
<LocalDebuggerCommandArguments>-r</LocalDebuggerCommandArguments>
4+
<LocalDebuggerCommandArguments>
5+
</LocalDebuggerCommandArguments>
56
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
67
</PropertyGroup>
78
</Project>

XEngine_Source/XEngine_StorageComponents/XStorage_SQLPacket/XStorage_SQLite/XStorage_SQLite.cpp

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ BOOL CXStorage_SQLite::XStorage_SQLite_Destory()
9292
return TRUE;
9393
}
9494
bIsRun = FALSE;
95-
if (NULL != pSTDThread)
96-
{
97-
pSTDThread->join();
98-
}
95+
pSTDThread->join();
9996
DataBase_SQLite_Close(xhSQL);
10097
return TRUE;
10198
}
@@ -148,7 +145,7 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileInsert(XSTORAGECORE_DBFILE* pSt_DBFil
148145
_stprintf_s(tszTableName, _T("%04d%02d"), st_LibTimer.wYear, st_LibTimer.wMonth);
149146
}
150147
//插入语句
151-
_stprintf_s(tszSQLStatement, _T("INSERT INTO `%s` (FilePath,FileName,FileHash,FileUser,FileSize,FileTime) VALUES('%s','%s','%s','%s',%lld,now())"), tszTableName, pSt_DBFile->st_ProtocolFile.tszFilePath, pSt_DBFile->st_ProtocolFile.tszFileName, pSt_DBFile->st_ProtocolFile.tszFileHash, pSt_DBFile->st_ProtocolFile.tszFileUser, pSt_DBFile->st_ProtocolFile.nFileSize);
148+
_stprintf_s(tszSQLStatement, _T("INSERT INTO `%s` (FilePath,FileName,FileHash,FileUser,FileSize,FileTime) VALUES('%s','%s','%s','%s',%lld,DATETIME('now', 'localtime'))"), tszTableName, pSt_DBFile->st_ProtocolFile.tszFilePath, pSt_DBFile->st_ProtocolFile.tszFileName, pSt_DBFile->st_ProtocolFile.tszFileHash, pSt_DBFile->st_ProtocolFile.tszFileUser, pSt_DBFile->st_ProtocolFile.nFileSize);
152149
if (!DataBase_SQLite_Exec(xhSQL, tszSQLStatement))
153150
{
154151
XStorage_IsErrorOccur = TRUE;
@@ -273,16 +270,16 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_Li
273270
{
274271
if (_tcslen(lpszTimeStart) > 0 && _tcslen(lpszTimeEnd) > 0)
275272
{
276-
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'TABLE' AND NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd);
273+
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table' AND NAME BETWEEN '%s' AND '%s'"), lpszTimeStart, lpszTimeEnd);
277274
}
278275
else
279276
{
280-
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'TABLE'"));
277+
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'"));
281278
}
282279
}
283280
else
284281
{
285-
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'TABLE'"));
282+
_stprintf_s(tszSQLStatement, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table'"));
286283
}
287284
if (!DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszResult, &nLine, &nRow))
288285
{
@@ -294,6 +291,10 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_Li
294291
//轮训
295292
for (int i = 0; i < nLine; i++)
296293
{
294+
if (!XStorage_SQLite_IsNumber(pptszResult[i]))
295+
{
296+
continue;
297+
}
297298
int nLineResult = 0;
298299
int nFieldResult = 0;
299300
memset(tszSQLStatement, '\0', sizeof(tszSQLStatement));
@@ -324,14 +325,14 @@ BOOL CXStorage_SQLite::XStorage_SQLite_FileQuery(XSTORAGECORE_DBFILE*** pppSt_Li
324325
TCHAR** pptszFileResult;
325326
if (DataBase_SQLite_GetTable(xhSQL, tszSQLStatement, &pptszFileResult, &nLineResult, &nFieldResult))
326327
{
327-
int nFiled = 0;
328+
int nFiled = nFieldResult;
328329
//循环获取所有查找到的文件
329330
for (int j = 0; j < nLineResult; j++)
330331
{
331332
XSTORAGECORE_DBFILE st_DBFile;
332333
memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE));
333334

334-
_tcscpy(st_DBFile.tszTableName, pptszResult[0]);
335+
_tcscpy(st_DBFile.tszTableName, pptszResult[i]);
335336
nFiled++;
336337

337338
_tcscpy(st_DBFile.st_ProtocolFile.tszFilePath, pptszFileResult[nFiled]);
@@ -490,20 +491,18 @@ BOOL CXStorage_SQLite::XStorage_SQLite_CreateTable()
490491
_stprintf_s(tszTableName, _T("%04d%02d"), st_DBTime.wYear, st_DBTime.wMonth + i);
491492
}
492493

493-
_stprintf_s(tszSQLQuery, _T("DROP TABLE IF EXISTS `%s`;"
494-
"CREATE TABLE `%s` ("
495-
" `ID` int NOT NULL AUTO_INCREMENT COMMENT 'ID序号',"
496-
" `FilePath` varchar(260) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '文件路径',"
497-
" `FileName` varchar(260) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '文件名称',"
498-
" `FileHash` varchar(260) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文件HASH',"
499-
" `FileUser` varchar(260) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文件所属用户',"
500-
" `FileUser` varchar(260) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '文件所属用户',"
501-
" `FileSize` bigint NOT NULL COMMENT '文件大小',"
502-
" `FileTime` datetime NOT NULL COMMENT '插入时间',"
503-
" PRIMARY KEY (`ID`) USING BTREE"
504-
") ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;"
505-
"SET FOREIGN_KEY_CHECKS = 1;"
506-
), tszTableName, tszTableName);
494+
_stprintf_s(tszSQLQuery, _T("PRAGMA foreign_keys = false;"
495+
"CREATE TABLE IF NOT EXISTS \"%s\" ("
496+
" \"ID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
497+
" \"FilePath\" TEXT NOT NULL,"
498+
" \"FileName\" TEXT NOT NULL,"
499+
" \"FileHash\" TEXT,"
500+
" \"FileUser\" TEXT,"
501+
" \"FileSize\" integer NOT NULL,"
502+
" \"FileTime\" TEXT NOT NULL"
503+
");"
504+
"PRAGMA foreign_keys = true;"
505+
), tszTableName);
507506

508507
if (!DataBase_SQLite_Exec(xhSQL, tszSQLQuery))
509508
{
@@ -572,12 +571,16 @@ BOOL CXStorage_SQLite::XStorage_SQLite_TimeDel()
572571
TCHAR tszSQLQuery[2048];
573572

574573
memset(tszSQLQuery, '\0', sizeof(tszSQLQuery));
575-
_stprintf_s(tszSQLQuery, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'TABLE' ORDER BY NAME"));
574+
_stprintf_s(tszSQLQuery, _T("SELECT NAME FROM SQLITE_MASTER WHERE TYPE = 'table' ORDER BY NAME"));
576575
if (DataBase_SQLite_GetTable(xhSQL, tszSQLQuery, &pptszResult, &nLine, &nField))
577576
{
578577
for (int i = 0; i < nLine; i++)
579578
{
580579
int nTimeMonth = 0;
580+
if (!XStorage_SQLite_IsNumber(pptszResult[i]))
581+
{
582+
continue;
583+
}
581584
//只有在处理正确的情况下才进行删除操作
582585
if (XStorage_SQLite_TimeMonth(pptszResult[i], &nTimeMonth))
583586
{
@@ -608,6 +611,18 @@ BOOL CXStorage_SQLite::XStorage_SQLite_TimeDel()
608611
DataBase_SQLite_FreeTable(pptszResult);
609612
return TRUE;
610613
}
614+
BOOL CXStorage_SQLite::XStorage_SQLite_IsNumber(LPCTSTR lpszStr)
615+
{
616+
int nLen = _tcslen(lpszStr);
617+
for (int i = 0; i < nLen; i++)
618+
{
619+
if (0 == isdigit(lpszStr[i]))
620+
{
621+
return FALSE;
622+
}
623+
}
624+
return TRUE;
625+
}
611626
//////////////////////////////////////////////////////////////////////////
612627
// 线程函数
613628
//////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)