PageRenderTime 73ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Miranda IM - CK Release/Miranda/Plugins/PasteIt/src/PasteToWeb1.cpp

http://miranda-dev.googlecode.com/
C++ | 393 lines | 360 code | 16 blank | 17 comment | 17 complexity | e2275100eb68a9a7bbfe77b00e398d4e MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause, LGPL-2.1
  1. /*
  2. Paste It plugin
  3. Copyright (C) 2011 Krzysztof Kral
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation version 2
  7. of the License.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "StdAfx.h"
  16. #include "PasteToWeb1.h"
  17. #include "Options.h"
  18. PasteFormat PasteToWeb1::formats[] =
  19. {
  20. {L"4cs", L"4CS"},
  21. {L"6502acme", L"6502 ACME Cross Assembler"},
  22. {L"6502kickass", L"6502 Kick Assembler"},
  23. {L"6502tasm", L"6502 TASM/64TASS"},
  24. {L"abap", L"ABAP"},
  25. {L"actionscript", L"ActionScript"},
  26. {L"actionscript3", L"ActionScript 3"},
  27. {L"ada", L"Ada"},
  28. {L"algol68", L"ALGOL 68"},
  29. {L"apache", L"Apache Log"},
  30. {L"applescript", L"AppleScript"},
  31. {L"apt_sources", L"APT Sources"},
  32. {L"asm", L"ASM (NASM)"},
  33. {L"asp", L"ASP"},
  34. {L"autoconf", L"autoconf"},
  35. {L"autohotkey", L"Autohotkey"},
  36. {L"autoit", L"AutoIt"},
  37. {L"avisynth", L"Avisynth"},
  38. {L"awk", L"Awk"},
  39. {L"bascomavr", L"BASCOM AVR"},
  40. {L"bash", L"Bash"},
  41. {L"basic4gl", L"Basic4GL"},
  42. {L"bibtex", L"BibTeX"},
  43. {L"blitzbasic", L"Blitz Basic"},
  44. {L"bnf", L"BNF"},
  45. {L"boo", L"BOO"},
  46. {L"bf", L"BrainFuck"},
  47. {L"c", L"C"},
  48. {L"c_mac", L"C for Macs"},
  49. {L"cil", L"C Intermediate Language"},
  50. {L"csharp", L"C#"},
  51. {L"cpp", L"C++"},
  52. {L"cpp-qt", L"C++ (with QT extensions)"},
  53. {L"c_loadrunner", L"C: Loadrunner"},
  54. {L"caddcl", L"CAD DCL"},
  55. {L"cadlisp", L"CAD Lisp"},
  56. {L"cfdg", L"CFDG"},
  57. {L"chaiscript", L"ChaiScript"},
  58. {L"clojure", L"Clojure"},
  59. {L"klonec", L"Clone C"},
  60. {L"klonecpp", L"Clone C++"},
  61. {L"cmake", L"CMake"},
  62. {L"cobol", L"COBOL"},
  63. {L"coffeescript", L"CoffeeScript"},
  64. {L"cfm", L"ColdFusion"},
  65. {L"css", L"CSS"},
  66. {L"cuesheet", L"Cuesheet"},
  67. {L"d", L"D"},
  68. {L"dcs", L"DCS"},
  69. {L"delphi", L"Delphi"},
  70. {L"oxygene", L"Delphi Prism (Oxygene)"},
  71. {L"diff", L"Diff"},
  72. {L"div", L"DIV"},
  73. {L"dos", L"DOS"},
  74. {L"dot", L"DOT"},
  75. {L"e", L"E"},
  76. {L"ecmascript", L"ECMAScript"},
  77. {L"eiffel", L"Eiffel"},
  78. {L"email", L"Email"},
  79. {L"epc", L"EPC"},
  80. {L"erlang", L"Erlang"},
  81. {L"fsharp", L"F#"},
  82. {L"falcon", L"Falcon"},
  83. {L"fo", L"FO Language"},
  84. {L"f1", L"Formula One"},
  85. {L"fortran", L"Fortran"},
  86. {L"freebasic", L"FreeBasic"},
  87. {L"gambas", L"GAMBAS"},
  88. {L"gml", L"Game Maker"},
  89. {L"gdb", L"GDB"},
  90. {L"genero", L"Genero"},
  91. {L"genie", L"Genie"},
  92. {L"gettext", L"GetText"},
  93. {L"go", L"Go"},
  94. {L"groovy", L"Groovy"},
  95. {L"gwbasic", L"GwBasic"},
  96. {L"haskell", L"Haskell"},
  97. {L"hicest", L"HicEst"},
  98. {L"hq9plus", L"HQ9 Plus"},
  99. {L"html4strict", L"HTML"},
  100. {L"html5", L"HTML 5"},
  101. {L"icon", L"Icon"},
  102. {L"idl", L"IDL"},
  103. {L"ini", L"INI file"},
  104. {L"inno", L"Inno Script"},
  105. {L"intercal", L"INTERCAL"},
  106. {L"io", L"IO"},
  107. {L"j", L"J"},
  108. {L"java", L"Java"},
  109. {L"java5", L"Java 5"},
  110. {L"javascript", L"JavaScript"},
  111. {L"jquery", L"jQuery"},
  112. {L"kixtart", L"KiXtart"},
  113. {L"latex", L"Latex"},
  114. {L"lb", L"Liberty BASIC"},
  115. {L"lsl2", L"Linden Scripting"},
  116. {L"lisp", L"Lisp"},
  117. {L"llvm", L"LLVM"},
  118. {L"locobasic", L"Loco Basic"},
  119. {L"logtalk", L"Logtalk"},
  120. {L"lolcode", L"LOL Code"},
  121. {L"lotusformulas", L"Lotus Formulas"},
  122. {L"lotusscript", L"Lotus Script"},
  123. {L"lscript", L"LScript"},
  124. {L"lua", L"Lua"},
  125. {L"m68k", L"M68000 Assembler"},
  126. {L"magiksf", L"MagikSF"},
  127. {L"make", L"Make"},
  128. {L"mapbasic", L"MapBasic"},
  129. {L"matlab", L"MatLab"},
  130. {L"mirc", L"mIRC"},
  131. {L"mmix", L"MIX Assembler"},
  132. {L"modula2", L"Modula 2"},
  133. {L"modula3", L"Modula 3"},
  134. {L"68000devpac", L"Motorola 68000 HiSoft Dev"},
  135. {L"mpasm", L"MPASM"},
  136. {L"mxml", L"MXML"},
  137. {L"mysql", L"MySQL"},
  138. {L"newlisp", L"newLISP"},
  139. {L"text", L"None"},
  140. {L"nsis", L"NullSoft Installer"},
  141. {L"oberon2", L"Oberon 2"},
  142. {L"objeck", L"Objeck Programming Langua"},
  143. {L"objc", L"Objective C"},
  144. {L"ocaml-brief", L"OCalm Brief"},
  145. {L"ocaml", L"OCaml"},
  146. {L"pf", L"OpenBSD PACKET FILTER"},
  147. {L"glsl", L"OpenGL Shading"},
  148. {L"oobas", L"Openoffice BASIC"},
  149. {L"oracle11", L"Oracle 11"},
  150. {L"oracle8", L"Oracle 8"},
  151. {L"oz", L"Oz"},
  152. {L"pascal", L"Pascal"},
  153. {L"pawn", L"PAWN"},
  154. {L"pcre", L"PCRE"},
  155. {L"per", L"Per"},
  156. {L"perl", L"Perl"},
  157. {L"perl6", L"Perl 6"},
  158. {L"php", L"PHP"},
  159. {L"php-brief", L"PHP Brief"},
  160. {L"pic16", L"Pic 16"},
  161. {L"pike", L"Pike"},
  162. {L"pixelbender", L"Pixel Bender"},
  163. {L"plsql", L"PL/SQL"},
  164. {L"postgresql", L"PostgreSQL"},
  165. {L"povray", L"POV-Ray"},
  166. {L"powershell", L"Power Shell"},
  167. {L"powerbuilder", L"PowerBuilder"},
  168. {L"proftpd", L"ProFTPd"},
  169. {L"progress", L"Progress"},
  170. {L"prolog", L"Prolog"},
  171. {L"properties", L"Properties"},
  172. {L"providex", L"ProvideX"},
  173. {L"purebasic", L"PureBasic"},
  174. {L"pycon", L"PyCon"},
  175. {L"python", L"Python"},
  176. {L"q", L"q/kdb+"},
  177. {L"qbasic", L"QBasic"},
  178. {L"rsplus", L"R"},
  179. {L"rails", L"Rails"},
  180. {L"rebol", L"REBOL"},
  181. {L"reg", L"REG"},
  182. {L"robots", L"Robots"},
  183. {L"rpmspec", L"RPM Spec"},
  184. {L"ruby", L"Ruby"},
  185. {L"gnuplot", L"Ruby Gnuplot"},
  186. {L"sas", L"SAS"},
  187. {L"scala", L"Scala"},
  188. {L"scheme", L"Scheme"},
  189. {L"scilab", L"Scilab"},
  190. {L"sdlbasic", L"SdlBasic"},
  191. {L"smalltalk", L"Smalltalk"},
  192. {L"smarty", L"Smarty"},
  193. {L"sql", L"SQL"},
  194. {L"systemverilog", L"SystemVerilog"},
  195. {L"tsql", L"T-SQL"},
  196. {L"tcl", L"TCL"},
  197. {L"teraterm", L"Tera Term"},
  198. {L"thinbasic", L"thinBasic"},
  199. {L"typoscript", L"TypoScript"},
  200. {L"unicon", L"Unicon"},
  201. {L"uscript", L"UnrealScript"},
  202. {L"vala", L"Vala"},
  203. {L"vbnet", L"VB.NET"},
  204. {L"verilog", L"VeriLog"},
  205. {L"vhdl", L"VHDL"},
  206. {L"vim", L"VIM"},
  207. {L"visualprolog", L"Visual Pro Log"},
  208. {L"vb", L"VisualBasic"},
  209. {L"visualfoxpro", L"VisualFoxPro"},
  210. {L"whitespace", L"WhiteSpace"},
  211. {L"whois", L"WHOIS"},
  212. {L"winbatch", L"Win Batch"},
  213. {L"xbasic", L"XBasic"},
  214. {L"xml", L"XML"},
  215. {L"xorg_conf", L"Xorg Config"},
  216. {L"xpp", L"XPP"},
  217. {L"yaml", L"YAML"},
  218. {L"z80", L"Z80 Assembler"},
  219. {L"zxbasic", L"ZXBasic"},
  220. };
  221. PasteFormat PasteToWeb1::defFormats[] =
  222. {
  223. {L"text", L"None"},
  224. {L"xml", L"XML"},
  225. {L"html4strict", L"HTML"},
  226. {L"html5", L"HTML 5"},
  227. {L"javascript", L"JavaScript"},
  228. {L"php", L"PHP"},
  229. {L"c", L"C"},
  230. {L"csharp", L"C#"},
  231. {L"cpp", L"C++"},
  232. {L"java", L"Java"},
  233. {L"java5", L"Java 5"},
  234. {L"ini", L"INI file"},
  235. {L"css", L"CSS"},
  236. {L"sql", L"SQL"},
  237. {L"asm", L"ASM (NASM)"},
  238. {L"asp", L"ASP"},
  239. {L"caddcl", L"CAD DCL"},
  240. {L"cadlisp", L"CAD Lisp"},
  241. {L"delphi", L"Delphi"},
  242. {L"diff", L"Diff"},
  243. {L"jquery", L"jQuery"},
  244. {L"latex", L"Latex"},
  245. {L"pascal", L"Pascal"},
  246. {L"perl", L"Perl"},
  247. {L"perl6", L"Perl 6"},
  248. {L"python", L"Python"},
  249. {L"vbnet", L"VB.NET"},
  250. {L"vb", L"VisualBasic"},
  251. };
  252. PasteToWeb1::PasteToWeb1()
  253. {
  254. }
  255. PasteToWeb1::~PasteToWeb1()
  256. {
  257. }
  258. void PasteToWeb1::SendToServer(std::wstring str, std::wstring fileName, std::wstring format)
  259. {
  260. std::map<std::string, std::string> headers;
  261. headers["Content-Type"] = "application/x-www-form-urlencoded";
  262. std::wstring content = _T("api_option=paste&api_paste_private=");
  263. content += Options::instance->webOptions[pageIndex]->publicPaste ? _T("0") : _T("1");
  264. content += _T("&api_paste_expire_date=");
  265. content += Options::instance->webOptions[pageIndex]->combo1.empty() ? _T("1M") : Options::instance->webOptions[pageIndex]->combo1;
  266. content += _T("&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd&api_paste_format=");
  267. content += format;
  268. if(!Options::instance->webOptions[pageIndex]->pastebinUserKey.empty())
  269. {
  270. content += _T("&api_user_key=");
  271. content += Options::instance->webOptions[pageIndex]->pastebinUserKey;
  272. }
  273. content += _T("&api_paste_code=");
  274. for(std::wstring::iterator it = str.begin(); it != str.end(); ++it)
  275. {
  276. if(*it == L'%')
  277. {
  278. content += L"%25";
  279. }
  280. else if(*it ==L'&')
  281. {
  282. content += L"%26";
  283. }
  284. else if(*it ==L'=')
  285. {
  286. content += L"%3D";
  287. }
  288. else
  289. {
  290. content += *it;
  291. }
  292. }
  293. wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_post.php", headers, content);
  294. if(resCont != NULL)
  295. {
  296. if(memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0)
  297. {
  298. _stprintf_s(bufErr, 1024, TranslateT("Error during sending text to web page: %s"), resCont + 17);
  299. error = bufErr;
  300. }
  301. else
  302. {
  303. char* s = mir_u2a_cp(resCont, CP_ACP);
  304. strcpy_s(szFileLink, 256, s);
  305. mir_free(s);
  306. }
  307. mir_free(resCont);
  308. }
  309. else
  310. {
  311. error = TranslateT("Error during sending text to web page");
  312. }
  313. }
  314. std::wstring PasteToWeb1::GetUserKey(std::wstring& user, std::wstring& password)
  315. {
  316. std::map<std::string, std::string> headers;
  317. headers["Content-Type"] = "application/x-www-form-urlencoded";
  318. std::wstring content = _T("api_user_name=");
  319. content += user;
  320. content += _T("&api_user_password=");
  321. content += password;
  322. content += _T("&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd");
  323. wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_login.php", headers, content);
  324. std::wstring toRet;
  325. if(resCont != NULL)
  326. {
  327. if(memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0)
  328. {
  329. _stprintf_s(bufErr, 1024, TranslateT("Error during getting user key from web page: %s"), resCont + 17);
  330. MessageBox(NULL, bufErr, TranslateT("Error"), MB_OK | MB_ICONERROR);
  331. }
  332. else
  333. toRet = resCont;
  334. mir_free(resCont);
  335. }
  336. return toRet;
  337. }
  338. std::list<PasteFormat> PasteToWeb1::GetFormats()
  339. {
  340. int count = sizeof(formats) / sizeof(formats[0]);
  341. std::list<PasteFormat> ret(formats, formats + count);
  342. return ret;
  343. }
  344. std::list<PasteFormat> PasteToWeb1::GetDefFormats()
  345. {
  346. int count = sizeof(defFormats) / sizeof(defFormats[0]);
  347. std::list<PasteFormat> ret(defFormats, defFormats + count);
  348. return ret;
  349. }
  350. void PasteToWeb1::ConfigureSettings()
  351. {
  352. Options::instance->webOptions[pageIndex]->isSendFileName = false;
  353. Options::instance->webOptions[pageIndex]->isPublicPaste = true;
  354. Options::instance->webOptions[pageIndex]->isCombo1 = true;
  355. Options::instance->webOptions[pageIndex]->combo1Desc = TranslateT("Paste expire date");
  356. PasteFormat pf;
  357. pf.id = L"N";
  358. pf.name = TranslateT("Never");
  359. Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf);
  360. pf.id = L"10M";
  361. pf.name = TranslateT("10 minutes");
  362. Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf);
  363. pf.id = L"1H";
  364. pf.name = TranslateT("1 hour");
  365. Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf);
  366. pf.id = L"1D";
  367. pf.name = TranslateT("1 day");
  368. Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf);
  369. pf.id = L"1M";
  370. pf.name = TranslateT("1 month");
  371. Options::instance->webOptions[pageIndex]->combo1Values.push_back(pf);
  372. Options::instance->webOptions[pageIndex]->combo1 = L"1M";
  373. Options::instance->webOptions[pageIndex]->isPastebin = true;
  374. }