| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
#include <curl/curl.h> |
|---|
| 32 |
#include <curl/types.h> |
|---|
| 33 |
#include <curl/easy.h> |
|---|
| 34 |
|
|---|
| 35 |
#include "Module.hpp" |
|---|
| 36 |
#include "ModuleManager.hpp" |
|---|
| 37 |
#include "SocketManager.hpp" |
|---|
| 38 |
#include "Nepenthes.hpp" |
|---|
| 39 |
#include "SubmitHandler.hpp" |
|---|
| 40 |
#include "EventHandler.hpp" |
|---|
| 41 |
#include "EventHandler.cpp" |
|---|
| 42 |
|
|---|
| 43 |
#include <cstdlib> |
|---|
| 44 |
#include <cstring> |
|---|
| 45 |
|
|---|
| 46 |
using namespace std; |
|---|
| 47 |
|
|---|
| 48 |
namespace nepenthes |
|---|
| 49 |
{ |
|---|
| 50 |
class NormanContext |
|---|
| 51 |
{ |
|---|
| 52 |
public: |
|---|
| 53 |
NormanContext(char *email,string filename, uint32_t filesize, char *filebuffer, char *md5sum) |
|---|
| 54 |
{ |
|---|
| 55 |
m_Email = email; |
|---|
| 56 |
m_FileName = filename; |
|---|
| 57 |
m_FileSize = filesize; |
|---|
| 58 |
m_FileBuffer = (char *) malloc(filesize); |
|---|
| 59 |
m_MD5Sum = md5sum; |
|---|
| 60 |
memcpy((char *)m_FileBuffer,(char *)filebuffer,filesize); |
|---|
| 61 |
|
|---|
| 62 |
m_FormPost = NULL; |
|---|
| 63 |
m_LastPtr = NULL; |
|---|
| 64 |
m_HeaderList = NULL; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
curl_formadd(&m_FormPost, |
|---|
| 68 |
&m_LastPtr, |
|---|
| 69 |
CURLFORM_COPYNAME, "email", |
|---|
| 70 |
CURLFORM_CONTENTTYPE, "form-data", |
|---|
| 71 |
CURLFORM_COPYCONTENTS, email, |
|---|
| 72 |
CURLFORM_END); |
|---|
| 73 |
|
|---|
| 74 |
string name = "nepenthes-"; |
|---|
| 75 |
name += md5sum; |
|---|
| 76 |
name += "-"; |
|---|
| 77 |
name += filename; |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
curl_formadd(&m_FormPost, |
|---|
| 81 |
&m_LastPtr, |
|---|
| 82 |
CURLFORM_COPYNAME, "upfile", |
|---|
| 83 |
CURLFORM_BUFFER, name.c_str(), |
|---|
| 84 |
CURLFORM_BUFFERPTR, m_FileBuffer, |
|---|
| 85 |
CURLFORM_BUFFERLENGTH, filesize, |
|---|
| 86 |
CURLFORM_END); |
|---|
| 87 |
|
|---|
| 88 |
char buf[] = "Expect:"; |
|---|
| 89 |
m_HeaderList = curl_slist_append(m_HeaderList, buf); |
|---|
| 90 |
|
|---|
| 91 |
} |
|---|
| 92 |
~NormanContext() |
|---|
| 93 |
{ |
|---|
| 94 |
free(m_FileBuffer); |
|---|
| 95 |
curl_formfree(m_FormPost); |
|---|
| 96 |
curl_slist_free_all(m_HeaderList); |
|---|
| 97 |
|
|---|
| 98 |
} |
|---|
| 99 |
char *getEmail() |
|---|
| 100 |
{ |
|---|
| 101 |
return (char *)m_Email.c_str(); |
|---|
| 102 |
} |
|---|
| 103 |
char *getFileName() |
|---|
| 104 |
{ |
|---|
| 105 |
return (char *)m_FileName.c_str(); |
|---|
| 106 |
} |
|---|
| 107 |
uint32_t getFileSize() |
|---|
| 108 |
{ |
|---|
| 109 |
return m_FileSize; |
|---|
| 110 |
} |
|---|
| 111 |
char *getMD5Sum() |
|---|
| 112 |
{ |
|---|
| 113 |
return (char *)m_MD5Sum.c_str(); |
|---|
| 114 |
} |
|---|
| 115 |
char *getFileBuffer() |
|---|
| 116 |
{ |
|---|
| 117 |
return m_FileBuffer; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
struct curl_httppost *m_FormPost; |
|---|
| 122 |
struct curl_httppost *m_LastPtr; |
|---|
| 123 |
struct curl_slist *m_HeaderList; |
|---|
| 124 |
|
|---|
| 125 |
protected: |
|---|
| 126 |
string m_Email; |
|---|
| 127 |
string m_FileName; |
|---|
| 128 |
char *m_FileBuffer; |
|---|
| 129 |
uint32_t m_FileSize; |
|---|
| 130 |
string m_MD5Sum; |
|---|
| 131 |
}; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
class SubmitNorman : public Module , public SubmitHandler, public EventHandler |
|---|
| 135 |
{ |
|---|
| 136 |
public: |
|---|
| 137 |
SubmitNorman(Nepenthes *); |
|---|
| 138 |
~SubmitNorman(); |
|---|
| 139 |
bool Init(); |
|---|
| 140 |
bool Exit(); |
|---|
| 141 |
|
|---|
| 142 |
void Submit(Download *down); |
|---|
| 143 |
void Hit(Download *down); |
|---|
| 144 |
uint32_t handleEvent(Event *event); |
|---|
| 145 |
static size_t WriteCallback(char *buffer, size_t size, size_t nitems, void *userp); |
|---|
| 146 |
protected: |
|---|
| 147 |
CURLM * m_CurlStack; |
|---|
| 148 |
int32_t m_Queued; |
|---|
| 149 |
string m_Email; |
|---|
| 150 |
|
|---|
| 151 |
list <string> m_UrlList; |
|---|
| 152 |
}; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
extern nepenthes::Nepenthes *g_Nepenthes; |
|---|
| 156 |
|
|---|