summaryrefslogtreecommitdiff
path: root/src/dkimbase.cpp
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/dkimbase.cpp
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/dkimbase.cpp')
-rw-r--r--src/dkimbase.cpp113
1 files changed, 56 insertions, 57 deletions
diff --git a/src/dkimbase.cpp b/src/dkimbase.cpp
index f6abf45..c27e767 100644
--- a/src/dkimbase.cpp
+++ b/src/dkimbase.cpp
@@ -19,10 +19,13 @@
* Changes done by ¢feh@fehcom.de obeying the above license
*
*****************************************************************************/
+#include "dkimbase.h"
+
#include <string.h>
+
#include <algorithm>
+
#include "dkim.h"
-#include "dkimbase.h"
CDKIMBase::CDKIMBase()
@@ -52,11 +55,11 @@ int CDKIMBase::Init(void)
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// Alloc - allocate buffer
//
////////////////////////////////////////////////////////////////////////////////
-int CDKIMBase::Alloc(char*& szBuffer,int nRequiredSize)
+int CDKIMBase::Alloc(char *& szBuffer, int nRequiredSize)
{
szBuffer = new char[nRequiredSize];
@@ -64,25 +67,25 @@ int CDKIMBase::Alloc(char*& szBuffer,int nRequiredSize)
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// ReAlloc - extend buffer if necessary, leaving room for future expansion
//
////////////////////////////////////////////////////////////////////////////////
-int CDKIMBase::ReAlloc(char*& szBuffer,int& nBufferSize,int nRequiredSize)
+int CDKIMBase::ReAlloc(char *& szBuffer, int& nBufferSize, int nRequiredSize)
{
if (nRequiredSize > nBufferSize) {
- char* newp;
- int nNewSize = nRequiredSize + BUFFER_ALLOC_INCREMENT;
+ char *newp;
+ int nNewSize = nRequiredSize + BUFFER_ALLOC_INCREMENT;
- if (Alloc(newp,nNewSize) == DKIM_SUCCESS) {
+ if (Alloc(newp, nNewSize) == DKIM_SUCCESS) {
if (szBuffer != NULL && nBufferSize > 0) {
- memcpy(newp,szBuffer,nBufferSize);
+ memcpy(newp, szBuffer, nBufferSize);
delete[] szBuffer;
}
szBuffer = newp;
- nBufferSize = nNewSize;
+ nBufferSize = nNewSize;
} else {
- return DKIM_OUT_OF_MEMORY; // memory alloc error!
+ return DKIM_OUT_OF_MEMORY; // memory alloc error!
}
}
@@ -90,30 +93,30 @@ int CDKIMBase::ReAlloc(char*& szBuffer,int& nBufferSize,int nRequiredSize)
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// Process - split buffers into lines without any CRs or LFs at the end.
//
////////////////////////////////////////////////////////////////////////////////
-void CDKIMBase::Free(char* szBuffer)
+void CDKIMBase::Free(char *szBuffer)
{
- if (szBuffer)
- delete[] szBuffer;
+ if (szBuffer) delete[] szBuffer;
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// Process - split buffers into lines without any CRs or LFs at the end.
//
////////////////////////////////////////////////////////////////////////////////
-int CDKIMBase::Process(const char* szBuffer,int nBufLength,bool bEOF)
-{ const char* p = szBuffer;
- const char* e = szBuffer + nBufLength;
+int CDKIMBase::Process(const char *szBuffer, int nBufLength, bool bEOF)
+{
+ const char *p = szBuffer;
+ const char *e = szBuffer + nBufLength;
while (p < e) {
if (*p != '\n' || m_LinePos == 0 || m_Line[m_LinePos - 1] != '\r') {
// add char to line
if (m_LinePos >= m_LineSize) {
- int nRet = ReAlloc(m_Line,m_LineSize,m_LinePos + 1);
+ int nRet = ReAlloc(m_Line, m_LineSize, m_LinePos + 1);
if (nRet != DKIM_SUCCESS) return nRet;
}
m_Line[m_LinePos++] = *p;
@@ -126,16 +129,15 @@ int CDKIMBase::Process(const char* szBuffer,int nBufLength,bool bEOF)
if (m_LinePos == 0) {
m_InHeaders = false;
int Result = ProcessHeaders();
- if (Result != DKIM_SUCCESS)
- return Result;
+ if (Result != DKIM_SUCCESS) return Result;
} else {
// append the header to the headers list
if (m_Line[0] != ' ' && m_Line[0] != '\t') {
- HeaderList.push_back(string(m_Line,m_LinePos));
-// fprintf(stderr," dkimbase.cpp:Process:Input: %s \n",m_Line);
+ HeaderList.push_back(string(m_Line, m_LinePos));
+ // fprintf(stderr," dkimbase.cpp:Process:Input: %s \n",m_Line);
} else {
if (!HeaderList.empty()) {
- HeaderList.back().append("\r\n",2).append(m_Line,m_LinePos);
+ HeaderList.back().append("\r\n", 2).append(m_Line, m_LinePos);
} else {
// no header to append to...
}
@@ -143,7 +145,7 @@ int CDKIMBase::Process(const char* szBuffer,int nBufLength,bool bEOF)
}
} else {
// process body line
- int Result = ProcessBody(m_Line,m_LinePos,bEOF);
+ int Result = ProcessBody(m_Line, m_LinePos, bEOF);
if (Result != DKIM_SUCCESS) {
m_LinePos = 0;
return Result;
@@ -160,28 +162,28 @@ int CDKIMBase::Process(const char* szBuffer,int nBufLength,bool bEOF)
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// ProcessFinal - process leftovers if stopping before the body or mid-line
//
////////////////////////////////////////////////////////////////////////////////
int CDKIMBase::ProcessFinal(void)
{
if (m_LinePos > 0) {
- Process("\r\n",2,true);
+ Process("\r\n", 2, true);
}
if (m_InHeaders) {
m_InHeaders = false;
ProcessHeaders();
/* type conversion should be safe as length is zero */
- ProcessBody((char *)"",0,true);
+ ProcessBody((char *)"", 0, true);
}
return DKIM_SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// ProcessHeaders - process the headers (to be implemented by derived class)
//
////////////////////////////////////////////////////////////////////////////////
@@ -191,52 +193,54 @@ int CDKIMBase::ProcessHeaders()
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// ProcessBody - process body line (to be implemented by derived class)
//
////////////////////////////////////////////////////////////////////////////////
-int CDKIMBase::ProcessBody(char* szBuffer, int nBufLength, bool bEOF)
+int CDKIMBase::ProcessBody(char *szBuffer, int nBufLength, bool bEOF)
{
return DKIM_SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
-//
+//
// RemoveSWSP - remove streaming white space from buffer/string inline
//
////////////////////////////////////////////////////////////////////////////////
-struct isswsp
-{
- bool operator()(char ch) { return(ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'); }
+struct isswsp {
+ bool operator()(char ch)
+ {
+ return (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n');
+ }
};
-void CDKIMBase::RemoveSWSP(char* szBuffer)
+void CDKIMBase::RemoveSWSP(char *szBuffer)
{
- *remove_if(szBuffer,szBuffer + strlen(szBuffer),isswsp()) = '\0';
+ *remove_if(szBuffer, szBuffer + strlen(szBuffer), isswsp()) = '\0';
}
-void CDKIMBase::RemoveSWSP(char* pBuffer,int& nBufLength)
+void CDKIMBase::RemoveSWSP(char *pBuffer, int& nBufLength)
{
- nBufLength = remove_if(pBuffer,pBuffer+nBufLength,isswsp()) - pBuffer;
+ nBufLength = remove_if(pBuffer, pBuffer + nBufLength, isswsp()) - pBuffer;
}
void CDKIMBase::RemoveSWSP(string& sBuffer)
{
- sBuffer.erase(remove_if(sBuffer.begin(),sBuffer.end(),isswsp()),sBuffer.end());
+ sBuffer.erase(remove_if(sBuffer.begin(), sBuffer.end(), isswsp()), sBuffer.end());
}
//////////////////////////////////////////////////////////////////////////////////////////
-//
+//
// CompressSWSP - compress streaming white space into single spaces from buffer/string inline
//
//////////////////////////////////////////////////////////////////////////////////////////
-void CDKIMBase::CompressSWSP(char* pBuffer,int& nBufLength)
+void CDKIMBase::CompressSWSP(char *pBuffer, int& nBufLength)
{
- char* pSrc = pBuffer;
- char* pDst = pBuffer;
- char* pEnd = pBuffer + nBufLength;
+ char *pSrc = pBuffer;
+ char *pDst = pBuffer;
+ char *pEnd = pBuffer + nBufLength;
while (pSrc != pEnd) {
if (isswsp()(*pSrc)) {
@@ -245,8 +249,7 @@ void CDKIMBase::CompressSWSP(char* pBuffer,int& nBufLength)
++pSrc;
} while (pSrc != pEnd && isswsp()(*pSrc));
- if (pSrc == pEnd)
- break;
+ if (pSrc == pEnd) break;
*pDst++ = ' ';
}
@@ -270,8 +273,7 @@ void CDKIMBase::CompressSWSP(string& sBuffer)
++iSrc;
} while (iSrc != iEnd && isswsp()(*iSrc));
- if (iSrc == iEnd)
- break;
+ if (iSrc == iEnd) break;
*iDst++ = ' ';
}
@@ -283,7 +285,7 @@ void CDKIMBase::CompressSWSP(string& sBuffer)
}
//////////////////////////////////////////////////////////////////////////////////////////
-//
+//
// RelaxHeader - relax a header field (lower case the name, remove swsp before and after :)
//
// modified 4/21/06 STB to remove white space before colon
@@ -303,17 +305,14 @@ string CDKIMBase::RelaxHeader(const string& sHeader)
} else {
// lower case the header field name
for (unsigned i = 0; i < cpos; i++) {
- if (sTemp[i] >= 'A' && sTemp[i] <= 'Z')
- sTemp[i] += 'a'-'A';
+ if (sTemp[i] >= 'A' && sTemp[i] <= 'Z') sTemp[i] += 'a' - 'A';
}
// remove the space after the :
- if (cpos + 1 < sTemp.length() && sTemp[cpos+1] == ' ')
- sTemp.erase(cpos + 1, 1);
+ if (cpos + 1 < sTemp.length() && sTemp[cpos + 1] == ' ') sTemp.erase(cpos + 1, 1);
// remove the space before the :
- if (cpos > 0 && sTemp[cpos - 1] == ' ')
- sTemp.erase(cpos - 1,1);
+ if (cpos > 0 && sTemp[cpos - 1] == ' ') sTemp.erase(cpos - 1, 1);
}
return sTemp;