src/shepp/SheppObjSet.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: SheppObjSet.H 891 2007-03-07 14:15:01Z 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 
00118 
00123   static int dsInfo(DSInfo &ds, vector<string> &words, string &error_msg)
00124   {
00125     words.erase(words.begin()); // -ds
00126 
00127     // must have at least 4 elements: keytag, algorithm, digtype and digest
00128     if (words.size() < 4) {
00129       error_msg = "not enough arguments for DS";
00130       return -1;
00131     }
00132 
00133     // parse the key tag: check if it has only numbers
00134     string c;
00135     for (unsigned int i = 0; i < words[0].length(); i++) {
00136       c = words[0][i];
00137       if (c != "0" && atoi(c.c_str()) == 0) {
00138         error_msg = "keyTag must be a number";
00139         return -1;
00140       }
00141     }
00142 
00143     int key_tag = atoi(words[0].c_str());
00144     if (key_tag < 0) {
00145       error_msg = "keyTag cannot be a negative number";
00146       return -1;
00147     }
00148     ds.set_key_tag(key_tag);
00149 
00150     int alg = atoi(words[1].c_str());
00151     if (alg < 0) {
00152       error_msg = "alg cannot be a negative number";
00153       return -1;
00154     }
00155     ds.set_algo(alg);
00156 
00157     int dig_type = atoi(words[2].c_str());
00158     if (dig_type < 0) {
00159       error_msg = "digestType cannot be a negative number";
00160       return -1;
00161     }
00162     ds.set_digest_type(dig_type);
00163     ds.set_digest(words[3]);
00164 
00165     words.erase(words.begin(), words.begin() + 4);
00166 
00167     //optional parameters
00168     while (!words.empty()) {
00169       if (words[0] == "-maxlife") {
00170         if (words.size() < 2) {
00171           error_msg = "maxSigLife value missing";
00172           return -1;
00173         }
00174         words.erase(words.begin()); // -maxlife
00175         int maxlife = atoi(words[0].c_str());
00176         if (maxlife < 0) {
00177           error_msg = "maxSigLife cannot be a negative number";
00178           return -1;
00179         }
00180         ds.set_max_sig_life(maxlife);
00181         words.erase(words.begin()); // maxlife value
00182       } else if (words[0] == "-keyData") {
00183         if (words.size() < 5) {
00184           error_msg = "not enough arguments for keyData";
00185           return -1;
00186         }
00187         DSInfo::KeyData kd;
00188         kd._flags = atoi(words[1].c_str());
00189         kd._protocol = atoi(words[2].c_str());
00190         kd._algorithm = atoi(words[3].c_str());
00191         kd._pub_key = words[4];
00192 
00193         if (kd._flags < 0 || kd._protocol < 0 || kd._algorithm < 0) {
00194           error_msg =
00195             "keyData flags, protocol and alg cannot be negative numbers";
00196           return -1;
00197         }
00198         words.erase(words.begin(), words.begin() + 5); 
00199         ds.set_key_data(kd);
00200       } else {
00201         break;
00202       }
00203     }
00204 
00205     return 0;
00206   }
00207 
00208   //contact specific
00209 
00211 
00218   static int postalInfo(PostalInfo &postal, vector<string> &words,
00219                         string &error_msg, bool relaxed)
00220   {
00221     postal.set_type(words[0]);
00222     words.erase(words.begin());
00223 
00224     while (!words.empty()) {
00225       if (words[0] == "-name") {
00226         //name
00227         words.erase(words.begin());
00228         if (words.empty()) {
00229           error_msg = "unspecified contact name";
00230           return -1;
00231         }
00232         postal.set_name(words[0]);
00233         words.erase(words.begin());
00234         string postal_name = postal.get_name();
00235         if (SheppStrUtil::quote_gathering(words, postal_name) != 0) {
00236           error_msg = "error setting contact name";
00237           return -1;
00238         }
00239         postal.set_name(postal_name);
00240       } else if (words[0] == "-org") {
00241         //org
00242         words.erase(words.begin());
00243         if (words.empty()) {
00244           error_msg = "unspecified organization";
00245           return -1;
00246         }
00247         postal.set_org(words[0]);
00248         words.erase(words.begin());
00249         string postal_org = postal.get_org();
00250         if (SheppStrUtil::quote_gathering(words, postal_org) != 0) {
00251           error_msg = "error setting organization";
00252           return -1;
00253         }
00254         postal.set_org(postal_org);
00255       } else if (words[0] == "-street1") {
00256         //street1
00257         words.erase(words.begin());
00258         if (words.empty()) {
00259           error_msg = "unspecified address street/line 1";
00260           return -1;
00261         }
00262         postal.set_str1(words[0]);
00263         words.erase(words.begin());
00264         string postal_str1 = postal.get_str1();
00265         if (SheppStrUtil::quote_gathering(words, postal_str1) != 0) {
00266           error_msg = "error setting address street/line 1";
00267           return -1;
00268         }
00269         postal.set_str1(postal_str1);
00270       } else if (words[0] == "-street2") {
00271         //street2
00272         words.erase(words.begin());
00273         if (words.empty()) {
00274           error_msg = "unspecified address number/line 2";
00275           return -1;
00276         }
00277         postal.set_str2(words[0]);
00278         words.erase(words.begin());
00279         string postal_str2 = postal.get_str2();
00280         if (SheppStrUtil::quote_gathering(words, postal_str2) != 0) {
00281           error_msg = "error setting address number/line 2";
00282           return -1;
00283         }
00284         postal.set_str2(postal_str2);
00285       } else if (words[0] == "-street3") {
00286         //street3
00287         words.erase(words.begin());
00288         if (words.empty()) {
00289           error_msg = "unspecified street3";
00290           return -1;
00291         }
00292         postal.set_str3(words[0]);
00293         words.erase(words.begin());
00294         string postal_str3 = postal.get_str3();
00295         if (SheppStrUtil::quote_gathering(words, postal_str3) != 0) {
00296           error_msg = "error setting address line 3";
00297           return -1;
00298         }
00299         postal.set_str3(postal_str3);
00300       } else if (words[0] == "-city") {
00301         //city
00302         words.erase(words.begin());
00303         if (words.empty()) {
00304           error_msg = "unspecified city";
00305           return -1;
00306         }
00307         postal.set_city(words[0]);
00308         words.erase(words.begin());
00309         string postal_city = postal.get_city();
00310         if (SheppStrUtil::quote_gathering(words, postal_city) != 0) {
00311           error_msg = "error setting city";
00312           return -1;
00313         }
00314         postal.set_city(postal_city);
00315       } else if (words[0] == "-state") {
00316         //state
00317         words.erase(words.begin());
00318         if (words.empty()) {
00319           error_msg = "unspecified state";
00320           return -1;
00321         }
00322         postal.set_sp(words[0]);
00323         words.erase(words.begin());
00324         string postal_sp = postal.get_sp();
00325         if (SheppStrUtil::quote_gathering(words, postal_sp) != 0) {
00326           error_msg = "error setting state/province";
00327           return -1;
00328         }
00329         postal.set_sp(postal_sp);
00330       } else if (words[0] == "-pc") {
00331         //pc
00332         words.erase(words.begin());
00333         if (words.empty()) {
00334           error_msg = "unspecified postal code";
00335           return -1;
00336         }
00337         postal.set_pc(words[0]);
00338         words.erase(words.begin());
00339         string postal_pc = postal.get_pc();
00340         if (SheppStrUtil::quote_gathering(words, postal_pc) != 0) {
00341           error_msg = "error setting postal code";
00342           return -1;
00343         }
00344         postal.set_pc(postal_pc);
00345       } else if (words[0] == "-cc") {
00346         words.erase(words.begin());
00347         if (words.empty()) {
00348           error_msg = "unspecified country code";
00349           return -1;
00350         }
00351         postal.set_cc(words[0]);
00352         words.erase(words.begin());
00353       } else {
00354         break;
00355       }
00356     }
00357 
00358     //relaxed: update; !relaxed: create
00359     if (!relaxed) {
00360       if (postal.get_name() == "") {
00361         error_msg = "name is mandatory";
00362         return -1;
00363       }
00364 
00365       if (postal.get_str1() == "") {
00366         error_msg = "address street/line 1 is mandatory";
00367         return -1;
00368       }
00369     
00370       if (postal.get_city() == "") {
00371         error_msg = "city is mandatory";
00372         return -1;
00373       }
00374     
00375       if (postal.get_cc() == "") {
00376         error_msg = "country code is mandatory";
00377         return -1;
00378       }
00379     } else {
00380       if (postal.get_name() == "" &&
00381           postal.get_org() == "" &&
00382           postal.get_str1() == "" &&
00383           postal.get_str2() == "" &&
00384           postal.get_str3() == "" &&
00385           postal.get_city() == "" &&
00386           postal.get_sp() == "" &&
00387           postal.get_pc() == "" &&
00388           postal.get_cc() == "") {
00389         error_msg = "empty postal info";
00390         return -1;
00391       }
00392     }   
00393 
00394     return 0;
00395   }
00396 
00398 
00403   static int phone(CommonData::Phone &phone, vector<string> &words)
00404   {
00405     if (words.empty() ||
00406         SheppStrUtil::split(words[0], phone.number, phone.ext, ":", true)
00407         != 0) {
00408       return -1;
00409     }
00410     words.erase(words.begin());
00411     return 0;
00412   }
00413 
00415 
00420   static int disclose(CommonData::Disclose &disclose, string word)
00421   {
00422     string opt1 = word;
00423     string opt2;
00424     while (opt1 != "" &&
00425            SheppStrUtil::split(opt1, opt1, opt2, ",", true) == 0) {
00426       if (opt1 == "name_int") {
00427         disclose.name_int = true;
00428       } else if (opt1 == "name_loc") {
00429         disclose.name_loc = true;
00430       } else if (opt1 == "org_int") {
00431         disclose.org_int = true;
00432       } else if (opt1 == "org_loc") {
00433         disclose.org_loc = true;
00434       } else if (opt1 == "addr_int") {
00435         disclose.addr_int = true;
00436       } else if (opt1 == "addr_loc") {
00437         disclose.addr_loc = true;
00438       } else if (opt1 == "voice") {
00439         disclose.voice = true;
00440       } else if (opt1 == "fax") {
00441         disclose.fax = true;
00442       } else if (opt1 == "email") {
00443         disclose.email = true;
00444       } else {
00445         return -1;
00446       }
00447       opt1 = opt2;
00448     }
00449     return 0;
00450   }
00451 
00452   // brorg specific
00453 
00455 
00461   static int contacts(map<string, string, less<string> > &contacts,
00462                       string args, string &error_msg)
00463   {
00464     string one = args;
00465     string rest;
00466 
00467     do {
00468       if (SheppStrUtil::split(one, one, rest, ",", true) != 0) {
00469         error_msg = "invalid contact";
00470         return -1;
00471       }
00472 
00473       string key;
00474       string value;
00475       if (SheppStrUtil::split(one, key, value, "=", false) != 0) {
00476         error_msg = "invalid contact";
00477         return -1;
00478       }
00479 
00480       contacts[key] = value;
00481 
00482       one = rest;
00483     } while (one != "");
00484 
00485     return 0;
00486   }
00487 };
00488 
00489 #endif //__SHEPP_OBJ_SET_H__

Generated on Tue Mar 20 13:02:18 2007 for libepp_nicbr by  doxygen 1.4.7