cmdman.cpp 19 KB

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