diff options
author | George Hazan <george.hazan@gmail.com> | 2015-08-30 20:18:34 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-08-30 20:18:34 +0000 |
commit | 2f1ac5fc48cf9de50fe4380ea22d88840945728c (patch) | |
tree | 78045cb7ab1492812d6bf513e244cc6226851282 /plugins/HTTPServer/src/IndexXML.cpp | |
parent | 1279b591a7b8faf4c5dbb088b0432d19ef85726d (diff) |
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@15121 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/HTTPServer/src/IndexXML.cpp')
-rw-r--r-- | plugins/HTTPServer/src/IndexXML.cpp | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/plugins/HTTPServer/src/IndexXML.cpp b/plugins/HTTPServer/src/IndexXML.cpp index 6e25cfce28..04bc7edd8c 100644 --- a/plugins/HTTPServer/src/IndexXML.cpp +++ b/plugins/HTTPServer/src/IndexXML.cpp @@ -17,22 +17,22 @@ #include "Glob.h"
-static const TCHAR szXmlHeader1[] = _T("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n")
- _T("<?xml-stylesheet type=\"text/xsl\" href=\"");
+static const TCHAR szXmlHeader1[] = _T("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n")
+_T("<?xml-stylesheet type=\"text/xsl\" href=\"");
-static const TCHAR szXmlHeader2[] = _T("\"?>\r\n")
- _T("<config>\r\n");
+static const TCHAR szXmlHeader2[] = _T("\"?>\r\n")
+_T("<config>\r\n");
-static const TCHAR szXmlTail[] = _T("</config>");
+static const TCHAR szXmlTail[] = _T("</config>");
-
-static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace,
- const char * pszNew) {
+static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace,
+ const char * pszNew)
+{
static char szBuffer[1024];
char* pszSign = strchr(pszSrc, pszReplace);
if (pszSign) {
- strncpy(szBuffer, pszSrc, _countof(szBuffer)-1);
+ strncpy(szBuffer, pszSrc, _countof(szBuffer) - 1);
do {
mir_strcpy(szBuffer + (pszSign - pszSrc), pszNew);
@@ -43,7 +43,7 @@ static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace, strncpy(pszSrc, szBuffer, MaxLength);
- pszSrc[MaxLength-1] = '\0';
+ pszSrc[MaxLength - 1] = '\0';
}
}
@@ -63,7 +63,7 @@ static void ReplaceSign(char* pszSrc, int MaxLength, const char pszReplace, bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const char * pszSrvPath, DWORD dwRemoteIP)
{
- char szMask[MAX_PATH+1];
+ char szMask[MAX_PATH + 1];
mir_snprintf(szMask, "%s*", pszRealPath);
WIN32_FIND_DATAA fdFindFileData;
@@ -71,7 +71,7 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const if (hFind == INVALID_HANDLE_VALUE)
return FALSE;
- HANDLE hFile = CreateFile(pszIndexPath, GENERIC_WRITE, FILE_SHARE_READ, NULL,
+ HANDLE hFile = CreateFile(pszIndexPath, GENERIC_WRITE, FILE_SHARE_READ, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
@@ -80,9 +80,9 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const }
const int BUFFER_SIZE = 1000;
- char szBuffer[BUFFER_SIZE+1];
+ char szBuffer[BUFFER_SIZE + 1];
char* pszBuffer = szBuffer;
- char szFileName[MAX_PATH+1] = "";
+ char szFileName[MAX_PATH + 1] = "";
char* pszExt;
DWORD dwBytesWritten = 0;
@@ -102,8 +102,8 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const // check if a index.xsl exists in the same directory otherwise use the global
mir_snprintf(szMask, "%s%s", pszRealPath, "index.xsl");
- HANDLE hFileExists = CreateFile(szMask, GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
+ HANDLE hFileExists = CreateFile(szMask, GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileExists == INVALID_HANDLE_VALUE) {
@@ -120,24 +120,25 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const // Write dirname
ReplaceSign(szFileName, MAX_PATH, '&', "&");
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
" <dirname>%s</dirname>\r\n", szFileName);
WriteFile(hFile, szBuffer, pszBuffer - szBuffer, &dwBytesWritten, NULL);
// Find files and directories
do {
if (mir_strcmp(fdFindFileData.cFileName, ".") &&
- strncmp(fdFindFileData.cFileName, "@", 1) &&
- (mir_strcmp(fdFindFileData.cFileName, "..") || mir_strcmp(pszSrvPath, "/"))) { // hide .. in root
+ strncmp(fdFindFileData.cFileName, "@", 1) &&
+ (mir_strcmp(fdFindFileData.cFileName, "..") || mir_strcmp(pszSrvPath, "/"))) { // hide .. in root
pszBuffer = szBuffer;
mir_strcpy(szFileName, fdFindFileData.cFileName);
ReplaceSign(szFileName, MAX_PATH, '&', "&");
if (fdFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
" <item name=\"%s\" isdir=\"true\"/>\r\n", szFileName);
- } else {
+ }
+ else {
pszExt = strrchr(szFileName, '.');
if (pszExt != NULL) {
@@ -145,24 +146,24 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const pszExt++;
}
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
" <item name=\"%s\" ext=\"%s\" size=\"%i\" ",
- szFileName, (pszExt == NULL) ? "" : pszExt, fdFindFileData.nFileSizeLow);
+ szFileName, (pszExt == NULL) ? "" : pszExt, fdFindFileData.nFileSizeLow);
SYSTEMTIME systemTime;
FileTimeToSystemTime(&fdFindFileData.ftCreationTime, &systemTime);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
- "created=\"%i/%02i/%02i %i:%02i:%02i\" ",
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ "created=\"%i/%02i/%02i %i:%02i:%02i\" ",
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond);
FileTimeToSystemTime(&fdFindFileData.ftLastWriteTime, &systemTime);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
- "modified=\"%i/%02i/%02i %i:%02i:%02i\" ",
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ "modified=\"%i/%02i/%02i %i:%02i:%02i\" ",
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
"/>\r\n");
}
@@ -176,28 +177,29 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const FindClose(hFind);
// Add other shared files & directories
- for (CLFileShareNode * pclCur = pclFirstNode; pclCur ; pclCur = pclCur->pclNext) {
+ for (CLFileShareNode * pclCur = pclFirstNode; pclCur; pclCur = pclCur->pclNext) {
if (!((pclCur->st.dwAllowedIP ^ dwRemoteIP) & pclCur->st.dwAllowedMask) && // hide inaccessible shares
- (size_t)(pclCur->nGetSrvPathLen()) > mir_strlen(pszSrvPath) &&
- !strstr(pclCur->st.pszRealPath, "\\@") &&
- !strncmp(pclCur->st.pszSrvPath, pszSrvPath, mir_strlen(pszSrvPath))) {
+ (size_t)(pclCur->nGetSrvPathLen()) > mir_strlen(pszSrvPath) &&
+ !strstr(pclCur->st.pszRealPath, "\\@") &&
+ !strncmp(pclCur->st.pszSrvPath, pszSrvPath, mir_strlen(pszSrvPath))) {
pszBuffer = szBuffer;
mir_strcpy(szFileName, &pclCur->st.pszSrvPath[mir_strlen(pszSrvPath)]);
ReplaceSign(szFileName, MAX_PATH, '&', "&");
if (pclCur->bIsDirectory()) {
- szFileName[mir_strlen(szFileName)-1] = '\0';
+ szFileName[mir_strlen(szFileName) - 1] = '\0';
if (!strchr(szFileName, '/')) { // only one level deeper
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
" <item name=\"%s\" isdir=\"true\"/>\r\n", szFileName);
if (!WriteFile(hFile, szBuffer, pszBuffer - szBuffer, &dwBytesWritten, NULL))
break;
}
- } else {
+ }
+ else {
if (!strchr(szFileName, '/') && // only one level deeper
- strncmp(pszRealPath, pclCur->st.pszRealPath, mir_strlen(pszRealPath))) { // no duplicates
+ strncmp(pszRealPath, pclCur->st.pszRealPath, mir_strlen(pszRealPath))) { // no duplicates
pszExt = strrchr(szFileName, '.');
if (pszExt != NULL) {
@@ -209,7 +211,7 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const FILETIME ftFileCreateTime;
FILETIME ftFileAccessTime;
FILETIME ftFileModifyTime;
- HANDLE hFileS = CreateFile(pclCur->st.pszRealPath, GENERIC_READ,
+ HANDLE hFileS = CreateFile(pclCur->st.pszRealPath, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileS != INVALID_HANDLE_VALUE) {
dwFileSize = GetFileSize(hFileS, NULL);
@@ -217,24 +219,24 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const CloseHandle(hFileS);
}
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
" <item name=\"%s\" ext=\"%s\" size=\"%i\" ",
szFileName, (pszExt == NULL) ? "" : pszExt, dwFileSize);
SYSTEMTIME systemTime;
FileTimeToSystemTime(&ftFileCreateTime, &systemTime);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
- "created=\"%i/%02i/%02i %i:%02i:%02i\" ",
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ "created=\"%i/%02i/%02i %i:%02i:%02i\" ",
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond);
FileTimeToSystemTime(&ftFileModifyTime, &systemTime);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
- "modified=\"%i/%02i/%02i %i:%02i:%02i\" ",
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ "modified=\"%i/%02i/%02i %i:%02i:%02i\" ",
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour,
systemTime.wMinute, systemTime.wSecond);
- pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
+ pszBuffer += mir_snprintf(pszBuffer, BUFFER_SIZE - (pszBuffer - szBuffer),
"/>\r\n");
if (!WriteFile(hFile, szBuffer, pszBuffer - szBuffer, &dwBytesWritten, NULL))
@@ -250,4 +252,4 @@ bool bCreateIndexXML(const char * pszRealPath, const char * pszIndexPath, const CloseHandle(hFile);
return TRUE;
-}
\ No newline at end of file +}
|