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 "-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 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[: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 string numbers = SheppStrUtil::doc2id(words[0]);
00113 cmd->insert_id(numbers);
00114 cmd->insert_organization(numbers, 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(SheppStrUtil::doc2id(words[0]));
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(SheppStrUtil::doc2id(words[0]));
00216 cmd->set_organization(words[0]);
00217
00218 words.erase(words.begin());
00219
00220
00221 AuthInfo auth;
00222 cmd->set_authInfo(auth);
00223
00224 while (!words.empty()) {
00225 if (words[0] == "-postalInfo") {
00226
00227 words.erase(words.begin());
00228 if (words.empty()) {
00229 return cmd_brorg_help("missing postal info arguments", cmd_name);
00230 }
00231 PostalInfo postal;
00232 string error_msg;
00233 if (SheppObjSet::postalInfo(postal, words, error_msg, false) != 0) {
00234 return cmd_brorg_help(error_msg, cmd_name);
00235 }
00236 vector<PostalInfo> postal_list = common_data.get_postal_info();
00237 for (int i = 0; i < (int) postal_list.size(); i++) {
00238 if (postal_list[i].get_type() == postal.get_type()) {
00239 return cmd_brorg_help("duplicated postal info type", cmd_name);
00240 }
00241 }
00242 common_data.insert_postal_info(postal);
00243 } else if (words[0] == "-voice") {
00244
00245 words.erase(words.begin());
00246 CommonData::Phone phone;
00247 if (SheppObjSet::phone(phone, words) != 0) {
00248 return cmd_brorg_help("error setting voice telephone number",
00249 cmd_name);
00250 }
00251 common_data.set_voice(phone);
00252 } else if (words[0] == "-fax") {
00253
00254 words.erase(words.begin());
00255 CommonData::Phone phone;
00256 if (SheppObjSet::phone(phone, words) != 0) {
00257 return cmd_brorg_help("error setting fax telephone number",
00258 cmd_name);
00259 }
00260 common_data.set_fax(phone);
00261 } else if (words[0] == "-email") {
00262
00263 words.erase(words.begin());
00264 if (words.empty()) {
00265 return cmd_brorg_help("no e-mail address specified", cmd_name);
00266 }
00267 common_data.set_email(words[0]);
00268 words.erase(words.begin());
00269 } else if (words[0] == "-auth") {
00270
00271 AuthInfo auth;
00272 if (SheppObjSet::authInfo(auth, words) != 0) {
00273 return cmd_brorg_help("invalid auth", cmd_name);
00274 }
00275 cmd->set_authInfo(auth);
00276 } else if (words[0] == "-disclose") {
00277
00278 words.erase(words.begin());
00279 CommonData::Disclose disclose;
00280 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00281 return cmd_brorg_help("invalid diclose information", cmd_name);
00282 }
00283 words.erase(words.begin());
00284 common_data.set_disclose(disclose);
00285 } else if (words[0] == "-contact") {
00286
00287 words.erase(words.begin());
00288 if (words.empty()) {
00289 return cmd_brorg_help("-contact requires an argument", cmd_name);
00290 }
00291 map<string, string, less<string> > my_contacts;
00292 string error_msg;
00293 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00294 return cmd_brorg_help(error_msg, cmd_name);
00295 }
00296 map<string, string, less<string> >::const_iterator it;
00297 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00298 cmd->insert_contact((*it).first, (*it).second);
00299 }
00300 words.erase(words.begin());
00301 } else {
00302 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00303 cmd_name);
00304 }
00305 }
00306
00307 if (common_data.get_postal_info().empty()) {
00308 return cmd_brorg_help("at least one postal info must be entered",
00309 cmd_name);
00310 }
00311
00312 if (common_data.get_email() == "") {
00313 return cmd_brorg_help("e-mail is mandatory", cmd_name);
00314 }
00315
00316 if (common_data.get_voice().number == "") {
00317 return cmd_brorg_help("voice telephone number is mandatory", cmd_name);
00318 }
00319
00320 if (cmd->get_organization() == "") {
00321 return cmd_brorg_help("orgid unset", cmd_name);
00322 }
00323
00324 if (cmd->get_contact_list().empty()) {
00325 return cmd_brorg_help("at least one contact must be entered", cmd_name);
00326 }
00327
00328 cmd->set_common_data(common_data);
00329
00330 if (_debug) {
00331 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00332
00333 vector<PostalInfo>::const_iterator it;
00334 vector<PostalInfo> postal_list;
00335 postal_list = cmd->get_common_data().get_postal_info();
00336 for (it = postal_list.begin(); it != postal_list.end(); it++) {
00337 SheppPrint::postal_info((*it));
00338 }
00339
00340 if (cmd->get_common_data().get_voice().number != "") {
00341 printf(" voice:");
00342 SheppPrint::phone(cmd->get_common_data().get_voice());
00343 }
00344
00345 if (cmd->get_common_data().get_fax().number != "") {
00346 printf(" fax :");
00347 SheppPrint::phone(cmd->get_common_data().get_fax());
00348 }
00349
00350 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00351
00352 SheppPrint::authInfo(cmd->get_authInfo());
00353
00354 if (cmd->get_common_data().get_disclose().is_set()) {
00355 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00356 }
00357
00358
00359 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00360
00361 map<string, string, less<string> > contacts = cmd->get_contact_list();
00362 map<string, string, less<string> >::const_iterator c_it;
00363 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00364 printf(" contact[%s] = [%s]\n", (*c_it).first.c_str(),
00365 (*c_it).second.c_str());
00366 }
00367 }
00368
00369 if (process_action(act) != 0) {
00370 return -1;
00371 }
00372
00373 return 0;
00374 }
00375
00377
00381 int cmd_brorg_delete(vector<string> words)
00382 {
00383 string cmd_name = "delete";
00384 return cmd_brorg_help("", cmd_name);
00385 }
00386
00388
00392 int cmd_brorg_renew(vector<string> words)
00393 {
00394 string cmd_name = "renew";
00395 return cmd_brorg_help("", cmd_name);
00396 }
00397
00399
00403 int cmd_brorg_update(vector<string> words)
00404 {
00405 BrOrgUpdate act;
00406 BrOrgUpdateCmd *cmd = act.get_command();
00407 string cmd_name = "update";
00408
00409 if (words.empty()) {
00410 return cmd_brorg_help("no brorg specified", cmd_name);
00411 }
00412
00413 CommonData common_data;
00414 common_data.set_id(SheppStrUtil::doc2id(words[0]));
00415
00416 cmd->set_organization(words[0]);
00417 words.erase(words.begin());
00418
00419 while (!words.empty()) {
00420 if (words[0] == "-add-status") {
00421
00422 words.erase(words.begin());
00423 if (words.empty()) {
00424 return cmd_brorg_help("error setting add-status", cmd_name);
00425 }
00426 string tmp1 = words[0];
00427 string tmp2;
00428 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00429 cmd->insert_status_list_add(tmp1);
00430 if (tmp2 == "") {
00431 break;
00432 }
00433 tmp1 = tmp2;
00434 }
00435 words.erase(words.begin());
00436 } else if (words[0] == "-rem-status") {
00437
00438 words.erase(words.begin());
00439 if (words.empty()) {
00440 return cmd_brorg_help("error setting rem-status", cmd_name);
00441 }
00442 string tmp1 = words[0];
00443 string tmp2;
00444 while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
00445 cmd->insert_status_list_rem(tmp1);
00446 if (tmp2 == "") {
00447 break;
00448 }
00449 tmp1 = tmp2;
00450 }
00451 words.erase(words.begin());
00452 } else if (words[0] == "-postalInfo") {
00453
00454 words.erase(words.begin());
00455 if (words.empty()) {
00456 return cmd_brorg_help("missing postal info arguments", cmd_name);
00457 }
00458 PostalInfo postal;
00459 string error_msg;
00460 if (SheppObjSet::postalInfo(postal, words, error_msg, true) != 0) {
00461 return cmd_brorg_help(error_msg, cmd_name);
00462 }
00463 vector<PostalInfo> postal_list = common_data.get_postal_info();
00464 for (int i = 0; i < (int) postal_list.size(); i++) {
00465 if (postal_list[i].get_type() == postal.get_type()) {
00466 return cmd_brorg_help("duplicated postal info type", cmd_name);
00467 }
00468 }
00469 common_data.insert_postal_info(postal);
00470 } else if (words[0] == "-voice") {
00471
00472 words.erase(words.begin());
00473 CommonData::Phone phone;
00474 if (SheppObjSet::phone(phone, words) != 0) {
00475 return cmd_brorg_help("error setting voice telephone number",
00476 cmd_name);
00477 }
00478 common_data.set_voice(phone);
00479 } else if (words[0] == "-fax") {
00480
00481 words.erase(words.begin());
00482 CommonData::Phone phone;
00483 if (SheppObjSet::phone(phone, words) != 0) {
00484 return cmd_brorg_help("error setting fax telephone number",
00485 cmd_name);
00486 }
00487 common_data.set_fax(phone);
00488 } else if (words[0] == "-email") {
00489
00490 words.erase(words.begin());
00491 if (words.empty()) {
00492 return cmd_brorg_help("no e-mail address specified", cmd_name);
00493 }
00494 common_data.set_email(words[0]);
00495 words.erase(words.begin());
00496 } else if (words[0] == "-auth") {
00497
00498 AuthInfo auth;
00499 if (SheppObjSet::authInfo(auth, words) != 0) {
00500 return cmd_brorg_help("invalid auth", cmd_name);
00501 }
00502 cmd->set_authInfo(auth);
00503 } else if (words[0] == "-disclose") {
00504
00505 words.erase(words.begin());
00506 CommonData::Disclose disclose;
00507 if (SheppObjSet::disclose(disclose, words[0]) != 0) {
00508 return cmd_brorg_help("invalid diclose information", cmd_name);
00509 }
00510 words.erase(words.begin());
00511 common_data.set_disclose(disclose);
00512 } else if (words[0] == "-add-contact") {
00513
00514 words.erase(words.begin());
00515 if (words.empty()) {
00516 return cmd_brorg_help("-add-contact requires an argument",
00517 cmd_name);
00518 }
00519 map<string, string, less<string> > my_contacts;
00520 string error_msg;
00521 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00522 return cmd_brorg_help(error_msg, cmd_name);
00523 }
00524 map<string, string, less<string> >::const_iterator it;
00525 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00526 cmd->insert_contact_add((*it).first, (*it).second);
00527 }
00528 words.erase(words.begin());
00529 } else if (words[0] == "-rem-contact") {
00530
00531 words.erase(words.begin());
00532 if (words.empty()) {
00533 return cmd_brorg_help("-rem-contact requires an argument",
00534 cmd_name);
00535 }
00536 map<string, string, less<string> > my_contacts;
00537 string error_msg;
00538 if (SheppObjSet::contacts(my_contacts, words[0], error_msg) != 0) {
00539 return cmd_brorg_help(error_msg, cmd_name);
00540 }
00541 map<string, string, less<string> >::const_iterator it;
00542 for (it = my_contacts.begin(); it != my_contacts.end(); it++) {
00543 cmd->insert_contact_rem((*it).first, (*it).second);
00544 }
00545 words.erase(words.begin());
00546 } else {
00547 return cmd_brorg_help("invalid syntax near \"" + words[0] + "\"",
00548 cmd_name);
00549 }
00550 }
00551
00552 if (cmd->get_status_list_add().empty() &&
00553 cmd->get_status_list_rem().empty() &&
00554 common_data.get_postal_info().empty() &&
00555 common_data.get_voice().number == "" &&
00556 common_data.get_fax().number == "" &&
00557 common_data.get_email() == "" &&
00558 cmd->get_authInfo().get_pw() == "" &&
00559 !common_data.get_disclose().is_set() &&
00560 cmd->get_organization() == "") {
00561 return cmd_brorg_help("not enough information for update", cmd_name);
00562 }
00563
00564 cmd->set_common_data(common_data);
00565
00566 if (_debug) {
00567 printf(" brorg: [%s]\n", cmd->get_common_data().get_id().c_str());
00568
00569 set<string> status = cmd->get_status_list_add();
00570 set<string>::const_iterator st_it;
00571 if (!status.empty()) {
00572 printf(" status to add: [ ");
00573 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00574 printf("%s ", (*st_it).c_str());
00575 }
00576 printf("]\n");
00577 }
00578
00579 status = cmd->get_status_list_rem();
00580 if (!status.empty()) {
00581 printf(" status to rem: [ ");
00582 for (st_it = status.begin(); st_it != status.end(); st_it++) {
00583 printf("%s ", (*st_it).c_str());
00584 }
00585 printf("]\n");
00586 }
00587
00588 vector<PostalInfo> postal_list;
00589 postal_list = cmd->get_common_data().get_postal_info();
00590 for (int i = 0; i < (int) postal_list.size(); i++) {
00591 SheppPrint::postal_info(postal_list[i]);
00592 }
00593
00594 if (cmd->get_common_data().get_voice().number != "") {
00595 printf(" voice:");
00596 SheppPrint::phone(cmd->get_common_data().get_voice());
00597 }
00598
00599 if (cmd->get_common_data().get_fax().number != "") {
00600 printf(" fax :");
00601 SheppPrint::phone(cmd->get_common_data().get_fax());
00602 }
00603
00604 if (cmd->get_common_data().get_email() != "") {
00605 printf(" email: [%s]\n", cmd->get_common_data().get_email().c_str());
00606 }
00607
00608 if (cmd->get_authInfo().get_pw() != "") {
00609 SheppPrint::authInfo(cmd->get_authInfo());
00610 }
00611
00612 if (cmd->get_common_data().get_disclose().is_set()) {
00613 SheppPrint::disclose(cmd->get_common_data().get_disclose());
00614 }
00615
00616
00617 if (cmd->get_organization() != "") {
00618 printf(" orgid: [%s]\n", cmd->get_organization().c_str());
00619
00620 map<string, string, less<string> > contacts =
00621 cmd->get_contact_list_add();
00622 map<string, string, less<string> >::const_iterator c_it;
00623 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00624 printf(" contact to add [%s] = [%s]\n", (*c_it).first.c_str(),
00625 (*c_it).second.c_str());
00626 }
00627
00628 contacts = cmd->get_contact_list_rem();
00629 for (c_it = contacts.begin(); c_it != contacts.end(); c_it++) {
00630 printf(" contact to rem [%s] = [%s]\n", (*c_it).first.c_str(),
00631 (*c_it).second.c_str());
00632 }
00633 }
00634 }
00635
00636 if (process_action(act) != 0) {
00637 return -1;
00638 }
00639
00640 return 0;
00641 }
00642
00644
00648 int cmd_brorg(char *arg)
00649 {
00650 if (strlen(arg) > 0) {
00651 vector<string> words = SheppStrUtil::parse_line(arg);
00652
00653
00654 if (!words.empty() && !(words[0] == "help")) {
00655 if (words[0] == "check") {
00656 words.erase(words.begin());
00657 return cmd_brorg_check(words);
00658 } else if (words[0] == "info") {
00659 words.erase(words.begin());
00660 return cmd_brorg_info(words);
00661 } else if (words[0] == "transfer") {
00662 words.erase(words.begin());
00663 return cmd_brorg_transfer(words);
00664 } else if (words[0] == "create") {
00665 words.erase(words.begin());
00666 return cmd_brorg_create(words);
00667 } else if (words[0] == "delete") {
00668 words.erase(words.begin());
00669 return cmd_brorg_delete(words);
00670 } else if (words[0] == "renew") {
00671 words.erase(words.begin());
00672 return cmd_brorg_renew(words);
00673 } else if (words[0] == "update") {
00674 words.erase(words.begin());
00675 return cmd_brorg_update(words);
00676 } else {
00677 return cmd_brorg_help("invalid command: brorg " + words[0]);
00678 }
00679 }
00680 }
00681
00682 return cmd_brorg_help("");
00683 }
00684
00685 #endif //__BRORG_FUNCTIONS_H__