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 street/line 1\"> "
00047 "[-street2 \"address number/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]]\n");
00053 printf(" [-disclose opt,opt,...] "
00054 " [-responsible \"Responsible Name\"]\n"
00055 " -contact key=value[,key=value,...]\n");
00056 printf("\n");
00057 printf(" available values for opt:\n");
00058 printf(" {name_int name_loc org_int org_loc addr_int addr_loc "
00059 "voice fax email}\n");
00060 printf("\n");
00061 }
00062 if (specific == "" || specific == "delete") {
00063 printf(" delete: not implemented\n");
00064 printf("\n");
00065 }
00066 if (specific == "" || specific == "renew") {
00067 printf(" renew: not implemented\n");
00068 printf("\n");
00069 }
00070 if (specific == "" || specific == "update") {
00071 printf(" update <brorg> [-add-status st1,...,stN] "
00072 "[-rem-status st1,...,stN]\n");
00073 printf(" [-postalInfo <type> [-name \"BrOrg Name\"] "
00074 "[-org \"Org Name\"]\n");
00075 printf(" [-street1 \"address street/line 1\"] "
00076 "[-street2 \"address number/line 2\"]\n");
00077 printf(" [-street3 \"address line 3\"] [-city \"City Name\"] "
00078 "[-state \"State or Province\"]\n");
00079 printf(" [-pc \"postal code\"] [-cc country-code] ...]\n");
00080 printf(" [-voice number:ext] [-fax number:ext]\n");
00081 printf(" [-email emailAddr] [-auth authInfoPw[:authInfoRoid]] "
00082 "[-disclose opt,opt,...]\n");
00083 printf(" [-responsible \"Responsible Name\"]\n");
00084 printf(" [-add-contact key=value[,key=value,...]\n");
00085 printf(" [-rem-contact key=value[,key=value,...]\n");
00086 printf("\n");
00087 printf(" available values for opt:\n");
00088 printf(" {name_int name_loc org_int org_loc addr_int addr_loc "
00089 "voice fax email}\n");
00090 printf("\n");
00091 }
00092
00093 if (error_msg != "") {
00094 return -1;
00095 }
00096
00097 return 0;
00098 }
00099
00101
00105 int cmd_brorg_check(vector<string> words)
00106 {
00107 BrOrgCheck act;
00108 BrOrgCheckCmd *cmd = act.get_command();
00109 string cmd_name = "check";
00110
00111 string id;
00112 int counter = 0;
00113 while (!words.empty()) {
00114 string numbers = SheppStrUtil::doc2id(words[0]);
00115 cmd->insert_id(numbers);
00116 cmd->insert_organization(numbers, words[0]);
00117 words.erase(words.begin());
00118 counter++;
00119 }
00120
00121 if (cmd->get_id_list().empty() || cmd->get_organization_list().empty()) {
00122 return cmd_brorg_help("no brorg specified", cmd_name);
00123 }
00124
00125 if (_debug) {
00126 map<string, string, less<string> > brorgs = cmd->get_organization_list();
00127 map<string, string, less<string> >::const_iterator it;
00128 printf("brorgs to be checked:\n");
00129 for (it = brorgs.begin(); it != brorgs.end(); it++) {
00130 printf(" id: [%s] org: [%s]\n", (*it).first.c_str(),
00131 (*it).second.c_str());
00132 }
00133 }
00134
00135 if (process_action(act) != 0) {
00136 return -1;
00137 }
00138
00139 return 0;
00140 }
00141
00143
00147 int cmd_brorg_info(vector<string> words)
00148 {
00149 BrOrgInfo act;
00150 BrOrgInfoCmd *cmd = act.get_command();
00151 string cmd_name = "info";
00152
00153 if (words.empty()) {
00154 return cmd_brorg_help("no brorg specified", cmd_name);
00155 }
00156
00157 cmd->set_id(SheppStrUtil::doc2id(words[0]));
00158 cmd->set_organization(words[0]);
00159 words.erase(words.begin());
00160
00161 while (!words.empty()) {
00162 if (words[0] == "-auth") {
00163
00164 AuthInfo auth;
00165 if (SheppObjSet::authInfo(auth, words) != 0) {
00166 return cmd_brorg_help("invalid auth", cmd_name);
00167 }
00168 cmd->set_authInfo(auth);
00169 } else {
00170 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00171 cmd_name);
00172 }
00173
00174 }
00175
00176 if (_debug) {
00177 printf("id to get info: [%s]\n", cmd->get_id().c_str());
00178 printf("org to get info: [%s]\n", cmd->get_organization().c_str());
00179 SheppPrint::authInfo(cmd->get_authInfo());
00180 }
00181
00182 if (process_action(act) != 0) {
00183 return -1;
00184 }
00185
00186 return 0;
00187 }
00188
00190
00194 int cmd_brorg_transfer(vector<string> words)
00195 {
00196 string cmd_name = "transfer";
00197 return cmd_brorg_help("", cmd_name);
00198 }
00199
00201
00205 int cmd_brorg_create(vector<string> words)
00206 {
00207 BrOrgCreate act;
00208 BrOrgCreateCmd *cmd = act.get_command();
00209 string cmd_name = "create";
00210
00211 if (words.empty()) {
00212 return cmd_brorg_help("no brorg specified", cmd_name);
00213 }
00214
00215 CommonData common_data;
00216
00217 common_data.set_id(SheppStrUtil::doc2id(words[0]));
00218 cmd->set_organization(words[0]);
00219
00220 words.erase(words.begin());
00221
00222
00223 AuthInfo auth;
00224 cmd->set_authInfo(auth);
00225
00226 while (!words.empty()) {
00227 if (words[0] == "-postalInfo") {
00228
00229 words.erase(words.begin());
00230 if (words.empty()) {
00231 return cmd_brorg_help("missing postal info arguments", cmd_name);
00232 }
00233 PostalInfo postal;
00234 string error_msg;
00235 if (SheppObjSet::postalInfo(postal, words, error_msg, false) != 0) {
00236 return cmd_brorg_help(error_msg, cmd_name);
00237 }
00238 vector<PostalInfo> postal_list = common_data.get_postal_info();
00239 for (int i = 0; i < (int) postal_list.size(); i++) {
00240 if (postal_list[i].get_type() == postal.get_type()) {
00241 return cmd_brorg_help("duplicated postal info type", cmd_name);
00242 }
00243 }
00244 common_data.insert_postal_info(postal);
00245 } else if (words[0] == "-voice") {
00246
00247 words.erase(words.begin());
00248 CommonData::Phone phone;
00249 if (SheppObjSet::phone(phone, words) != 0) {
00250 return cmd_brorg_help("error setting voice telephone number",
00251 cmd_name);
00252 }
00253 common_data.set_voice(phone);
00254 } else if (words[0] == "-fax") {
00255
00256 words.erase(words.begin());
00257 CommonData::Phone phone;
00258 if (SheppObjSet::phone(phone, words) != 0) {
00259 return cmd_brorg_help("error setting fax telephone number",
00260 cmd_name);
00261 }
00262 common_data.set_fax(phone);
00263 } else if (words[0] == "-email") {
00264
00265 words.erase(words.begin());
00266 if (words.empty()) {
00267 return cmd_brorg_help("no e-mail address specified", cmd_name);
00268 }
00269 common_data.set_email(words[0]);
00270 words.erase(words.begin());
00271 } else if (words[0] == "-auth") {
00272
00273 AuthInfo auth;
00274 if (SheppObjSet::authInfo(auth, words) != 0) {
00275 return cmd_brorg_help("invalid auth", cmd_name);
00276 }
00277 cmd->set_authInfo(auth);
00278 } else if (words[0] == "-disclose") {
00279
00280 words.erase(words.begin());
00281 CommonData::Disclose disclose;
00282 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00283 return cmd_brorg_help("invalid diclose information", cmd_name);
00284 }
00285 words.erase(words.begin());
00286 common_data.set_disclose(disclose);
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 if (words[0] == "-responsible") {
00304
00305 words.erase(words.begin());
00306 if (words.empty()) {
00307 return cmd_brorg_help("unspecified responsible name", cmd_name);
00308 }
00309 string responsible_name = words[0];
00310 words.erase(words.begin());
00311 if (SheppStrUtil::quote_gathering(words, responsible_name) != 0) {
00312 return cmd_brorg_help("error setting responsible name", cmd_name);
00313 }
00314 cmd->set_responsible(responsible_name);
00315 } else {
00316 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00317 cmd_name);
00318 }
00319 }
00320
00321 if (common_data.get_postal_info().empty()) {
00322 return cmd_brorg_help("at least one postal info must be entered",
00323 cmd_name);
00324 }
00325
00326 if (common_data.get_email() == "") {
00327 return cmd_brorg_help("e-mail is mandatory", cmd_name);
00328 }
00329
00330 if (common_data.get_voice().number == "") {
00331 return cmd_brorg_help("voice telephone number is mandatory", cmd_name);
00332 }
00333
00334 if (cmd->get_organization() == "") {
00335 return cmd_brorg_help("orgid unset", cmd_name);
00336 }
00337
00338 if (cmd->get_contact_list().empty()) {
00339 return cmd_brorg_help("at least one contact must be entered", cmd_name);
00340 }
00341
00342 cmd->set_common_data(common_data);
00343
00344 if (_debug) {
00345 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00346
00347 vector<PostalInfo>::const_iterator it;
00348 vector<PostalInfo> postal_list;
00349 postal_list = cmd->get_common_data().get_postal_info();
00350 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00351 SheppPrint::postal_info((*it));
00352 }
00353
00354 if (cmd->get_common_data().get_voice().number != "") {
00355 printf(" voice:");
00356 SheppPrint::phone(cmd->get_common_data().get_voice());
00357 }
00358
00359 if (cmd->get_common_data().get_fax().number != "") {
00360 printf(" fax :");
00361 SheppPrint::phone(cmd->get_common_data().get_fax());
00362 }
00363
00364 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00365
00366 SheppPrint::authInfo(cmd->get_authInfo());
00367
00368 if (cmd->get_common_data().get_disclose().is_set()) {
00369 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00370 }
00371
00372
00373 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00374
00375 map<string, string, less<string> > contacts = cmd->get_contact_list();
00376 map<string, string, less<string> >::const_iterator c_it;
00377 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00378 printf(" contact[%s] = [%s]\n", (*c_it).first.c_str(),
00379 (*c_it).second.c_str());
00380 }
00381 }
00382
00383 if (process_action(act) != 0) {
00384 return -1;
00385 }
00386
00387 return 0;
00388 }
00389
00391
00395 int cmd_brorg_delete(vector<string> words)
00396 {
00397 string cmd_name = "delete";
00398 return cmd_brorg_help("", cmd_name);
00399 }
00400
00402
00406 int cmd_brorg_renew(vector<string> words)
00407 {
00408 string cmd_name = "renew";
00409 return cmd_brorg_help("", cmd_name);
00410 }
00411
00413
00417 int cmd_brorg_update(vector<string> words)
00418 {
00419 BrOrgUpdate act;
00420 BrOrgUpdateCmd *cmd = act.get_command();
00421 string cmd_name = "update";
00422
00423 if (words.empty()) {
00424 return cmd_brorg_help("no brorg specified", cmd_name);
00425 }
00426
00427 CommonData common_data;
00428 common_data.set_id(SheppStrUtil::doc2id(words[0]));
00429
00430 cmd->set_organization(words[0]);
00431 words.erase(words.begin());
00432
00433 while (!words.empty()) {
00434 if (words[0] == "-add-status") {
00435
00436 words.erase(words.begin());
00437 if (words.empty()) {
00438 return cmd_brorg_help("error setting add-status", cmd_name);
00439 }
00440 string tmp1 = words[0];
00441 string tmp2;
00442 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00443 cmd->insert_status_list_add(tmp1);
00444 if (tmp2 == "") {
00445 break;
00446 }
00447 tmp1 = tmp2;
00448 }
00449 words.erase(words.begin());
00450 } else if (words[0] == "-rem-status") {
00451
00452 words.erase(words.begin());
00453 if (words.empty()) {
00454 return cmd_brorg_help("error setting rem-status", cmd_name);
00455 }
00456 string tmp1 = words[0];
00457 string tmp2;
00458 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00459 cmd->insert_status_list_rem(tmp1);
00460 if (tmp2 == "") {
00461 break;
00462 }
00463 tmp1 = tmp2;
00464 }
00465 words.erase(words.begin());
00466 } else if (words[0] == "-postalInfo") {
00467
00468 words.erase(words.begin());
00469 if (words.empty()) {
00470 return cmd_brorg_help("missing postal info arguments", cmd_name);
00471 }
00472 PostalInfo postal;
00473 string error_msg;
00474 if (SheppObjSet::postalInfo(postal, words, error_msg, true) != 0) {
00475 return cmd_brorg_help(error_msg, cmd_name);
00476 }
00477 vector<PostalInfo> postal_list = common_data.get_postal_info();
00478 for (int i = 0; i < (int) postal_list.size(); i++) {
00479 if (postal_list[i].get_type() == postal.get_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] == "-add-contact") {
00527
00528 words.erase(words.begin());
00529 if (words.empty()) {
00530 return cmd_brorg_help("-add-contact requires an argument",
00531 cmd_name);
00532 }
00533 map<string, string, less<string> > my_contacts;
00534 string error_msg;
00535 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00536 return cmd_brorg_help(error_msg, cmd_name);
00537 }
00538 map<string, string, less<string> >::const_iterator it;
00539 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00540 cmd->insert_contact_add((*it).first, (*it).second);
00541 }
00542 words.erase(words.begin());
00543 } else if (words[0] == "-rem-contact") {
00544
00545 words.erase(words.begin());
00546 if (words.empty()) {
00547 return cmd_brorg_help("-rem-contact requires an argument",
00548 cmd_name);
00549 }
00550 map<string, string, less<string> > my_contacts;
00551 string error_msg;
00552 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00553 return cmd_brorg_help(error_msg, cmd_name);
00554 }
00555 map<string, string, less<string> >::const_iterator it;
00556 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00557 cmd->insert_contact_rem((*it).first, (*it).second);
00558 }
00559 words.erase(words.begin());
00560
00561 } else if (words[0] == "-responsible") {
00562
00563 words.erase(words.begin());
00564 if (words.empty()) {
00565 return cmd_brorg_help("unspecified responsible name", cmd_name);
00566 }
00567 string responsible_name = words[0];
00568 words.erase(words.begin());
00569 if (SheppStrUtil::quote_gathering(words, responsible_name) != 0) {
00570 return cmd_brorg_help("error setting responsible name", cmd_name);
00571 }
00572 cmd->set_responsible(responsible_name);
00573 } else {
00574 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00575 cmd_name);
00576 }
00577 }
00578
00579 if (cmd->get_status_list_add().empty() &&
00580 cmd->get_status_list_rem().empty() &&
00581 common_data.get_postal_info().empty() &&
00582 common_data.get_voice().number == "" &&
00583 common_data.get_fax().number == "" &&
00584 common_data.get_email() == "" &&
00585 cmd->get_authInfo().get_pw() == "" &&
00586 !common_data.get_disclose().is_set() &&
00587 cmd->get_organization() == "") {
00588 return cmd_brorg_help("not enough information for update", cmd_name);
00589 }
00590
00591 cmd->set_common_data(common_data);
00592
00593 if (_debug) {
00594 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00595
00596 set<string> status = cmd->get_status_list_add();
00597 set<string>::const_iterator st_it;
00598 if (!status.empty()) {
00599 printf(" status to add: [ ");
00600 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00601 printf("%s ", (*st_it).c_str());
00602 }
00603 printf("]\n");
00604 }
00605
00606 status = cmd->get_status_list_rem();
00607 if (!status.empty()) {
00608 printf(" status to rem: [ ");
00609 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00610 printf("%s ", (*st_it).c_str());
00611 }
00612 printf("]\n");
00613 }
00614
00615 vector<PostalInfo> postal_list;
00616 postal_list = cmd->get_common_data().get_postal_info();
00617 for (int i = 0; i < (int) postal_list.size(); i++) {
00618 SheppPrint::postal_info(postal_list[i]);
00619 }
00620
00621 if (cmd->get_common_data().get_voice().number != "") {
00622 printf(" voice:");
00623 SheppPrint::phone(cmd->get_common_data().get_voice());
00624 }
00625
00626 if (cmd->get_common_data().get_fax().number != "") {
00627 printf(" fax :");
00628 SheppPrint::phone(cmd->get_common_data().get_fax());
00629 }
00630
00631 if (cmd->get_common_data().get_email() != "") {
00632 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00633 }
00634
00635 if (cmd->get_authInfo().get_pw() != "") {
00636 SheppPrint::authInfo(cmd->get_authInfo());
00637 }
00638
00639 if (cmd->get_common_data().get_disclose().is_set()) {
00640 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00641 }
00642
00643
00644 if (cmd->get_organization() != "") {
00645 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00646
00647 map<string, string, less<string> > contacts =
00648 cmd->get_contact_list_add();
00649 map<string, string, less<string> >::const_iterator c_it;
00650 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00651 printf(" contact to add [%s] = [%s]\n", (*c_it).first.c_str(),
00652 (*c_it).second.c_str());
00653 }
00654
00655 contacts = cmd->get_contact_list_rem();
00656 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00657 printf(" contact to rem [%s] = [%s]\n", (*c_it).first.c_str(),
00658 (*c_it).second.c_str());
00659 }
00660 }
00661 }
00662
00663 if (process_action(act) != 0) {
00664 return -1;
00665 }
00666
00667 return 0;
00668 }
00669
00671
00675 int cmd_brorg(char *arg)
00676 {
00677 if (strlen(arg) > 0) {
00678 vector<string> words = SheppStrUtil::parse_line(arg);
00679
00680
00681 if (!words.empty() && !(words[0] == "help")) {
00682 if (words[0] == "check") {
00683 words.erase(words.begin());
00684 return cmd_brorg_check(words);
00685 } else if (words[0] == "info") {
00686 words.erase(words.begin());
00687 return cmd_brorg_info(words);
00688 } else if (words[0] == "transfer") {
00689 words.erase(words.begin());
00690 return cmd_brorg_transfer(words);
00691 } else if (words[0] == "create") {
00692 words.erase(words.begin());
00693 return cmd_brorg_create(words);
00694 } else if (words[0] == "delete") {
00695 words.erase(words.begin());
00696 return cmd_brorg_delete(words);
00697 } else if (words[0] == "renew") {
00698 words.erase(words.begin());
00699 return cmd_brorg_renew(words);
00700 } else if (words[0] == "update") {
00701 words.erase(words.begin());
00702 return cmd_brorg_update(words);
00703 } else {
00704 return cmd_brorg_help("invalid command: brorg " + words[0]);
00705 }
00706 }
00707 }
00708
00709 return cmd_brorg_help("");
00710 }
00711
00712 #endif //__BRORG_FUNCTIONS_H__