00001
00002
00006 #ifndef __BRORG_FUNCTIONS_H__
00007 #define __BRORG_FUNCTIONS_H__
00008 #include "SheppCommandFunctions.H"
00009
00010 #include "BrOrgCheck.H"
00011 #include "BrOrgInfo.H"
00012 #include "BrOrgCreate.H"
00013 #include "BrOrgUpdate.H"
00014
00016
00021 int cmd_brorg_help(string error_msg, string specific = "")
00022 {
00023 if (error_msg != "") {
00024 printf("error: %s\n", error_msg.c_str());
00025 }
00026
00027 printf("brorg command syntax help:\n");
00028 printf("\n");
00029
00030 if (specific == "" || specific == "check") {
00031 printf(" check <id1:brorg1> [id2:brorg2 ... idN:brorgN]\n");
00032 printf("\n");
00033 }
00034 if (specific == "" || specific == "info") {
00035 printf(" info <id:brorg> [-auth authInfoPw[:authInfoRoid]]\n");
00036 printf("\n");
00037 }
00038 if (specific == "" || specific == "transfer") {
00039 printf(" transfer: not implemented\n");
00040 printf("\n");
00041 }
00042 if (specific == "" || specific == "create") {
00043 printf(" create <brorg>\n");
00044 printf(" [-postalInfo <type> <-name \"BrOrg Name\"> "
00045 "[-org \"Org Name\"]\n");
00046 printf(" <-street1 \"address line 1\"> "
00047 "[-street2 \"address line 2\"]\n");
00048 printf(" [-street3 \"address line 3\"] <-city \"City Name\"> "
00049 "[-state \"State or Province\"]\n");
00050 printf(" [-pc \"postal code\"] <-cc country-code> ...]\n");
00051 printf(" [-voice number:ext] [-fax number:ext]\n");
00052 printf(" <-email emailAddr> <-auth authInfoPw[:authInfoRoid]> "
00053 "[-disclose opt,opt,...]\n");
00054 printf(" <-orgid orgid> <-contact key=value[,key=value,...]>\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 <brorg> [-add-status st1,...,stN] "
00071 "[-rem-status st1,...,stN]\n");
00072 printf(" [-postalInfo <type> [-name \"BrOrg Name\"] "
00073 "[-org \"Org Name\"]\n");
00074 printf(" [-street1 \"address line 1\"] "
00075 "[-street2 \"address 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[:authInfoRoid]] "
00081 "[-disclose opt,opt,...]\n");
00082 printf(" [-orgid orgid [-add-contact key=value[,key=value,...]\n");
00083 printf(" [-rem-contact key=value[,key=value,...]]\n");
00084 printf("\n");
00085 printf(" available values for opt:\n");
00086 printf(" {name_int name_loc org_int org_loc addr_int addr_loc "
00087 "voice fax email}\n");
00088 printf("\n");
00089 }
00090
00091 if (error_msg != "") {
00092 return -1;
00093 }
00094
00095 return 0;
00096 }
00097
00099
00103 int cmd_brorg_check(vector<string> words)
00104 {
00105 BrOrgCheck act;
00106 BrOrgCheckCmd *cmd = act.get_command();
00107 string cmd_name = "check";
00108
00109 while (!words.empty()) {
00110 string id;
00111 string org;
00112 if (SheppStrUtil::split(words[0], id, org, ":", false) != 0) {
00113 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00114 cmd_name);
00115 }
00116
00117 cmd->insert_id(id);
00118 cmd->insert_organization(id, org);
00119
00120 words.erase(words.begin());
00121 }
00122
00123 if (cmd->get_id_list().empty() || cmd->get_organization_list().empty()) {
00124 return cmd_brorg_help("no brorg specified", cmd_name);
00125 }
00126
00127 if (_debug) {
00128 map<string, string, less<string> > brorgs = cmd->get_organization_list();
00129 map<string, string, less<string> >::const_iterator it;
00130 printf("brorgs to be checked:\n");
00131 for (it = brorgs.begin(); it != brorgs.end(); it++) {
00132 printf(" id: [%s] org: [%s]\n", (*it).first.c_str(),
00133 (*it).second.c_str());
00134 }
00135 }
00136
00137 if (process_action(act) != 0) {
00138 return -1;
00139 }
00140
00141 return 0;
00142 }
00143
00145
00149 int cmd_brorg_info(vector<string> words)
00150 {
00151 BrOrgInfo act;
00152 BrOrgInfoCmd *cmd = act.get_command();
00153 string cmd_name = "info";
00154
00155 string id;
00156 string org;
00157 if (words.empty() ||
00158 SheppStrUtil::split(words[0], id, org, ":", false) != 0) {
00159 return cmd_brorg_help("no brorg specified", cmd_name);
00160 }
00161
00162 cmd->set_id(id);
00163 cmd->set_organization(org);
00164 words.erase(words.begin());
00165
00166 while (!words.empty()) {
00167 if (words[0] == "-auth") {
00168
00169 AuthInfo auth;
00170 if (SheppObjSet::authInfo(auth, words) != 0) {
00171 return cmd_brorg_help("invalid auth", cmd_name);
00172 }
00173 cmd->set_authInfo(auth);
00174 } else {
00175 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00176 cmd_name);
00177 }
00178
00179 }
00180
00181 if (_debug) {
00182 printf("id to get info: [%s]\n", cmd->get_id().c_str());
00183 printf("org to get info: [%s]\n", cmd->get_organization().c_str());
00184 SheppPrint::authInfo(cmd->get_authInfo());
00185 }
00186
00187 if (process_action(act) != 0) {
00188 return -1;
00189 }
00190
00191 return 0;
00192 }
00193
00195
00199 int cmd_brorg_transfer(vector<string> words)
00200 {
00201 string cmd_name = "transfer";
00202 return cmd_brorg_help("", cmd_name);
00203 }
00204
00206
00210 int cmd_brorg_create(vector<string> words)
00211 {
00212 BrOrgCreate act;
00213 BrOrgCreateCmd *cmd = act.get_command();
00214 string cmd_name = "create";
00215
00216 if (words.empty()) {
00217 return cmd_brorg_help("no brorg specified", cmd_name);
00218 }
00219
00220 CommonData common_data;
00221
00222 common_data.set_id(words[0]);
00223 words.erase(words.begin());
00224
00225 while (!words.empty()) {
00226 if (words[0] == "-postalInfo") {
00227
00228 words.erase(words.begin());
00229 if (words.empty()) {
00230 return cmd_brorg_help("missing postal info arguments", cmd_name);
00231 }
00232 CommonData::PostalInfo postal;
00233 string error_msg;
00234 if (SheppObjSet::postalInfo(postal, words, error_msg, false) != 0) {
00235 return cmd_brorg_help(error_msg, cmd_name);
00236 }
00237 vector<CommonData::PostalInfo> postal_list
00238 = common_data.get_postal_info();
00239 vector<CommonData::PostalInfo>::const_iterator it;
00240 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00241 if ((*it).type == postal.type) {
00242 return cmd_brorg_help("duplicated postal info type", cmd_name);
00243 }
00244 }
00245 common_data.insert_postal_info(postal);
00246 } else if (words[0] == "-voice") {
00247
00248 words.erase(words.begin());
00249 CommonData::Phone phone;
00250 if (SheppObjSet::phone(phone, words) != 0) {
00251 return cmd_brorg_help("error setting voice telephone number",
00252 cmd_name);
00253 }
00254 common_data.set_voice(phone);
00255 } else if (words[0] == "-fax") {
00256
00257 words.erase(words.begin());
00258 CommonData::Phone phone;
00259 if (SheppObjSet::phone(phone, words) != 0) {
00260 return cmd_brorg_help("error setting fax telephone number",
00261 cmd_name);
00262 }
00263 common_data.set_fax(phone);
00264 } else if (words[0] == "-email") {
00265
00266 words.erase(words.begin());
00267 if (words.empty()) {
00268 return cmd_brorg_help("no e-mail address specified", cmd_name);
00269 }
00270 common_data.set_email(words[0]);
00271 words.erase(words.begin());
00272 } else if (words[0] == "-auth") {
00273
00274 AuthInfo auth;
00275 if (SheppObjSet::authInfo(auth, words) != 0) {
00276 return cmd_brorg_help("invalid auth", cmd_name);
00277 }
00278 cmd->set_authInfo(auth);
00279 } else if (words[0] == "-disclose") {
00280
00281 words.erase(words.begin());
00282 CommonData::Disclose disclose;
00283 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00284 return cmd_brorg_help("invalid diclose information", cmd_name);
00285 }
00286 words.erase(words.begin());
00287 common_data.set_disclose(disclose);
00288 } else if (words[0] == "-orgid") {
00289
00290 words.erase(words.begin());
00291 if (words.empty()) {
00292 return cmd_brorg_help("no orgid specified", cmd_name);
00293 }
00294 cmd->set_organization(words[0]);
00295 words.erase(words.begin());
00296 } else if (words[0] == "-contact") {
00297
00298 words.erase(words.begin());
00299 if (words.empty()) {
00300 return cmd_brorg_help("-contact requires an argument", cmd_name);
00301 }
00302 map<string, string, less<string> > my_contacts;
00303 string error_msg;
00304 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00305 return cmd_brorg_help(error_msg, cmd_name);
00306 }
00307 map<string, string, less<string> >::const_iterator it;
00308 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00309 cmd->insert_contact((*it).first, (*it).second);
00310 }
00311 words.erase(words.begin());
00312 } else {
00313 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00314 cmd_name);
00315 }
00316 }
00317
00318 if (common_data.get_postal_info().empty()) {
00319 return cmd_brorg_help("at least one postal info must be entered",
00320 cmd_name);
00321 }
00322
00323 if (common_data.get_email() == "") {
00324 return cmd_brorg_help("e-mail is mandatory", cmd_name);
00325 }
00326
00327 if (cmd->get_authInfo().get_pw() == "") {
00328 return cmd_brorg_help("auth info is mandatory", cmd_name);
00329 }
00330
00331 if (cmd->get_organization() == "") {
00332 return cmd_brorg_help("orgid unset", cmd_name);
00333 }
00334
00335 if (cmd->get_contact_list().empty()) {
00336 return cmd_brorg_help("at least one contact must be entered", cmd_name);
00337 }
00338
00339 cmd->set_common_data(common_data);
00340
00341 if (_debug) {
00342 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00343
00344 vector<CommonData::PostalInfo>::const_iterator it;
00345 vector<CommonData::PostalInfo> postal_list;
00346 postal_list = cmd->get_common_data().get_postal_info();
00347 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00348 SheppPrint::postal_info((*it));
00349 }
00350
00351 if (cmd->get_common_data().get_voice().number != "") {
00352 printf(" voice:");
00353 SheppPrint::phone(cmd->get_common_data().get_voice());
00354 }
00355
00356 if (cmd->get_common_data().get_fax().number != "") {
00357 printf(" fax :");
00358 SheppPrint::phone(cmd->get_common_data().get_fax());
00359 }
00360
00361 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00362
00363 SheppPrint::authInfo(cmd->get_authInfo());
00364
00365 if (cmd->get_common_data().get_disclose().is_set()) {
00366 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00367 }
00368
00369
00370 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00371
00372 map<string, string, less<string> > contacts = cmd->get_contact_list();
00373 map<string, string, less<string> >::const_iterator c_it;
00374 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00375 printf(" contact[%s] = [%s]\n", (*c_it).first.c_str(),
00376 (*c_it).second.c_str());
00377 }
00378 }
00379
00380 if (process_action(act) != 0) {
00381 return -1;
00382 }
00383
00384 return 0;
00385 }
00386
00388
00392 int cmd_brorg_delete(vector<string> words)
00393 {
00394 string cmd_name = "delete";
00395 return cmd_brorg_help("", cmd_name);
00396 }
00397
00399
00403 int cmd_brorg_renew(vector<string> words)
00404 {
00405 string cmd_name = "renew";
00406 return cmd_brorg_help("", cmd_name);
00407 }
00408
00410
00414 int cmd_brorg_update(vector<string> words)
00415 {
00416 BrOrgUpdate act;
00417 BrOrgUpdateCmd *cmd = act.get_command();
00418 string cmd_name = "update";
00419
00420 if (words.empty()) {
00421 return cmd_brorg_help("no brorg specified", cmd_name);
00422 }
00423
00424 CommonData common_data;
00425
00426 common_data.set_id(words[0]);
00427 words.erase(words.begin());
00428
00429 while (!words.empty()) {
00430 if (words[0] == "-add-status") {
00431
00432 words.erase(words.begin());
00433 if (words.empty()) {
00434 return cmd_brorg_help("error setting add-status", cmd_name);
00435 }
00436 string tmp1 = words[0];
00437 string tmp2;
00438 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00439 cmd->insert_status_list_add(tmp1);
00440 if (tmp2 == "") {
00441 break;
00442 }
00443 tmp1 = tmp2;
00444 }
00445 cmd->set_chg(true);
00446 words.erase(words.begin());
00447 } else if (words[0] == "-rem-status") {
00448
00449 words.erase(words.begin());
00450 if (words.empty()) {
00451 return cmd_brorg_help("error setting rem-status", cmd_name);
00452 }
00453 string tmp1 = words[0];
00454 string tmp2;
00455 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00456 cmd->insert_status_list_rem(tmp1);
00457 if (tmp2 == "") {
00458 break;
00459 }
00460 tmp1 = tmp2;
00461 }
00462 cmd->set_chg(true);
00463 words.erase(words.begin());
00464 } else if (words[0] == "-postalInfo") {
00465
00466 words.erase(words.begin());
00467 if (words.empty()) {
00468 return cmd_brorg_help("missing postal info arguments", cmd_name);
00469 }
00470 CommonData::PostalInfo postal;
00471 string error_msg;
00472 if (SheppObjSet::postalInfo(postal, words, error_msg, true) != 0) {
00473 return cmd_brorg_help(error_msg, cmd_name);
00474 }
00475 vector<CommonData::PostalInfo> postal_list
00476 = common_data.get_postal_info();
00477 vector<CommonData::PostalInfo>::const_iterator it;
00478 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00479 if ((*it).type == postal.type) {
00480 return cmd_brorg_help("duplicated postal info type", cmd_name);
00481 }
00482 }
00483 common_data.insert_postal_info(postal);
00484 } else if (words[0] == "-voice") {
00485
00486 words.erase(words.begin());
00487 CommonData::Phone phone;
00488 if (SheppObjSet::phone(phone, words) != 0) {
00489 return cmd_brorg_help("error setting voice telephone number",
00490 cmd_name);
00491 }
00492 common_data.set_voice(phone);
00493 } else if (words[0] == "-fax") {
00494
00495 words.erase(words.begin());
00496 CommonData::Phone phone;
00497 if (SheppObjSet::phone(phone, words) != 0) {
00498 return cmd_brorg_help("error setting fax telephone number",
00499 cmd_name);
00500 }
00501 common_data.set_fax(phone);
00502 } else if (words[0] == "-email") {
00503
00504 words.erase(words.begin());
00505 if (words.empty()) {
00506 return cmd_brorg_help("no e-mail address specified", cmd_name);
00507 }
00508 common_data.set_email(words[0]);
00509 words.erase(words.begin());
00510 } else if (words[0] == "-auth") {
00511
00512 AuthInfo auth;
00513 if (SheppObjSet::authInfo(auth, words) != 0) {
00514 return cmd_brorg_help("invalid auth", cmd_name);
00515 }
00516 cmd->set_authInfo(auth);
00517 } else if (words[0] == "-disclose") {
00518
00519 words.erase(words.begin());
00520 CommonData::Disclose disclose;
00521 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00522 return cmd_brorg_help("invalid diclose information", cmd_name);
00523 }
00524 words.erase(words.begin());
00525 common_data.set_disclose(disclose);
00526 } else if (words[0] == "-orgid") {
00527
00528 words.erase(words.begin());
00529 if (words.empty()) {
00530 return cmd_brorg_help("no orgid specified", cmd_name);
00531 }
00532 cmd->set_organization(words[0]);
00533 words.erase(words.begin());
00534 while (!words.empty()) {
00535 if (words[0] == "-add-contact") {
00536
00537 words.erase(words.begin());
00538 if (words.empty()) {
00539 return cmd_brorg_help("-add-contact requires an argument",
00540 cmd_name);
00541 }
00542 map<string, string, less<string> > my_contacts;
00543 string error_msg;
00544 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00545 return cmd_brorg_help(error_msg, cmd_name);
00546 }
00547 map<string, string, less<string> >::const_iterator it;
00548 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00549 cmd->insert_contact_add((*it).first, (*it).second);
00550 }
00551 words.erase(words.begin());
00552 } else if (words[0] == "-rem-contact") {
00553
00554 words.erase(words.begin());
00555 if (words.empty()) {
00556 return cmd_brorg_help("-rem-contact requires an argument",
00557 cmd_name);
00558 }
00559 map<string, string, less<string> > my_contacts;
00560 string error_msg;
00561 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00562 return cmd_brorg_help(error_msg, cmd_name);
00563 }
00564 map<string, string, less<string> >::const_iterator it;
00565 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00566 cmd->insert_contact_rem((*it).first, (*it).second);
00567 }
00568 words.erase(words.begin());
00569 } else {
00570 break;
00571 }
00572 }
00573 if (cmd->get_contact_list_add().empty() &&
00574 cmd->get_contact_list_rem().empty()) {
00575 return cmd_brorg_help("you didn't enter contacts to add or remove",
00576 cmd_name);
00577 }
00578 } else {
00579 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00580 cmd_name);
00581 }
00582 }
00583
00584 if (cmd->get_status_list_add().empty() &&
00585 cmd->get_status_list_rem().empty() &&
00586 common_data.get_postal_info().empty() &&
00587 common_data.get_voice().number == "" &&
00588 common_data.get_fax().number == "" &&
00589 common_data.get_email() == "" &&
00590 cmd->get_authInfo().get_pw() == "" &&
00591 !common_data.get_disclose().is_set() &&
00592 cmd->get_organization() == "") {
00593 return cmd_brorg_help("not enough information for update", cmd_name);
00594 }
00595
00596 cmd->set_common_data(common_data);
00597
00598 if (_debug) {
00599 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00600
00601 set<string> status = cmd->get_status_list_add();
00602 set<string>::const_iterator st_it;
00603 if (!status.empty()) {
00604 printf(" status to add: [ ");
00605 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00606 printf("%s ", (*st_it).c_str());
00607 }
00608 printf("]\n");
00609 }
00610
00611 status = cmd->get_status_list_rem();
00612 if (!status.empty()) {
00613 printf(" status to rem: [ ");
00614 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00615 printf("%s ", (*st_it).c_str());
00616 }
00617 printf("]\n");
00618 }
00619
00620 vector<CommonData::PostalInfo>::const_iterator it;
00621 vector<CommonData::PostalInfo> postal_list;
00622 postal_list = cmd->get_common_data().get_postal_info();
00623 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00624 SheppPrint::postal_info((*it));
00625 }
00626
00627 if (cmd->get_common_data().get_voice().number != "") {
00628 printf(" voice:");
00629 SheppPrint::phone(cmd->get_common_data().get_voice());
00630 }
00631
00632 if (cmd->get_common_data().get_fax().number != "") {
00633 printf(" fax :");
00634 SheppPrint::phone(cmd->get_common_data().get_fax());
00635 }
00636
00637 if (cmd->get_common_data().get_email() != "") {
00638 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00639 }
00640
00641 if (cmd->get_authInfo().get_pw() != "") {
00642 SheppPrint::authInfo(cmd->get_authInfo());
00643 }
00644
00645 if (cmd->get_common_data().get_disclose().is_set()) {
00646 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00647 }
00648
00649
00650 if (cmd->get_organization() != "") {
00651 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00652
00653 map<string, string, less<string> > contacts =
00654 cmd->get_contact_list_add();
00655 map<string, string, less<string> >::const_iterator c_it;
00656 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00657 printf(" contact to add [%s] = [%s]\n", (*c_it).first.c_str(),
00658 (*c_it).second.c_str());
00659 }
00660
00661 contacts = cmd->get_contact_list_rem();
00662 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00663 printf(" contact to rem [%s] = [%s]\n", (*c_it).first.c_str(),
00664 (*c_it).second.c_str());
00665 }
00666 }
00667 }
00668
00669 if (process_action(act) != 0) {
00670 return -1;
00671 }
00672
00673 return 0;
00674 }
00675
00677
00681 int cmd_brorg(char *arg)
00682 {
00683 if (strlen(arg) > 0) {
00684 vector<string> words = SheppStrUtil::parse_line(arg);
00685
00686
00687 if (!words.empty() && !(words[0] == "help")) {
00688 if (words[0] == "check") {
00689 words.erase(words.begin());
00690 return cmd_brorg_check(words);
00691 } else if (words[0] == "info") {
00692 words.erase(words.begin());
00693 return cmd_brorg_info(words);
00694 } else if (words[0] == "transfer") {
00695 words.erase(words.begin());
00696 return cmd_brorg_transfer(words);
00697 } else if (words[0] == "create") {
00698 words.erase(words.begin());
00699 return cmd_brorg_create(words);
00700 } else if (words[0] == "delete") {
00701 words.erase(words.begin());
00702 return cmd_brorg_delete(words);
00703 } else if (words[0] == "renew") {
00704 words.erase(words.begin());
00705 return cmd_brorg_renew(words);
00706 } else if (words[0] == "update") {
00707 words.erase(words.begin());
00708 return cmd_brorg_update(words);
00709 } else {
00710 return cmd_brorg_help("invalid command: brorg " + words[0]);
00711 }
00712 }
00713 }
00714
00715 return cmd_brorg_help("");
00716 }
00717
00718 #endif //__BRORG_FUNCTIONS_H__