root/nepenthes/trunk/modules/submit-norman/submit-norman.hpp

Revision 1699, 3.6 kB (checked in by common, 2 weeks ago)

nepenthes

  • missing includes for g++ 4.3 by Philipp Bescht, thanks
  • Property svn:keywords set to id rev
Line 
1 /********************************************************************************
2  *                              Nepenthes
3  *                        - finest collection -
4  *
5  *
6  *
7  * Copyright (C) 2005  Paul Baecher & Markus Koetter
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22  *
23  *
24  *             contact nepenthesdev@users.sourceforge.net 
25  *
26  *******************************************************************************/
27
28  /* $Id$ */
29
30
31 #include <curl/curl.h>
32 #include <curl/types.h> /* new for v7 */
33 #include <curl/easy.h> /* new for v7 */
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                         /* email field */
67                         curl_formadd(&m_FormPost,
68                                                  &m_LastPtr,
69                                                  CURLFORM_COPYNAME, "email",
70                                                  CURLFORM_CONTENTTYPE, "form-data",
71                                                  CURLFORM_COPYCONTENTS, email, // FIXME
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
Note: See TracBrowser for help on using the browser.