Skip to content

Instantly share code, notes, and snippets.

@MagnusTiberius
Created April 23, 2015 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MagnusTiberius/e5002530fcb1f72249e7 to your computer and use it in GitHub Desktop.
Save MagnusTiberius/e5002530fcb1f72249e7 to your computer and use it in GitHub Desktop.
void func()
{
wsabuf.buf = (char*)GetResponse(&wsabuf.len);
}
byte* GetResponse(ULONG *len)
{
byte *content = NULL;
DWORD dwThreadId = GetCurrentThreadId();
char *txtbuf = (char*)malloc(DATA_BUFSIZE);
memset(txtbuf, 0, DATA_BUFSIZE);
std::vector<byte> binbuffer = m_sbResponsePackage;
std::string ctstr;
ctstr.assign(contenType.begin(), contenType.end());
size_t contentsiz = binbuffer.size();
std::string ssiz = std::to_string(contentsiz);
if (contentsiz == 0)
{
strcpy_s(txtbuf, DATA_BUFSIZE, resp_ok);
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "Date: ");
strcat_s(txtbuf, DATA_BUFSIZE, "May 10, 2015");
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
int nbuffersize = strlen(txtbuf);
content = (byte*)malloc(nbuffersize);
memset(content, 0, nbuffersize);
memcpy(content, txtbuf, nbuffersize);
*len = nbuffersize;
return content;
}
strcpy_s(txtbuf, DATA_BUFSIZE, resp_ok);
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "Date: ");
strcat_s(txtbuf, DATA_BUFSIZE, "May 10, 2015");
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "Content-Type: ");
strcat_s(txtbuf, DATA_BUFSIZE, ctstr.c_str());
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "Content-Length: ");
strcat_s(txtbuf, DATA_BUFSIZE, ssiz.c_str());
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
strcat_s(txtbuf, DATA_BUFSIZE, "\n");
int nbuffersize = strlen(txtbuf);
int bufsiz = strlen(txtbuf) + binbuffer.size() + 1;
content = (byte*)malloc(bufsiz);
memset(content, 0, bufsiz);
memcpy(content, txtbuf, nbuffersize);
byte *p = &content[nbuffersize];
memcpy(p, &binbuffer[0], binbuffer.size());
//memcpy(p, m_byteContent, bufsize);
*len = bufsiz;
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment