cmdman.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #include "../include/cmdman.h"
  2. #include "../include/global.h"
  3. #include <iostream>
  4. #define DEBUGPRINT(x) debugprintfunc(x)
  5. //~ #define DEBUGPRINT(x) std::cerr << x
  6. //~ #define DEBUGPRINT(x)
  7. CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
  8. /* setup json stuff */
  9. Json::CharReaderBuilder rbuilder;
  10. wbuilder.settings_["indentation"] = "";
  11. reader = rbuilder.newCharReader();
  12. doversion = false;
  13. loginpossible = false;
  14. dologin = false;
  15. dosignup = false;
  16. /* initialize execute command map */
  17. execmap["help"] = &CmdMan::cmdHelp;
  18. execmap["status"] = &CmdMan::cmdStatus;
  19. execmap["disconnect"] = &CmdMan::cmdDisconnect;
  20. execmap["put"] = &CmdMan::cmdPut;
  21. execmap["get"] = &CmdMan::cmdGet;
  22. execmap["list"] = &CmdMan::cmdList;
  23. execmap["version"] = &CmdMan::cmdVersion;
  24. execmap["login"] = &CmdMan::cmdLogin;
  25. execmap["signup"] = &CmdMan::cmdSignup;
  26. execmap["putdata"] = &CmdMan::cmdPutdata;
  27. execmap["getdata"] = &CmdMan::cmdGetdata;
  28. execmap["listdata"] = &CmdMan::cmdListdata;
  29. execmap["deleteme"] = &CmdMan::cmdDeleteme;
  30. /* initialize description map */
  31. helpmap["help"] = descHelp;
  32. helpmap["status"] = descStatus;
  33. helpmap["disconnect"] = descDisconnect;
  34. helpmap["put"] = descPut;
  35. helpmap["get"] = descGet;
  36. helpmap["list"] = descList;
  37. helpmap["deleteme"] = descDeleteme;
  38. /* initialize handle command map */
  39. handlemap["status"] = &CmdMan::handleStatus;
  40. handlemap["close"] = &CmdMan::handleClose;
  41. handlemap["put"] = &CmdMan::handlePut;
  42. handlemap["get"] = &CmdMan::handleGet;
  43. handlemap["putdata"] = &CmdMan::handlePutdata;
  44. handlemap["getdata"] = &CmdMan::handleGetdata;
  45. handlemap["list"] = &CmdMan::handleList;
  46. handlemap["version"] = &CmdMan::handleVersion;
  47. handlemap["login"] = &CmdMan::handleLogin;
  48. handlemap["signup"] = &CmdMan::handleSignup;
  49. handlemap["listdata"] = &CmdMan::handleListdata;
  50. handlemap["deleteme"] = &CmdMan::handleDeleteme;
  51. debugprintfunc = dpf;
  52. }
  53. CmdMan::~CmdMan() { delete reader; }
  54. CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
  55. CmdRet retval;
  56. Json::Value root, arr;
  57. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  58. map<string, string>::iterator it;
  59. root["command"] = "help";
  60. for (it = helpmap.begin(); it != helpmap.end(); it++) {
  61. arr.append(it->first + " - " + it->second);
  62. }
  63. root["names"] = arr;
  64. retval.type = print;
  65. retval.msg = root;
  66. return retval;
  67. }
  68. CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
  69. CmdRet retval;
  70. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  71. Json::Value root;
  72. root["command"] = "status";
  73. retval.type = send;
  74. retval.msg = root;
  75. return retval;
  76. }
  77. CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
  78. CmdRet retval;
  79. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  80. Json::Value root;
  81. retval.type = send;
  82. if (loginpossible) {
  83. // not logged in, send appropriate login message instead of normal close
  84. root["login"] = false;
  85. root["user"] = "";
  86. root["pass"] = "";
  87. root["cancel"] = true;
  88. retval.type |= close;
  89. } else {
  90. root["command"] = "close";
  91. }
  92. retval.msg = root;
  93. return retval;
  94. }
  95. CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
  96. CmdRet retval;
  97. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  98. Json::Value root;
  99. bool opened = fileman.openPut(args[0]);
  100. root["command"] = "put";
  101. root["file"] = fileman.getPutName();
  102. if (opened) {
  103. root["size"] = fileman.getPutSize();
  104. root["chunks"] = fileman.getPutChunks();
  105. retval.type = send;
  106. } else {
  107. retval.type = error;
  108. root["accept"] = false;
  109. root["error"] = "couldnt open local file \"" + args[0] + "\"";
  110. }
  111. retval.msg = root;
  112. return retval;
  113. }
  114. CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
  115. CmdRet retval;
  116. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  117. Json::Value root;
  118. root["command"] = "putdata";
  119. root["file"] = fileman.getPutName();
  120. root["cancel"] = false;
  121. root["data"] = fileman.readBase64();
  122. root["remaining"] =
  123. fileman
  124. .getPutRemainingChunks(); // number already decremented by readBase64
  125. retval.type = send;
  126. retval.msg = root;
  127. return retval;
  128. }
  129. CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
  130. CmdRet retval;
  131. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  132. Json::Value root;
  133. bool opened = fileman.openGet(args[0]);
  134. root["command"] = "get";
  135. root["file"] = fileman.getGetName();
  136. if (opened) {
  137. retval.type = send;
  138. } else {
  139. retval.type = error;
  140. root["accept"] = false;
  141. root["error"] = "local file \"" + args[0] + "\" already exists";
  142. }
  143. retval.msg = root;
  144. return retval;
  145. }
  146. CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
  147. CmdRet retval;
  148. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  149. Json::Value root;
  150. root["command"] = "getdata";
  151. root["file"] = fileman.getGetName();
  152. root["chunk"] = fileman.getGetRemainingChunks();
  153. root["cancel"] = false;
  154. retval.type = send;
  155. retval.msg = root;
  156. return retval;
  157. }
  158. CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
  159. CmdRet retval;
  160. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  161. Json::Value root;
  162. bool opened = fileman.openList();
  163. root["command"] = "list";
  164. if (opened) {
  165. retval.type = send;
  166. } else {
  167. retval.type = error;
  168. root["accept"] = false;
  169. root["names"] = "";
  170. root["error"] = "cannot list, already listing";
  171. }
  172. retval.msg = root;
  173. return retval;
  174. }
  175. CmdMan::CmdRet CmdMan::cmdListdata(vector<string> args) {
  176. CmdRet retval;
  177. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  178. Json::Value root;
  179. root["command"] = "listdata";
  180. root["chunk"] = fileman.getListRemainingChunks();
  181. root["cancel"] = false;
  182. retval.type = send;
  183. retval.msg = root;
  184. return retval;
  185. }
  186. CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
  187. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  188. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using command \"" + cmd +
  189. "\" with arguments [ ");
  190. for (string s : args)
  191. DEBUGPRINT(s + " ");
  192. DEBUGPRINT("]");
  193. map<string, CmdRet (CmdMan::*)(vector<string>)>::iterator it =
  194. execmap.find(cmd);
  195. CmdRet retval;
  196. Json::Value root;
  197. root["command"] = cmd;
  198. if (it == execmap.end()) {
  199. retval.type = error;
  200. root["command"] = "error";
  201. root["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" + cmd +
  202. "\".\ntype help to list available commands.";
  203. retval.msg = root;
  204. return retval;
  205. } else if (loginpossible || dologin || dosignup) {
  206. DEBUGPRINT("execute does login");
  207. DEBUGPRINT(string("comparison is ") +
  208. std::to_string(cmd.compare("login") && cmd.compare("signup") &&
  209. cmd.compare("disconnect") &&
  210. cmd.compare("help")));
  211. if (cmd.compare("login") && cmd.compare("signup") &&
  212. cmd.compare("disconnect") && cmd.compare("help")) {
  213. retval.type = error;
  214. root["command"] = "error";
  215. root["error"] =
  216. string("Not logged in. Available commands are limited to ") +
  217. "login" + ", " + "signup" + " and " + "disconnect" + "\n" +
  218. "Use help for usage of these commands.";
  219. retval.msg = root;
  220. return retval;
  221. }
  222. }
  223. return (this->*(execmap[cmd]))(args);
  224. }
  225. CmdMan::CmdRet CmdMan::cmdDeleteme(vector<string> args) {
  226. CmdRet retval;
  227. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  228. Json::Value root;
  229. root["command"] = "deleteme";
  230. if (args.size() < 1) {
  231. retval.type = error;
  232. root["accept"] = false;
  233. root["error"] = "not enough arguments, at least 1 argument required";
  234. } else {
  235. retval.type = send;
  236. root["pass"] = args[0];
  237. }
  238. retval.msg = root;
  239. return retval;
  240. }
  241. /* login and signup commands */
  242. CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
  243. CmdRet retval;
  244. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  245. Json::Value root;
  246. if (loginpossible) {
  247. dologin = true;
  248. loginpossible = false;
  249. root["user"] = args[0];
  250. root["pass"] = args[1];
  251. root["login"] = true;
  252. root["cancel"] = false;
  253. retval.type = send;
  254. } else {
  255. root["command"] = "login";
  256. root["error"] = "Login not possible, because you already requested a login "
  257. "or you are logged in";
  258. root["accept"] = false;
  259. retval.type = error;
  260. }
  261. retval.msg = root;
  262. return retval;
  263. }
  264. CmdMan::CmdRet CmdMan::cmdSignup(vector<string> args) {
  265. CmdRet retval;
  266. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  267. Json::Value root;
  268. if (loginpossible) {
  269. dosignup = true;
  270. loginpossible = false;
  271. root["user"] = args[0];
  272. root["pass"] = args[1];
  273. root["login"] = false;
  274. root["cancel"] = false;
  275. retval.type = send;
  276. } else {
  277. root["command"] = "signup";
  278. root["error"] = "Signup not possible, because you already requested a "
  279. "login or you are logged in";
  280. root["accept"] = false;
  281. retval.type = error;
  282. }
  283. retval.msg = root;
  284. return retval;
  285. }
  286. /* internal commands */
  287. CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
  288. CmdRet retval;
  289. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  290. Json::Value root;
  291. root["version"] = protocolVersion;
  292. retval.type = send;
  293. retval.msg = root;
  294. doversion = true;
  295. return retval;
  296. }
  297. CmdMan::CmdRet CmdMan::handle(Json::Value root) {
  298. CmdRet retval;
  299. Json::Value output;
  300. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  301. if (doversion)
  302. root["command"] = "version";
  303. else if (dosignup)
  304. root["command"] = "signup";
  305. else if (dologin)
  306. root["command"] = "login";
  307. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" +
  308. Json::writeString(wbuilder, root) + "\n");
  309. string retmsg;
  310. map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it =
  311. handlemap.find(root["command"].asString());
  312. if (it == handlemap.end()) {
  313. retval.type = error;
  314. output["command"] = "error";
  315. output["error"] = string(__PRETTY_FUNCTION__) + " unknown command \"" +
  316. root["command"].asString() +
  317. "\".\nEnsure code is implemented.";
  318. retval.msg = output;
  319. return retval;
  320. }
  321. return (this->*(handlemap[root["command"].asString()]))(root);
  322. }
  323. CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
  324. CmdRet retval;
  325. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  326. retval.type = print;
  327. retval.msg = root;
  328. return retval;
  329. }
  330. CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
  331. CmdRet retval;
  332. Json::Value output;
  333. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  334. output["command"] = "disconnect";
  335. output["accept"] = true;
  336. retval.type = close | print;
  337. retval.msg = output;
  338. return retval;
  339. }
  340. CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
  341. CmdRet retval;
  342. Json::Value output;
  343. output["command"] = "put";
  344. output["file"] = fileman.getPutName();
  345. output["accept"] = false;
  346. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  347. if (!root["accept"].asBool()) {
  348. retval.type = error;
  349. output["error"] = "Server reports: " + root["error"].asString();
  350. fileman.cancelPut();
  351. } else if (root["file"].asString() != fileman.getPutName()) {
  352. retval.type = error;
  353. output["error"] = "Server reports filename " + root["file"].asString() +
  354. " but actual filename is " + fileman.getPutName();
  355. fileman.cancelPut();
  356. } else {
  357. output["accept"] = true;
  358. output["error"] = "";
  359. retval.type = print | send;
  360. retval.nextcommand = "putdata";
  361. }
  362. retval.msg = output;
  363. return retval;
  364. }
  365. CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
  366. CmdRet retval;
  367. Json::Value output;
  368. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  369. output["command"] = "putdata";
  370. output["file"] = fileman.getPutName();
  371. output["speed"] = 0.0f; // TODO
  372. output["cancel"] = true;
  373. if (root["received"].asInt() != fileman.getPutRemainingChunks()) {
  374. // the number of remaining chunks received from the daemon does not equal
  375. // the number stored at the client side
  376. retval.type = error;
  377. output["error"] = std::string("Server reports number of "
  378. "remaining chunks as ") +
  379. std::to_string(root["received"].asInt()) +
  380. " but actual number is " +
  381. std::to_string(fileman.getPutRemainingChunks());
  382. fileman.cancelPut();
  383. } else if (root["cancel"].asBool()) {
  384. retval.type = error;
  385. output["error"] = "Server reports: " + root["error"].asString();
  386. fileman.cancelPut();
  387. } else if (root["file"].asString() != fileman.getPutName()) {
  388. retval.type = error;
  389. output["error"] = "Server reports filename " + root["file"].asString() +
  390. " but actual filename is " + fileman.getPutName();
  391. fileman.cancelPut();
  392. } else {
  393. output["cancel"] = false;
  394. output["error"] = "";
  395. // sent successfully
  396. if (!root["received"].asInt()) {
  397. // everything sent
  398. retval.type = print;
  399. // TODO
  400. //~ retval.msg = "succesfully uploaded file " + fileman.getPutName();
  401. fileman.closePut();
  402. } else {
  403. retval.type = print | send;
  404. retval.nextcommand = "putdata";
  405. }
  406. }
  407. retval.msg = output;
  408. return retval;
  409. }
  410. CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
  411. CmdRet retval;
  412. Json::Value output;
  413. output["command"] = "get";
  414. output["file"] = fileman.getGetName();
  415. output["accept"] = false;
  416. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  417. if (!root["accept"].asBool()) {
  418. retval.type = error;
  419. output["error"] = "Server reports: " + root["error"].asString();
  420. } else if (root["file"].asString() != fileman.getGetName()) {
  421. retval.type = error;
  422. output["error"] = "Server reports filename " + root["file"].asString() +
  423. " but actual filename is " + fileman.getGetName();
  424. } else {
  425. fileman.setGetChunks(root["chunks"].asInt());
  426. output["accept"] = true;
  427. output["error"] = "";
  428. retval.type = print | send;
  429. retval.nextcommand = "getdata";
  430. }
  431. retval.msg = output;
  432. return retval;
  433. }
  434. CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
  435. CmdRet retval;
  436. Json::Value output;
  437. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  438. output["command"] = "getdata";
  439. output["file"] = fileman.getGetName();
  440. output["speed"] = 0.0f; // TODO
  441. output["cancel"] = true;
  442. // the passed number of recieved chunks should equal the number of sent chunks
  443. if (root["remaining"].asInt() != fileman.getGetRemainingChunks()) {
  444. retval.type = error;
  445. output["error"] =
  446. std::string("Server reports number of remaining chunks as ") +
  447. std::to_string(root["remaining"].asInt()) + " but actual number is " +
  448. std::to_string(fileman.getGetRemainingChunks());
  449. fileman.cancelGet();
  450. } else if (root["cancel"].asBool()) {
  451. retval.type = error;
  452. output["error"] = "Server reports: " + root["error"].asString();
  453. fileman.cancelGet();
  454. } else if (root["file"].asString() != fileman.getGetName()) {
  455. retval.type = error;
  456. output["error"] = "Server reports filename " + root["file"].asString() +
  457. " but actual filename is " + fileman.getGetName();
  458. fileman.cancelGet();
  459. } else {
  460. output["cancel"] = false;
  461. output["error"] = "";
  462. fileman.writeBase64(root["data"].asString());
  463. // loaded successfully
  464. if (fileman.getGetRemainingChunks() < 0) {
  465. // everything sent
  466. retval.type = print;
  467. //~ retval.msg = "succesfully downloaded file " + fileman.getGetName();
  468. fileman.closeGet();
  469. } else {
  470. retval.type = print | send;
  471. retval.nextcommand = "getdata";
  472. }
  473. }
  474. retval.msg = output;
  475. return retval;
  476. }
  477. CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
  478. CmdRet retval;
  479. Json::Value output; // LOCALOUTPUT
  480. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  481. output["command"] = "list";
  482. output["names"] = "";
  483. if (!root["accept"].asBool()) {
  484. retval.type = error;
  485. output["accept"] = false;
  486. output["error"] = "Server reports: " + root["error"].asString();
  487. fileman.cancelList();
  488. } else {
  489. fileman.setListChunks(root["chunks"].asInt());
  490. retval.type = send;
  491. output["accept"] = true;
  492. retval.nextcommand = "listdata";
  493. }
  494. retval.msg = output;
  495. return retval;
  496. }
  497. CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
  498. CmdRet retval;
  499. Json::Value output, arr;
  500. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  501. vector<string> toadd;
  502. output["command"] = "list";
  503. output["names"] = "";
  504. output["accept"] = false;
  505. // the passed number of recieved chunks should equal the number of sent chunks
  506. if (root["remaining"].asInt() != fileman.getListRemainingChunks()) {
  507. retval.type = error;
  508. output["error"] = std::string("Server reports number of "
  509. "remaining chunks as ") +
  510. std::to_string(root["remaining"].asInt()) +
  511. " but actual number is " +
  512. std::to_string(fileman.getListRemainingChunks());
  513. fileman.cancelList();
  514. } else if (root["cancel"].asBool()) {
  515. retval.type = error;
  516. output["error"] = "Server reports: " + root["error"].asString();
  517. fileman.cancelList();
  518. } else {
  519. output["accept"] = true;
  520. for (Json::Value i : root["names"])
  521. toadd.push_back(i.asString());
  522. fileman.putListData(toadd);
  523. // loaded successfully
  524. if (fileman.getListRemainingChunks() < 0) {
  525. // everything sent
  526. retval.type = print;
  527. for (string s : fileman.getListData())
  528. arr.append(s);
  529. output["names"] = arr;
  530. fileman.closeList();
  531. } else {
  532. retval.type = print | send;
  533. retval.nextcommand = "listdata";
  534. }
  535. }
  536. retval.msg = output;
  537. return retval;
  538. }
  539. CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
  540. CmdRet retval;
  541. Json::Value output; // LOCALOUTPUT
  542. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  543. output["command"] = "version";
  544. output["serverversion"] = root["version"].asString();
  545. output["clientversion"] = protocolVersion;
  546. if (!root["accept"].asBool()) {
  547. retval.type = error;
  548. output["accept"] = false;
  549. } else {
  550. retval.type = print | seton;
  551. output["accept"] = true;
  552. doversion = false;
  553. loginpossible = true;
  554. }
  555. retval.msg = output;
  556. return retval;
  557. }
  558. CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
  559. CmdRet retval;
  560. Json::Value output; // LOCALOUTPUT
  561. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  562. output["command"] = "login";
  563. if (!root["accept"].asBool()) {
  564. retval.type = error;
  565. output["error"] = root["error"].asString();
  566. output["accept"] = false;
  567. loginpossible = true;
  568. dologin = false;
  569. } else {
  570. retval.type = print | seton;
  571. output["error"] = "";
  572. output["accept"] = true;
  573. dologin = false;
  574. }
  575. retval.msg = output;
  576. return retval;
  577. }
  578. CmdMan::CmdRet CmdMan::handleSignup(Json::Value root) {
  579. CmdRet retval;
  580. Json::Value output; // LOCALOUTPUT
  581. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  582. output["command"] = "signup";
  583. if (!root["accept"].asBool()) {
  584. retval.type = error;
  585. output["error"] = root["error"].asString();
  586. output["accept"] = false;
  587. loginpossible = true;
  588. dosignup = false;
  589. } else {
  590. retval.type = print | seton;
  591. output["error"] = "";
  592. output["accept"] = true;
  593. dosignup = false;
  594. }
  595. retval.msg = output;
  596. return retval;
  597. }
  598. CmdMan::CmdRet CmdMan::handleDeleteme(Json::Value root) {
  599. CmdRet retval;
  600. DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
  601. if (!root["accept"].asBool()) {
  602. retval.type = error;
  603. } else {
  604. retval.type = close | print;
  605. }
  606. retval.msg = root;
  607. return retval;
  608. }