src/shepp/SheppObjSet.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: SheppObjSet.H 746 2006-05-24 12:30:18Z eduardo $ */
00007 #ifndef __SHEPP_OBJ_SET_H__
00008 #define __SHEPP_OBJ_SET_H__
00009 
00010 #include "CommonData.H"
00011 #include "DomainUpdateCmd.H"
00012 
00014 class SheppObjSet {
00015 public:
00016 
00017   //used by both contact and domain
00018 
00020 
00025   static int authInfo(AuthInfo &auth, vector<string> &words)
00026   {
00027     words.erase(words.begin());
00028     
00029     if (words.size() <= 0) {
00030       return -1;
00031     }
00032     
00033     string pw;
00034     string roid;
00035     if (SheppStrUtil::split(words[0], pw, roid, ":", true) != 0) {
00036       return -1;
00037     }
00038     
00039     auth.set_pw(pw);
00040     auth.set_roid(roid);
00041     
00042     words.erase(words.begin()); 
00043     
00044     return 0;
00045   }
00046 
00047   //domain specific
00048 
00050 
00055   static int nameServer(NameServer &ns, vector<string> &words)
00056   {
00057     words.erase(words.begin());
00058     if (words.empty()) {
00059       return -1;
00060     }
00061 
00062     string ips;
00063     SheppStrUtil::split(words[0], ns.name, ips, ",", true);
00064 
00065     if (ips != "") {
00066       string this_ip;
00067       do {
00068         if (SheppStrUtil::split(ips, this_ip, ips, ",", true) != 0) {
00069           return -1;
00070         }
00071       
00072         NSIPAddr ip;
00073         if (SheppStrUtil::split(this_ip, ip.version, ip.addr, ":", false)
00074             != 0) {
00075           return -1;
00076         }
00077 
00078         ns.ips.insert(ip);
00079       } while (ips != "");
00080     }
00081 
00082     words.erase(words.begin());
00083   
00084     return 0;
00085   }
00086 
00088 
00093   static int status(DomainUpdateCmd::Status &st, vector<string> &words)
00094   {
00095     string status;
00096     string lang;
00097     string description;
00098 
00099     if (SheppStrUtil::split(words[0], status, lang, ":", false) != 0) {
00100       return -1;
00101     }
00102     words.erase(words.begin());
00103 
00104     if (SheppStrUtil::split(lang, lang, description, ":", false) != 0) {
00105       return -1;
00106     }
00107 
00108     SheppStrUtil::quote_gathering(words, description);
00109 
00110     st.s = status;
00111     st.lang = lang;
00112     st.msg = description;
00113 
00114     return 0;
00115   }
00116 
00117   //contact specific
00118 
00120 
00127   static int postalInfo(PostalInfo &postal, vector<string> &words,
00128                         string &error_msg, bool relaxed)
00129   {
00130     postal.set_type(words[0]);
00131     words.erase(words.begin());
00132 
00133     while (!words.empty()) {
00134       if (words[0] == "-name") {
00135         //name
00136         words.erase(words.begin());
00137         if (words.empty()) {
00138           error_msg = "unspecified contact name";
00139           return -1;
00140         }
00141         postal.set_name(words[0]);
00142         words.erase(words.begin());
00143         string postal_name = postal.get_name();
00144         if (SheppStrUtil::quote_gathering(words, postal_name) != 0) {
00145           error_msg = "error setting contact name";
00146           return -1;
00147         }
00148         postal.set_name(postal_name);
00149       } else if (words[0] == "-org") {
00150         //org
00151         words.erase(words.begin());
00152         if (words.empty()) {
00153           error_msg = "unspecified organization";
00154           return -1;
00155         }
00156         postal.set_org(words[0]);
00157         words.erase(words.begin());
00158         string postal_org = postal.get_org();
00159         if (SheppStrUtil::quote_gathering(words, postal_org) != 0) {
00160           error_msg = "error setting organization";
00161           return -1;
00162         }
00163         postal.set_org(postal_org);
00164       } else if (words[0] == "-street1") {
00165         //street1
00166         words.erase(words.begin());
00167         if (words.empty()) {
00168           error_msg = "unspecified address street/line 1";
00169           return -1;
00170         }
00171         postal.set_str1(words[0]);
00172         words.erase(words.begin());
00173         string postal_str1 = postal.get_str1();
00174         if (SheppStrUtil::quote_gathering(words, postal_str1) != 0) {
00175           error_msg = "error setting address street/line 1";
00176           return -1;
00177         }
00178         postal.set_str1(postal_str1);
00179       } else if (words[0] == "-street2") {
00180         //street2
00181         words.erase(words.begin());
00182         if (words.empty()) {
00183           error_msg = "unspecified address number/line 2";
00184           return -1;
00185         }
00186         postal.set_str2(words[0]);
00187         words.erase(words.begin());
00188         string postal_str2 = postal.get_str2();
00189         if (SheppStrUtil::quote_gathering(words, postal_str2) != 0) {
00190           error_msg = "error setting address number/line 2";
00191           return -1;
00192         }
00193         postal.set_str2(postal_str2);
00194       } else if (words[0] == "-street3") {
00195         //street3
00196         words.erase(words.begin());
00197         if (words.empty()) {
00198           error_msg = "unspecified street3";
00199           return -1;
00200         }
00201         postal.set_str3(words[0]);
00202         words.erase(words.begin());
00203         string postal_str3 = postal.get_str3();
00204         if (SheppStrUtil::quote_gathering(words, postal_str3) != 0) {
00205           error_msg = "error setting address line 3";
00206           return -1;
00207         }
00208         postal.set_str3(postal_str3);
00209       } else if (words[0] == "-city") {
00210         //city
00211         words.erase(words.begin());
00212         if (words.empty()) {
00213           error_msg = "unspecified city";
00214           return -1;
00215         }
00216         postal.set_city(words[0]);
00217         words.erase(words.begin());
00218         string postal_city = postal.get_city();
00219         if (SheppStrUtil::quote_gathering(words, postal_city) != 0) {
00220           error_msg = "error setting city";
00221           return -1;
00222         }
00223         postal.set_city(postal_city);
00224       } else if (words[0] == "-state") {
00225         //state
00226         words.erase(words.begin());
00227         if (words.empty()) {
00228           error_msg = "unspecified state";
00229           return -1;
00230         }
00231         postal.set_sp(words[0]);
00232         words.erase(words.begin());
00233         string postal_sp = postal.get_sp();
00234         if (SheppStrUtil::quote_gathering(words, postal_sp) != 0) {
00235           error_msg = "error setting state/province";
00236           return -1;
00237         }
00238         postal.set_sp(postal_sp);
00239       } else if (words[0] == "-pc") {
00240         //pc
00241         words.erase(words.begin());
00242         if (words.empty()) {
00243           error_msg = "unspecified postal code";
00244           return -1;
00245         }
00246         postal.set_pc(words[0]);
00247         words.erase(words.begin());
00248         string postal_pc = postal.get_pc();
00249         if (SheppStrUtil::quote_gathering(words, postal_pc) != 0) {
00250           error_msg = "error setting postal code";
00251           return -1;
00252         }
00253         postal.set_pc(postal_pc);
00254       } else if (words[0] == "-cc") {
00255         words.erase(words.begin());
00256         if (words.empty()) {
00257           error_msg = "unspecified country code";
00258           return -1;
00259         }
00260         postal.set_cc(words[0]);
00261         words.erase(words.begin());
00262       } else {
00263         break;
00264       }
00265     }
00266 
00267     //relaxed: update; !relaxed: create
00268     if (!relaxed) {
00269       if (postal.get_name() == "") {
00270         error_msg = "name is mandatory";
00271         return -1;
00272       }
00273 
00274       if (postal.get_str1() == "") {
00275         error_msg = "address street/line 1 is mandatory";
00276         return -1;
00277       }
00278     
00279       if (postal.get_city() == "") {
00280         error_msg = "city is mandatory";
00281         return -1;
00282       }
00283     
00284       if (postal.get_cc() == "") {
00285         error_msg = "country code is mandatory";
00286         return -1;
00287       }
00288     } else {
00289       if (postal.get_name() == "" &&
00290           postal.get_org() == "" &&
00291           postal.get_str1() == "" &&
00292           postal.get_str2() == "" &&
00293           postal.get_str3() == "" &&
00294           postal.get_city() == "" &&
00295           postal.get_sp() == "" &&
00296           postal.get_pc() == "" &&
00297           postal.get_cc() == "") {
00298         error_msg = "empty postal info";
00299         return -1;
00300       }
00301     }   
00302 
00303     return 0;
00304   }
00305 
00307 
00312   static int phone(CommonData::Phone &phone, vector<string> &words)
00313   {
00314     if (words.empty() ||
00315         SheppStrUtil::split(words[0], phone.number, phone.ext, ":", true)
00316         != 0) {
00317       return -1;
00318     }
00319     words.erase(words.begin());
00320     return 0;
00321   }
00322 
00324 
00329   static int disclose(CommonData::Disclose &disclose, string word)
00330   {
00331     string opt1 = word;
00332     string opt2;
00333     while (opt1 != "" &&
00334            SheppStrUtil::split(opt1, opt1, opt2, ",", true) == 0) {
00335       if (opt1 == "name_int") {
00336         disclose.name_int = true;
00337       } else if (opt1 == "name_loc") {
00338         disclose.name_loc = true;
00339       } else if (opt1 == "org_int") {
00340         disclose.org_int = true;
00341       } else if (opt1 == "org_loc") {
00342         disclose.org_loc = true;
00343       } else if (opt1 == "addr_int") {
00344         disclose.addr_int = true;
00345       } else if (opt1 == "addr_loc") {
00346         disclose.addr_loc = true;
00347       } else if (opt1 == "voice") {
00348         disclose.voice = true;
00349       } else if (opt1 == "fax") {
00350         disclose.fax = true;
00351       } else if (opt1 == "email") {
00352         disclose.email = true;
00353       } else {
00354         return -1;
00355       }
00356       opt1 = opt2;
00357     }
00358     return 0;
00359   }
00360 
00361   // brorg specific
00362 
00364 
00370   static int contacts(map<string, string, less<string> > &contacts,
00371                       string args, string &error_msg)
00372   {
00373     string one = args;
00374     string rest;
00375 
00376     do {
00377       if (SheppStrUtil::split(one, one, rest, ",", true) != 0) {
00378         error_msg = "invalid contact";
00379         return -1;
00380       }
00381 
00382       string key;
00383       string value;
00384       if (SheppStrUtil::split(one, key, value, "=", false) != 0) {
00385         error_msg = "invalid contact";
00386         return -1;
00387       }
00388 
00389       contacts[key] = value;
00390 
00391       one = rest;
00392     } while (one != "");
00393 
00394     return 0;
00395   }
00396 };
00397 
00398 #endif //__SHEPP_OBJ_SET_H__

Generated on Thu Jun 8 17:40:00 2006 for libepp_nicbr by  doxygen 1.4.6