src/shepp/SheppObjSet.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: SheppObjSet.H 581 2006-03-15 18:55:45Z 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(CommonData::PostalInfo &postal,
00128                         vector<string> &words,
00129                         string &error_msg, bool relaxed)
00130   {
00131     postal.type = words[0];
00132     words.erase(words.begin());
00133 
00134     while (!words.empty()) {
00135       if (words[0] == "-name") {
00136         //name
00137         words.erase(words.begin());
00138         if (words.empty()) {
00139           error_msg = "unspecified contact name";
00140           return -1;
00141         }
00142         postal.name = words[0];
00143         words.erase(words.begin());
00144         if (SheppStrUtil::quote_gathering(words, postal.name) != 0) {
00145           error_msg = "error setting contact name";
00146           return -1;
00147         }
00148       } else if (words[0] == "-org") {
00149         //org
00150         words.erase(words.begin());
00151         if (words.empty()) {
00152           error_msg = "unspecified organization";
00153           return -1;
00154         }
00155         postal.org = words[0];
00156         words.erase(words.begin());
00157         if (SheppStrUtil::quote_gathering(words, postal.org) != 0) {
00158           error_msg = "error setting organization";
00159           return -1;
00160         }
00161       } else if (words[0] == "-street1") {
00162         //street1
00163         words.erase(words.begin());
00164         if (words.empty()) {
00165           error_msg = "unspecified street1";
00166           return -1;
00167         }
00168         postal.str1 = words[0];
00169         words.erase(words.begin());
00170         if (SheppStrUtil::quote_gathering(words, postal.str1) != 0) {
00171           error_msg = "error setting address line 1";
00172           return -1;
00173         }
00174       } else if (words[0] == "-street2") {
00175         //street2
00176         words.erase(words.begin());
00177         if (words.empty()) {
00178           error_msg = "unspecified street2";
00179           return -1;
00180         }
00181         postal.str2 = words[0];
00182         words.erase(words.begin());
00183         if (SheppStrUtil::quote_gathering(words, postal.str2) != 0) {
00184           error_msg = "error setting address line 2";
00185           return -1;
00186         }
00187       } else if (words[0] == "-street3") {
00188         //street3
00189         words.erase(words.begin());
00190         if (words.empty()) {
00191           error_msg = "unspecified street3";
00192           return -1;
00193         }
00194         postal.str3 = words[0];
00195         words.erase(words.begin());
00196         if (SheppStrUtil::quote_gathering(words, postal.str3) != 0) {
00197           error_msg = "error setting address line 3";
00198           return -1;
00199         }
00200       } else if (words[0] == "-city") {
00201         //city
00202         words.erase(words.begin());
00203         if (words.empty()) {
00204           error_msg = "unspecified city";
00205           return -1;
00206         }
00207         postal.city = words[0];
00208         words.erase(words.begin());
00209         if (SheppStrUtil::quote_gathering(words, postal.city) != 0) {
00210           error_msg = "error setting city";
00211           return -1;
00212         }
00213       } else if (words[0] == "-state") {
00214         //state
00215         words.erase(words.begin());
00216         if (words.empty()) {
00217           error_msg = "unspecified state";
00218           return -1;
00219         }
00220         postal.sp = words[0];
00221         words.erase(words.begin());
00222         if (SheppStrUtil::quote_gathering(words, postal.sp) != 0) {
00223           error_msg = "error setting state/province";
00224           return -1;
00225         }
00226       } else if (words[0] == "-pc") {
00227         //pc
00228         words.erase(words.begin());
00229         if (words.empty()) {
00230           error_msg = "unspecified postal code";
00231           return -1;
00232         }
00233         postal.pc = words[0];
00234         words.erase(words.begin());
00235         if (SheppStrUtil::quote_gathering(words, postal.pc) != 0) {
00236           error_msg = "error setting postal code";
00237           return -1;
00238         }
00239       } else if (words[0] == "-cc") {
00240         words.erase(words.begin());
00241         if (words.empty()) {
00242           error_msg = "unspecified country code";
00243           return -1;
00244         }
00245         postal.cc = words[0];
00246         words.erase(words.begin());
00247       } else {
00248         break;
00249       }
00250     }
00251 
00252     //relaxed: update; !relaxed: create
00253     if (!relaxed) {
00254       if (postal.name == "") {
00255         error_msg = "name is mandatory";
00256         return -1;
00257       }
00258 
00259       if (postal.str1 == "") {
00260         error_msg = "address line 1 is mandatory";
00261         return -1;
00262       }
00263     
00264       if (postal.city == "") {
00265         error_msg = "city is mandatory";
00266         return -1;
00267       }
00268     
00269       if (postal.cc == "") {
00270         error_msg = "country code is mandatory";
00271         return -1;
00272       }
00273     } else {
00274       if (postal.name == "" &&
00275           postal.org == "" &&
00276           postal.str1 == "" &&
00277           postal.str2 == "" &&
00278           postal.str3 == "" &&
00279           postal.city == "" &&
00280           postal.sp == "" &&
00281           postal.pc == "" &&
00282           postal.cc == "") {
00283         error_msg = "empty postal info";
00284         return -1;
00285       }
00286     }   
00287 
00288     return 0;
00289   }
00290 
00292 
00297   static int phone(CommonData::Phone &phone, vector<string> &words)
00298   {
00299     if (words.empty() ||
00300         SheppStrUtil::split(words[0], phone.number, phone.ext, ":", true)
00301         != 0) {
00302       return -1;
00303     }
00304     words.erase(words.begin());
00305     return 0;
00306   }
00307 
00309 
00314   static int disclose(CommonData::Disclose &disclose, string word)
00315   {
00316     string opt1 = word;
00317     string opt2;
00318     while (opt1 != "" &&
00319            SheppStrUtil::split(opt1, opt1, opt2, ",", true) == 0) {
00320       if (opt1 == "name_int") {
00321         disclose.name_int = true;
00322       } else if (opt1 == "name_loc") {
00323         disclose.name_loc = true;
00324       } else if (opt1 == "org_int") {
00325         disclose.org_int = true;
00326       } else if (opt1 == "org_loc") {
00327         disclose.org_loc = true;
00328       } else if (opt1 == "addr_int") {
00329         disclose.addr_int = true;
00330       } else if (opt1 == "addr_loc") {
00331         disclose.addr_loc = true;
00332       } else if (opt1 == "voice") {
00333         disclose.voice = true;
00334       } else if (opt1 == "fax") {
00335         disclose.fax = true;
00336       } else if (opt1 == "email") {
00337         disclose.email = true;
00338       } else {
00339         return -1;
00340       }
00341       opt1 = opt2;
00342     }
00343     return 0;
00344   }
00345 
00346   // brorg specific
00347 
00349 
00355   static int contacts(map<string, string, less<string> > &contacts,
00356                       string args, string &error_msg)
00357   {
00358     string one = args;
00359     string rest;
00360 
00361     do {
00362       if (SheppStrUtil::split(one, one, rest, ",", true) != 0) {
00363         error_msg = "invalid contact";
00364         return -1;
00365       }
00366 
00367       string key;
00368       string value;
00369       if (SheppStrUtil::split(one, key, value, "=", false) != 0) {
00370         error_msg = "invalid contact";
00371         return -1;
00372       }
00373 
00374       contacts[key] = value;
00375 
00376       one = rest;
00377     } while (one != "");
00378 
00379     return 0;
00380   }
00381 };
00382 
00383 #endif //__SHEPP_OBJ_SET_H__

Generated on Wed Mar 22 14:18:27 2006 for libepp_nicbr by  doxygen 1.4.6