00001
00002
00006 #ifndef __CONTACT_FUNCTIONS_H__
00007 #define __CONTACT_FUNCTIONS_H__
00008 #include "SheppCommandFunctions.H"
00009
00010 #include "ContactCheck.H"
00011 #include "ContactInfo.H"
00012 #include "ContactTransfer.H"
00013 #include "ContactCreate.H"
00014 #include "ContactUpdate.H"
00015
00017
00022 int cmd_contact_help(string error_msg, string specific = "")
00023 {
00024 if (error_msg != "") {
00025 printf("error: %s\n", error_msg.c_str());
00026 }
00027
00028 printf("contact command syntax help:\n");
00029 printf("\n");
00030
00031 if (specific == "" || specific == "check") {
00032 printf(" check <contact1> [contact2 ... contactN]\n");
00033 printf("\n");
00034 }
00035 if (specific == "" || specific == "info") {
00036 printf(" info <contact> [-auth authInfoPw]\n");
00037 printf("\n");
00038 }
00039 if (specific == "" || specific == "transfer") {
00040 printf(" transfer: <contact> [-auth authInfoPw]\n");
00041 printf("\n");
00042 }
00043 if (specific == "" || specific == "create") {
00044 printf(" create <contact>\n");
00045 printf(" [-postalInfo <type> <-name \"Contact Name\"> "
00046 "[-org \"Org Name\"]\n");
00047 printf(" <-street1 \"address street/line 1\"> "
00048 "[-street2 \"address number/line 2\"]\n");
00049 printf(" [-street3 \"address line 3\"] <-city \"City Name\"> "
00050 "[-state \"State or Province\"]\n");
00051 printf(" [-pc \"postal code\"] <-cc country-code> ...]\n");
00052 printf(" [-voice number:ext] [-fax number:ext]\n");
00053 printf(" <-email emailAddr> [-auth authInfoPw]\n");
00054 printf(" [-disclose <flag> opt,opt,...]\n");
00055 printf("\n");
00056 printf(" available values for opt:\n");
00057 printf(" {name_int name_loc org_int org_loc addr_int addr_loc "
00058 "voice fax email}\n");
00059 printf("\n");
00060 }
00061 if (specific == "" || specific == "delete") {
00062 printf(" delete: not implemented\n");
00063 printf("\n");
00064 }
00065 if (specific == "" || specific == "renew") {
00066 printf(" renew: not implemented\n");
00067 printf("\n");
00068 }
00069 if (specific == "" || specific == "update") {
00070 printf(" update <contact> [-add-status st1,...,stN] "
00071 "[-rem-status st1,...,stN]\n");
00072 printf(" [-postalInfo <type> [-name \"Contact Name\"] "
00073 "[-org \"Org Name\"]\n");
00074 printf(" [-street1 \"address street/line 1\"] "
00075 "[-street2 \"address number/line 2\"]\n");
00076 printf(" [-street3 \"address line 3\"] [-city \"City Name\"] "
00077 "[-state \"State or Province\"]\n");
00078 printf(" [-pc \"postal code\"] [-cc country-code] ...]\n");
00079 printf(" [-voice number:ext] [-fax number:ext]\n");
00080 printf(" [-email emailAddr] [-auth authInfoPw]\n");
00081 printf(" [-disclose <flag> opt,opt,...]\n");
00082 printf("\n");
00083 printf(" available values for opt:\n");
00084 printf(" {name_int name_loc org_int org_loc addr_int addr_loc "
00085 "voice fax email}\n");
00086 printf("\n");
00087 }
00088
00089 if (error_msg != "") {
00090 return -1;
00091 }
00092
00093 return 0;
00094 }
00095
00097
00101 int cmd_contact_check(vector<string> &args)
00102 {
00103 ContactCheck act;
00104 ContactCheckCmd *cmd = act.get_command();
00105
00106 string cmd_name = "check";
00107
00108 while (!args.empty()) {
00109 cmd->insert_id(args[0]);
00110 args.erase(args.begin());
00111 }
00112
00113 if (cmd->get_id_list().empty()) {
00114 return cmd_contact_help("no contact id specified", cmd_name);
00115 }
00116
00117 if (_debug) {
00118 set<string> contacts = cmd->get_id_list();
00119 set<string>::const_iterator it;
00120 printf("contacts to be checked:\n");
00121 for (it = contacts.begin(); it != contacts.end(); it++) {
00122 printf(" [%s]\n", (*it).c_str());
00123 }
00124 }
00125
00126 if (process_action(act) != 0) {
00127 return -1;
00128 }
00129
00130 return 0;
00131 }
00132
00134
00138 int cmd_contact_info(vector<string> &args)
00139 {
00140 ContactInfo act;
00141 ContactInfoCmd *cmd = act.get_command();
00142 string cmd_name = "info";
00143
00144 if (args.empty()) {
00145 return cmd_contact_help("no contact id specified", cmd_name);
00146 }
00147
00148 cmd->set_id(args[0]);
00149 args.erase(args.begin());
00150
00151 while (!args.empty()) {
00152 if (args[0] == "-auth") {
00153
00154 AuthInfo auth;
00155 if (SheppObjSet::authInfo(auth, args) != 0) {
00156 return cmd_contact_help("invalid auth", cmd_name);
00157 }
00158
00159
00160 if (auth.get_roid_f() == true) {
00161 return cmd_contact_help("invalid auth", cmd_name);
00162 }
00163
00164 cmd->set_authInfo(auth);
00165 } else {
00166 return cmd_contact_help("invalid syntax near \"" + args[0] + "\"",
00167 cmd_name);
00168 }
00169 }
00170
00171 if (_debug) {
00172 printf("id to get info: [%s]\n", cmd->get_id().c_str());
00173 SheppPrint::authInfo(cmd->get_authInfo());
00174 }
00175
00176 if (process_action(act) != 0) {
00177 return -1;
00178 }
00179
00180 return 0;
00181 }
00182
00184
00188 int cmd_contact_transfer(vector<string> &args)
00189 {
00190 ContactTransfer act;
00191 ContactTransferCmd *cmd = act.get_command();
00192 string cmd_name = "transfer";
00193
00194 if (args.empty()) {
00195 return cmd_contact_help("no contact id specified", cmd_name);
00196 }
00197
00198 cmd->set_id(args[0]);
00199 args.erase(args.begin());
00200
00201 while (!args.empty()) {
00202 if (args[0] == "-auth") {
00203
00204 AuthInfo auth;
00205 if (SheppObjSet::authInfo(auth, args) != 0) {
00206 return cmd_contact_help("invalid auth", cmd_name);
00207 }
00208
00209
00210 if (auth.get_roid_f() == true) {
00211 return cmd_contact_help("invalid auth", cmd_name);
00212 }
00213
00214 cmd->set_authInfo(auth);
00215 } else {
00216 return cmd_contact_help("invalid syntax near \"" + args[0] + "\"",
00217 cmd_name);
00218 }
00219 }
00220
00221 if (process_action(act) != 0) {
00222 return -1;
00223 }
00224
00225 return 0;
00226 }
00227
00229
00233 int cmd_contact_create(vector<string> &args)
00234 {
00235 ContactCreate act;
00236 ContactCreateCmd *cmd = act.get_command();
00237 string cmd_name = "create";
00238
00239 if (args.empty()) {
00240 return cmd_contact_help("no contact id specified", cmd_name);
00241 }
00242
00243 CommonData common_data;
00244
00245 common_data.set_id(args[0]);
00246 args.erase(args.begin());
00247
00248
00249 AuthInfo auth;
00250 cmd->set_authInfo(auth);
00251
00252 while (!args.empty()) {
00253 if (args[0] == "-postalInfo") {
00254
00255 args.erase(args.begin());
00256 if (args.empty()) {
00257 return cmd_contact_help("missing postal info arguments", cmd_name);
00258 }
00259 PostalInfo postal;
00260 string error_msg;
00261 if (SheppObjSet::postalInfo(postal, args, error_msg, false) != 0) {
00262 return cmd_contact_help(error_msg, cmd_name);
00263 }
00264 vector<PostalInfo> postal_list = common_data.get_postal_info();
00265 for (int i = 0; i < (int) postal_list.size(); i++) {
00266 if (postal_list[i].get_type() == postal.get_type()) {
00267 return cmd_contact_help("duplicated postal info type", cmd_name);
00268 }
00269 }
00270 common_data.insert_postal_info(postal);
00271 } else if (args[0] == "-voice") {
00272
00273 args.erase(args.begin());
00274 CommonData::Phone phone;
00275 if (SheppObjSet::phone(phone, args) != 0) {
00276 return cmd_contact_help("error setting voice telephone number",
00277 cmd_name);
00278 }
00279 common_data.set_voice(phone);
00280 } else if (args[0] == "-fax") {
00281
00282 args.erase(args.begin());
00283 CommonData::Phone phone;
00284 if (SheppObjSet::phone(phone, args) != 0) {
00285 return cmd_contact_help("error setting fax telephone number",
00286 cmd_name);
00287 }
00288 common_data.set_fax(phone);
00289 } else if (args[0] == "-email") {
00290
00291 args.erase(args.begin());
00292 if (args.empty()) {
00293 return cmd_contact_help("no e-mail address specified", cmd_name);
00294 }
00295 common_data.set_email(args[0]);
00296 args.erase(args.begin());
00297 } else if (args[0] == "-auth") {
00298
00299 AuthInfo auth;
00300 if (SheppObjSet::authInfo(auth, args) != 0) {
00301 return cmd_contact_help("invalid auth", cmd_name);
00302 }
00303
00304
00305 if (auth.get_roid_f() == true) {
00306 return cmd_contact_help("invalid auth", cmd_name);
00307 }
00308
00309 cmd->set_authInfo(auth);
00310 } else if (args[0] == "-disclose") {
00311
00312 args.erase(args.begin());
00313 CommonData::Disclose disclose;
00314
00315 if (args[0] != "0" && args[0] != "1") {
00316 return cmd_contact_help("disclose flag must be '0' or '1'", cmd_name);
00317 }
00318 disclose.flag = atoi(args[0].c_str());
00319 args.erase(args.begin());
00320
00321 if (SheppObjSet::disclose(disclose, args[0]) != 0) {
00322 return cmd_contact_help("invalid diclose information", cmd_name);
00323 }
00324 args.erase(args.begin());
00325 common_data.set_disclose(disclose);
00326 } else {
00327 return cmd_contact_help("invalid syntax near \"" + args[0] + "\"",
00328 cmd_name);
00329 }
00330 }
00331
00332 if (common_data.get_postal_info().empty()) {
00333 return cmd_contact_help("at least one postal info must be entered",
00334 cmd_name);
00335 }
00336
00337 if (common_data.get_email() == "") {
00338 return cmd_contact_help("e-mail is mandatory", cmd_name);
00339 }
00340
00341 cmd->set_common_data(common_data);
00342
00343 if (_debug) {
00344 printf(" contact id: [%s]\n", cmd->get_common_data().get_id().c_str());
00345
00346 vector<PostalInfo>::const_iterator it;
00347 vector<PostalInfo> postal_list;
00348 postal_list = cmd->get_common_data().get_postal_info();
00349 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00350 SheppPrint::postal_info((*it));
00351 }
00352
00353 if (cmd->get_common_data().get_voice().number != "") {
00354 printf(" voice:");
00355 SheppPrint::phone(cmd->get_common_data().get_voice());
00356 }
00357
00358 if (cmd->get_common_data().get_fax().number != "") {
00359 printf(" fax :");
00360 SheppPrint::phone(cmd->get_common_data().get_fax());
00361 }
00362
00363 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00364
00365 SheppPrint::authInfo(cmd->get_authInfo());
00366
00367 if (cmd->get_common_data().get_disclose().is_set()) {
00368 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00369 }
00370 }
00371
00372 if (process_action(act) != 0) {
00373 return -1;
00374 }
00375
00376 return 0;
00377 }
00378
00380
00384 int cmd_contact_delete(vector<string> &args)
00385 {
00386 string cmd_name = "delete";
00387 return cmd_contact_help("", cmd_name);
00388 }
00389
00391
00395 int cmd_contact_renew(vector<string> &args)
00396 {
00397 string cmd_name = "renew";
00398 return cmd_contact_help("", cmd_name);
00399 }
00400
00402
00406 int cmd_contact_update(vector<string> &args)
00407 {
00408 ContactUpdate act;
00409 ContactUpdateCmd *cmd = act.get_command();
00410 string cmd_name = "update";
00411
00412 if (args.empty()) {
00413 return cmd_contact_help("no contact id specified", cmd_name);
00414 }
00415
00416 CommonData common_data;
00417
00418 common_data.set_id(args[0]);
00419 args.erase(args.begin());
00420
00421 while (!args.empty()) {
00422 if (args[0] == "-add-status") {
00423
00424 args.erase(args.begin());
00425 if (args.empty()) {
00426 return cmd_contact_help("error setting add-status", cmd_name);
00427 }
00428 string tmp1 = args[0];
00429 string tmp2;
00430 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00431 cmd->insert_status_list_add(tmp1);
00432 if (tmp2 == "") {
00433 break;
00434 }
00435 tmp1 = tmp2;
00436 }
00437 args.erase(args.begin());
00438 } else if (args[0] == "-rem-status") {
00439
00440 args.erase(args.begin());
00441 if (args.empty()) {
00442 return cmd_contact_help("error setting rem-status", cmd_name);
00443 }
00444 string tmp1 = args[0];
00445 string tmp2;
00446 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00447 cmd->insert_status_list_rem(tmp1);
00448 if (tmp2 == "") {
00449 break;
00450 }
00451 tmp1 = tmp2;
00452 }
00453 args.erase(args.begin());
00454 } else if (args[0] == "-postalInfo") {
00455
00456 args.erase(args.begin());
00457 if (args.empty()) {
00458 return cmd_contact_help("missing postal info arguments", cmd_name);
00459 }
00460 PostalInfo postal;
00461 string error_msg;
00462 if (SheppObjSet::postalInfo(postal, args, error_msg, true) != 0) {
00463 return cmd_contact_help(error_msg, cmd_name);
00464 }
00465 vector<PostalInfo> postal_list = common_data.get_postal_info();
00466 for (int i = 0; i < (int) postal_list.size(); i++) {
00467 if (postal_list[i].get_type() == postal.get_type()) {
00468 return cmd_contact_help("duplicated postal info type", cmd_name);
00469 }
00470 }
00471 common_data.insert_postal_info(postal);
00472 } else if (args[0] == "-voice") {
00473
00474 args.erase(args.begin());
00475 CommonData::Phone phone;
00476 if (SheppObjSet::phone(phone, args) != 0) {
00477 return cmd_contact_help("error setting voice telephone number",
00478 cmd_name);
00479 }
00480 common_data.set_voice(phone);
00481 } else if (args[0] == "-fax") {
00482
00483 args.erase(args.begin());
00484 CommonData::Phone phone;
00485 if (SheppObjSet::phone(phone, args) != 0) {
00486 return cmd_contact_help("error setting fax telephone number",
00487 cmd_name);
00488 }
00489 common_data.set_fax(phone);
00490 } else if (args[0] == "-email") {
00491
00492 args.erase(args.begin());
00493 if (args.empty()) {
00494 return cmd_contact_help("no e-mail address specified", cmd_name);
00495 }
00496 common_data.set_email(args[0]);
00497 args.erase(args.begin());
00498 } else if (args[0] == "-auth") {
00499
00500 AuthInfo auth;
00501 if (SheppObjSet::authInfo(auth, args) != 0) {
00502 return cmd_contact_help("invalid auth", cmd_name);
00503 }
00504
00505
00506 if (auth.get_roid_f() == true) {
00507 return cmd_contact_help("invalid auth", cmd_name);
00508 }
00509
00510 cmd->set_authInfo(auth);
00511 } else if (args[0] == "-disclose") {
00512
00513 args.erase(args.begin());
00514 CommonData::Disclose disclose;
00515
00516 if (args[0] != "0" && args[0] != "1") {
00517 return cmd_contact_help("disclose flag must be '0' or '1'", cmd_name);
00518 }
00519 disclose.flag = atoi(args[0].c_str());
00520 args.erase(args.begin());
00521
00522 if (SheppObjSet::disclose(disclose, args[0]) != 0) {
00523 return cmd_contact_help("invalid diclose information", cmd_name);
00524 }
00525 args.erase(args.begin());
00526 common_data.set_disclose(disclose);
00527 } else {
00528 return cmd_contact_help("invalid syntax near \"" + args[0] + "\"",
00529 cmd_name);
00530 }
00531 }
00532
00533 if (cmd->get_status_list_add().empty() &&
00534 cmd->get_status_list_rem().empty() &&
00535 common_data.get_postal_info().empty() &&
00536 common_data.get_voice().number == "" &&
00537 common_data.get_fax().number == "" &&
00538 common_data.get_email() == "" &&
00539 cmd->get_authInfo().get_pw() == "" &&
00540 !common_data.get_disclose().is_set()) {
00541 return cmd_contact_help("you didn't set a thing", cmd_name);
00542 }
00543
00544 cmd->set_common_data(common_data);
00545
00546 if (_debug) {
00547 printf(" contact id: [%s]\n", cmd->get_common_data().get_id().c_str());
00548
00549 set<string> status = cmd->get_status_list_add();
00550 set<string>::const_iterator st_it;
00551 if (!status.empty()) {
00552 printf(" status to add: [ ");
00553 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00554 printf("%s ", (*st_it).c_str());
00555 }
00556 printf("]\n");
00557 }
00558
00559 status = cmd->get_status_list_rem();
00560 if (!status.empty()) {
00561 printf(" status to rem: [ ");
00562 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00563 printf("%s ", (*st_it).c_str());
00564 }
00565 printf("]\n");
00566 }
00567
00568 vector<PostalInfo>::const_iterator it;
00569 vector<PostalInfo> postal_list;
00570 postal_list = cmd->get_common_data().get_postal_info();
00571 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00572 SheppPrint::postal_info((*it));
00573 }
00574
00575 if (cmd->get_common_data().get_voice_f()) {
00576 printf(" voice:");
00577 SheppPrint::phone(cmd->get_common_data().get_voice());
00578 }
00579
00580 if (cmd->get_common_data().get_fax_f()) {
00581 printf(" fax :");
00582 SheppPrint::phone(cmd->get_common_data().get_fax());
00583 }
00584
00585 if (cmd->get_common_data().get_email_f()) {
00586 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00587 }
00588
00589 if (cmd->get_authInfo().get_pw() != "") {
00590 SheppPrint::authInfo(cmd->get_authInfo());
00591 }
00592
00593 if (cmd->get_common_data().get_disclose().is_set()) {
00594 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00595 }
00596 }
00597
00598 if (process_action(act) != 0) {
00599 return -1;
00600 }
00601
00602 return 0;
00603 }
00604
00606
00610 int cmd_contact(vector<string> &args)
00611 {
00612
00613 if (!args.empty() && !(args[0] == "help")) {
00614 if (args[0] == "check") {
00615 args.erase(args.begin());
00616 return cmd_contact_check(args);
00617 } else if (args[0] == "info") {
00618 args.erase(args.begin());
00619 return cmd_contact_info(args);
00620 } else if (args[0] == "transfer") {
00621 args.erase(args.begin());
00622 return cmd_contact_transfer(args);
00623 } else if (args[0] == "create") {
00624 args.erase(args.begin());
00625 return cmd_contact_create(args);
00626 } else if (args[0] == "delete") {
00627 args.erase(args.begin());
00628 return cmd_contact_delete(args);
00629 } else if (args[0] == "renew") {
00630 args.erase(args.begin());
00631 return cmd_contact_renew(args);
00632 } else if (args[0] == "update") {
00633 args.erase(args.begin());
00634 return cmd_contact_update(args);
00635 } else {
00636 return cmd_contact_help("invalid command: contact " + args[0]);
00637 }
00638 }
00639
00640 return cmd_contact_help("");
00641 }
00642
00643 #endif //__CONTACT_FUNCTIONS_H__