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 <brorg1> [brorg2 ... brorgN]\n");
00032 printf("\n");
00033 }
00034 if (specific == "" || specific == "info") {
00035 printf(" info <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(" [-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 string id;
00110 int counter = 0;
00111 while (!words.empty()) {
00112 id = "SHEPP" + StrUtil::to_string("%d", counter);
00113 cmd->insert_id(id);
00114 cmd->insert_organization(id, words[0]);
00115 words.erase(words.begin());
00116 counter++;
00117 }
00118
00119 if (cmd->get_id_list().empty() || cmd->get_organization_list().empty()) {
00120 return cmd_brorg_help("no brorg specified", cmd_name);
00121 }
00122
00123 if (_debug) {
00124 map<string, string, less<string> > brorgs = cmd->get_organization_list();
00125 map<string, string, less<string> >::const_iterator it;
00126 printf("brorgs to be checked:\n");
00127 for (it = brorgs.begin(); it != brorgs.end(); it++) {
00128 printf(" id: [%s] org: [%s]\n", (*it).first.c_str(),
00129 (*it).second.c_str());
00130 }
00131 }
00132
00133 if (process_action(act) != 0) {
00134 return -1;
00135 }
00136
00137 return 0;
00138 }
00139
00141
00145 int cmd_brorg_info(vector<string> words)
00146 {
00147 BrOrgInfo act;
00148 BrOrgInfoCmd *cmd = act.get_command();
00149 string cmd_name = "info";
00150
00151 if (words.empty()) {
00152 return cmd_brorg_help("no brorg specified", cmd_name);
00153 }
00154
00155 cmd->set_id("SHEPP");
00156 cmd->set_organization(words[0]);
00157 words.erase(words.begin());
00158
00159 while (!words.empty()) {
00160 if (words[0] == "-auth") {
00161
00162 AuthInfo auth;
00163 if (SheppObjSet::authInfo(auth, words) != 0) {
00164 return cmd_brorg_help("invalid auth", cmd_name);
00165 }
00166 cmd->set_authInfo(auth);
00167 } else {
00168 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00169 cmd_name);
00170 }
00171
00172 }
00173
00174 if (_debug) {
00175 printf("id to get info: [%s]\n", cmd->get_id().c_str());
00176 printf("org to get info: [%s]\n", cmd->get_organization().c_str());
00177 SheppPrint::authInfo(cmd->get_authInfo());
00178 }
00179
00180 if (process_action(act) != 0) {
00181 return -1;
00182 }
00183
00184 return 0;
00185 }
00186
00188
00192 int cmd_brorg_transfer(vector<string> words)
00193 {
00194 string cmd_name = "transfer";
00195 return cmd_brorg_help("", cmd_name);
00196 }
00197
00199
00203 int cmd_brorg_create(vector<string> words)
00204 {
00205 BrOrgCreate act;
00206 BrOrgCreateCmd *cmd = act.get_command();
00207 string cmd_name = "create";
00208
00209 if (words.empty()) {
00210 return cmd_brorg_help("no brorg specified", cmd_name);
00211 }
00212
00213 CommonData common_data;
00214
00215 common_data.set_id(words[0]);
00216 words.erase(words.begin());
00217
00218 while (!words.empty()) {
00219 if (words[0] == "-postalInfo") {
00220
00221 words.erase(words.begin());
00222 if (words.empty()) {
00223 return cmd_brorg_help("missing postal info arguments", cmd_name);
00224 }
00225 PostalInfo postal;
00226 string error_msg;
00227 if (SheppObjSet::postalInfo(postal, words, error_msg, false) != 0) {
00228 return cmd_brorg_help(error_msg, cmd_name);
00229 }
00230 vector<PostalInfo> postal_list = common_data.get_postal_info();
00231 for (int i = 0; i < (int) postal_list.size(); i++) {
00232 if (postal_list[i].get_type() == postal.get_type()) {
00233 return cmd_brorg_help("duplicated postal info type", cmd_name);
00234 }
00235 }
00236 common_data.insert_postal_info(postal);
00237 } else if (words[0] == "-voice") {
00238
00239 words.erase(words.begin());
00240 CommonData::Phone phone;
00241 if (SheppObjSet::phone(phone, words) != 0) {
00242 return cmd_brorg_help("error setting voice telephone number",
00243 cmd_name);
00244 }
00245 common_data.set_voice(phone);
00246 } else if (words[0] == "-fax") {
00247
00248 words.erase(words.begin());
00249 CommonData::Phone phone;
00250 if (SheppObjSet::phone(phone, words) != 0) {
00251 return cmd_brorg_help("error setting fax telephone number",
00252 cmd_name);
00253 }
00254 common_data.set_fax(phone);
00255 } else if (words[0] == "-email") {
00256
00257 words.erase(words.begin());
00258 if (words.empty()) {
00259 return cmd_brorg_help("no e-mail address specified", cmd_name);
00260 }
00261 common_data.set_email(words[0]);
00262 words.erase(words.begin());
00263 } else if (words[0] == "-auth") {
00264
00265 AuthInfo auth;
00266 if (SheppObjSet::authInfo(auth, words) != 0) {
00267 return cmd_brorg_help("invalid auth", cmd_name);
00268 }
00269 cmd->set_authInfo(auth);
00270 } else if (words[0] == "-disclose") {
00271
00272 words.erase(words.begin());
00273 CommonData::Disclose disclose;
00274 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00275 return cmd_brorg_help("invalid diclose information", cmd_name);
00276 }
00277 words.erase(words.begin());
00278 common_data.set_disclose(disclose);
00279 } else if (words[0] == "-orgid") {
00280
00281 words.erase(words.begin());
00282 if (words.empty()) {
00283 return cmd_brorg_help("no orgid specified", cmd_name);
00284 }
00285 cmd->set_organization(words[0]);
00286 words.erase(words.begin());
00287 } else if (words[0] == "-contact") {
00288
00289 words.erase(words.begin());
00290 if (words.empty()) {
00291 return cmd_brorg_help("-contact requires an argument", cmd_name);
00292 }
00293 map<string, string, less<string> > my_contacts;
00294 string error_msg;
00295 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00296 return cmd_brorg_help(error_msg, cmd_name);
00297 }
00298 map<string, string, less<string> >::const_iterator it;
00299 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00300 cmd->insert_contact((*it).first, (*it).second);
00301 }
00302 words.erase(words.begin());
00303 } else {
00304 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00305 cmd_name);
00306 }
00307 }
00308
00309 if (common_data.get_postal_info().empty()) {
00310 return cmd_brorg_help("at least one postal info must be entered",
00311 cmd_name);
00312 }
00313
00314 if (common_data.get_email() == "") {
00315 return cmd_brorg_help("e-mail is mandatory", cmd_name);
00316 }
00317
00318 if (cmd->get_authInfo().get_pw() == "") {
00319 return cmd_brorg_help("auth info is mandatory", cmd_name);
00320 }
00321
00322 if (cmd->get_organization() == "") {
00323 return cmd_brorg_help("orgid unset", cmd_name);
00324 }
00325
00326 if (cmd->get_contact_list().empty()) {
00327 return cmd_brorg_help("at least one contact must be entered", cmd_name);
00328 }
00329
00330 cmd->set_common_data(common_data);
00331
00332 if (_debug) {
00333 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00334
00335 vector<PostalInfo>::const_iterator it;
00336 vector<PostalInfo> postal_list;
00337 postal_list = cmd->get_common_data().get_postal_info();
00338 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00339 SheppPrint::postal_info((*it));
00340 }
00341
00342 if (cmd->get_common_data().get_voice().number != "") {
00343 printf(" voice:");
00344 SheppPrint::phone(cmd->get_common_data().get_voice());
00345 }
00346
00347 if (cmd->get_common_data().get_fax().number != "") {
00348 printf(" fax :");
00349 SheppPrint::phone(cmd->get_common_data().get_fax());
00350 }
00351
00352 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00353
00354 SheppPrint::authInfo(cmd->get_authInfo());
00355
00356 if (cmd->get_common_data().get_disclose().is_set()) {
00357 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00358 }
00359
00360
00361 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00362
00363 map<string, string, less<string> > contacts = cmd->get_contact_list();
00364 map<string, string, less<string> >::const_iterator c_it;
00365 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00366 printf(" contact[%s] = [%s]\n", (*c_it).first.c_str(),
00367 (*c_it).second.c_str());
00368 }
00369 }
00370
00371 if (process_action(act) != 0) {
00372 return -1;
00373 }
00374
00375 return 0;
00376 }
00377
00379
00383 int cmd_brorg_delete(vector<string> words)
00384 {
00385 string cmd_name = "delete";
00386 return cmd_brorg_help("", cmd_name);
00387 }
00388
00390
00394 int cmd_brorg_renew(vector<string> words)
00395 {
00396 string cmd_name = "renew";
00397 return cmd_brorg_help("", cmd_name);
00398 }
00399
00401
00405 int cmd_brorg_update(vector<string> words)
00406 {
00407 BrOrgUpdate act;
00408 BrOrgUpdateCmd *cmd = act.get_command();
00409 string cmd_name = "update";
00410
00411 if (words.empty()) {
00412 return cmd_brorg_help("no brorg specified", cmd_name);
00413 }
00414
00415 CommonData common_data;
00416 common_data.set_id("SHEPP");
00417
00418 cmd->set_organization(words[0]);
00419 words.erase(words.begin());
00420
00421 while (!words.empty()) {
00422 if (words[0] == "-add-status") {
00423
00424 words.erase(words.begin());
00425 if (words.empty()) {
00426 return cmd_brorg_help("error setting add-status", cmd_name);
00427 }
00428 string tmp1 = words[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 words.erase(words.begin());
00438 } else if (words[0] == "-rem-status") {
00439
00440 words.erase(words.begin());
00441 if (words.empty()) {
00442 return cmd_brorg_help("error setting rem-status", cmd_name);
00443 }
00444 string tmp1 = words[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 words.erase(words.begin());
00454 } else if (words[0] == "-postalInfo") {
00455
00456 words.erase(words.begin());
00457 if (words.empty()) {
00458 return cmd_brorg_help("missing postal info arguments", cmd_name);
00459 }
00460 PostalInfo postal;
00461 string error_msg;
00462 if (SheppObjSet::postalInfo(postal, words, error_msg, true) != 0) {
00463 return cmd_brorg_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_brorg_help("duplicated postal info type", cmd_name);
00469 }
00470 }
00471 common_data.insert_postal_info(postal);
00472 } else if (words[0] == "-voice") {
00473
00474 words.erase(words.begin());
00475 CommonData::Phone phone;
00476 if (SheppObjSet::phone(phone, words) != 0) {
00477 return cmd_brorg_help("error setting voice telephone number",
00478 cmd_name);
00479 }
00480 common_data.set_voice(phone);
00481 } else if (words[0] == "-fax") {
00482
00483 words.erase(words.begin());
00484 CommonData::Phone phone;
00485 if (SheppObjSet::phone(phone, words) != 0) {
00486 return cmd_brorg_help("error setting fax telephone number",
00487 cmd_name);
00488 }
00489 common_data.set_fax(phone);
00490 } else if (words[0] == "-email") {
00491
00492 words.erase(words.begin());
00493 if (words.empty()) {
00494 return cmd_brorg_help("no e-mail address specified", cmd_name);
00495 }
00496 common_data.set_email(words[0]);
00497 words.erase(words.begin());
00498 } else if (words[0] == "-auth") {
00499
00500 AuthInfo auth;
00501 if (SheppObjSet::authInfo(auth, words) != 0) {
00502 return cmd_brorg_help("invalid auth", cmd_name);
00503 }
00504 cmd->set_authInfo(auth);
00505 } else if (words[0] == "-disclose") {
00506
00507 words.erase(words.begin());
00508 CommonData::Disclose disclose;
00509 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00510 return cmd_brorg_help("invalid diclose information", cmd_name);
00511 }
00512 words.erase(words.begin());
00513 common_data.set_disclose(disclose);
00514 } else if (words[0] == "-add-contact") {
00515
00516 words.erase(words.begin());
00517 if (words.empty()) {
00518 return cmd_brorg_help("-add-contact requires an argument",
00519 cmd_name);
00520 }
00521 map<string, string, less<string> > my_contacts;
00522 string error_msg;
00523 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00524 return cmd_brorg_help(error_msg, cmd_name);
00525 }
00526 map<string, string, less<string> >::const_iterator it;
00527 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00528 cmd->insert_contact_add((*it).first, (*it).second);
00529 }
00530 words.erase(words.begin());
00531 } else if (words[0] == "-rem-contact") {
00532
00533 words.erase(words.begin());
00534 if (words.empty()) {
00535 return cmd_brorg_help("-rem-contact requires an argument",
00536 cmd_name);
00537 }
00538 map<string, string, less<string> > my_contacts;
00539 string error_msg;
00540 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00541 return cmd_brorg_help(error_msg, cmd_name);
00542 }
00543 map<string, string, less<string> >::const_iterator it;
00544 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00545 cmd->insert_contact_rem((*it).first, (*it).second);
00546 }
00547 words.erase(words.begin());
00548 } else {
00549 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00550 cmd_name);
00551 }
00552 }
00553
00554 if (cmd->get_status_list_add().empty() &&
00555 cmd->get_status_list_rem().empty() &&
00556 common_data.get_postal_info().empty() &&
00557 common_data.get_voice().number == "" &&
00558 common_data.get_fax().number == "" &&
00559 common_data.get_email() == "" &&
00560 cmd->get_authInfo().get_pw() == "" &&
00561 !common_data.get_disclose().is_set() &&
00562 cmd->get_organization() == "") {
00563 return cmd_brorg_help("not enough information for update", cmd_name);
00564 }
00565
00566 cmd->set_common_data(common_data);
00567
00568 if (_debug) {
00569 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00570
00571 set<string> status = cmd->get_status_list_add();
00572 set<string>::const_iterator st_it;
00573 if (!status.empty()) {
00574 printf(" status to add: [ ");
00575 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00576 printf("%s ", (*st_it).c_str());
00577 }
00578 printf("]\n");
00579 }
00580
00581 status = cmd->get_status_list_rem();
00582 if (!status.empty()) {
00583 printf(" status to rem: [ ");
00584 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00585 printf("%s ", (*st_it).c_str());
00586 }
00587 printf("]\n");
00588 }
00589
00590 vector<PostalInfo> postal_list;
00591 postal_list = cmd->get_common_data().get_postal_info();
00592 for (int i = 0; i < (int) postal_list.size(); i++) {
00593 SheppPrint::postal_info(postal_list[i]);
00594 }
00595
00596 if (cmd->get_common_data().get_voice().number != "") {
00597 printf(" voice:");
00598 SheppPrint::phone(cmd->get_common_data().get_voice());
00599 }
00600
00601 if (cmd->get_common_data().get_fax().number != "") {
00602 printf(" fax :");
00603 SheppPrint::phone(cmd->get_common_data().get_fax());
00604 }
00605
00606 if (cmd->get_common_data().get_email() != "") {
00607 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00608 }
00609
00610 if (cmd->get_authInfo().get_pw() != "") {
00611 SheppPrint::authInfo(cmd->get_authInfo());
00612 }
00613
00614 if (cmd->get_common_data().get_disclose().is_set()) {
00615 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00616 }
00617
00618
00619 if (cmd->get_organization() != "") {
00620 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00621
00622 map<string, string, less<string> > contacts =
00623 cmd->get_contact_list_add();
00624 map<string, string, less<string> >::const_iterator c_it;
00625 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00626 printf(" contact to add [%s] = [%s]\n", (*c_it).first.c_str(),
00627 (*c_it).second.c_str());
00628 }
00629
00630 contacts = cmd->get_contact_list_rem();
00631 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00632 printf(" contact to rem [%s] = [%s]\n", (*c_it).first.c_str(),
00633 (*c_it).second.c_str());
00634 }
00635 }
00636 }
00637
00638 if (process_action(act) != 0) {
00639 return -1;
00640 }
00641
00642 return 0;
00643 }
00644
00646
00650 int cmd_brorg(char *arg)
00651 {
00652 if (strlen(arg) > 0) {
00653 vector<string> words = SheppStrUtil::parse_line(arg);
00654
00655
00656 if (!words.empty() && !(words[0] == "help")) {
00657 if (words[0] == "check") {
00658 words.erase(words.begin());
00659 return cmd_brorg_check(words);
00660 } else if (words[0] == "info") {
00661 words.erase(words.begin());
00662 return cmd_brorg_info(words);
00663 } else if (words[0] == "transfer") {
00664 words.erase(words.begin());
00665 return cmd_brorg_transfer(words);
00666 } else if (words[0] == "create") {
00667 words.erase(words.begin());
00668 return cmd_brorg_create(words);
00669 } else if (words[0] == "delete") {
00670 words.erase(words.begin());
00671 return cmd_brorg_delete(words);
00672 } else if (words[0] == "renew") {
00673 words.erase(words.begin());
00674 return cmd_brorg_renew(words);
00675 } else if (words[0] == "update") {
00676 words.erase(words.begin());
00677 return cmd_brorg_update(words);
00678 } else {
00679 return cmd_brorg_help("invalid command: brorg " + words[0]);
00680 }
00681 }
00682 }
00683
00684 return cmd_brorg_help("");
00685 }
00686
00687 #endif //__BRORG_FUNCTIONS_H__