00001
00002
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
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
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());
00126
00127
00128 if (words.size() < 4) {
00129 error_msg = "not enough arguments for DS";
00130 return -1;
00131 }
00132
00133
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
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());
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());
00182 } else if (words[0] == "-keyData") {
00183 KeyData dnskey;
00184 if (SheppObjSet::keyData(dnskey, words, error_msg) != 0) {
00185 return -1;
00186 }
00187 ds.set_key_data(dnskey);
00188 } else {
00189 break;
00190 }
00191 }
00192
00193 return 0;
00194 }
00195
00197
00202 static int keyData(KeyData &dnskey, vector<string> &words, string &error_msg)
00203 {
00204 if (words.size() < 5) {
00205 error_msg = "not enough arguments for keyData";
00206 return -1;
00207 }
00208
00209 dnskey.set_flags(atoi(words[1].c_str()));
00210 dnskey.set_protocol(atoi(words[2].c_str()));
00211 dnskey.set_algorithm(atoi(words[3].c_str()));
00212 dnskey.set_pub_key(words[4]);
00213
00214 if (dnskey.get_flags() < 0 || dnskey.get_protocol() < 0 ||
00215 dnskey.get_algorithm() < 0) {
00216 error_msg =
00217 "keyData flags, protocol and alg cannot be negative numbers";
00218 return -1;
00219 }
00220 words.erase(words.begin(), words.begin() + 5);
00221
00222 return 0;
00223 }
00224
00225
00226
00228
00235 static int postalInfo(PostalInfo &postal, vector<string> &words,
00236 string &error_msg, bool relaxed)
00237 {
00238
00239 string postal_type = words[0];
00240 words.erase(words.begin());
00241 if (SheppStrUtil::quote_gathering(words, postal_type) != 0) {
00242 error_msg = "error setting postalInfo type";
00243 return -1;
00244 }
00245 postal.set_type(postal_type);
00246
00247 while (!words.empty()) {
00248 if (words[0] == "-name") {
00249
00250 words.erase(words.begin());
00251 if (words.empty()) {
00252 error_msg = "unspecified contact name";
00253 return -1;
00254 }
00255 string postal_name = words[0];
00256 words.erase(words.begin());
00257 if (SheppStrUtil::quote_gathering(words, postal_name) != 0) {
00258 error_msg = "error setting contact name";
00259 return -1;
00260 }
00261 postal.set_name(postal_name);
00262 } else if (words[0] == "-org") {
00263
00264 words.erase(words.begin());
00265 if (words.empty()) {
00266 error_msg = "unspecified organization";
00267 return -1;
00268 }
00269 string postal_org = words[0];
00270 words.erase(words.begin());
00271 if (SheppStrUtil::quote_gathering(words, postal_org) != 0) {
00272 error_msg = "error setting organization";
00273 return -1;
00274 }
00275 postal.set_org(postal_org);
00276 } else if (words[0] == "-street1") {
00277
00278 words.erase(words.begin());
00279 if (words.empty()) {
00280 error_msg = "unspecified address street/line 1";
00281 return -1;
00282 }
00283 string postal_str1 = words[0];
00284 words.erase(words.begin());
00285 if (SheppStrUtil::quote_gathering(words, postal_str1) != 0) {
00286 error_msg = "error setting address street/line 1";
00287 return -1;
00288 }
00289 postal.set_str1(postal_str1);
00290 } else if (words[0] == "-street2") {
00291
00292 words.erase(words.begin());
00293 if (words.empty()) {
00294 error_msg = "unspecified address number/line 2";
00295 return -1;
00296 }
00297 string postal_str2 = words[0];
00298 words.erase(words.begin());
00299 if (SheppStrUtil::quote_gathering(words, postal_str2) != 0) {
00300 error_msg = "error setting address number/line 2";
00301 return -1;
00302 }
00303 postal.set_str2(postal_str2);
00304 } else if (words[0] == "-street3") {
00305
00306 words.erase(words.begin());
00307 if (words.empty()) {
00308 error_msg = "unspecified street3";
00309 return -1;
00310 }
00311 string postal_str3 = words[0];
00312 words.erase(words.begin());
00313 if (SheppStrUtil::quote_gathering(words, postal_str3) != 0) {
00314 error_msg = "error setting address line 3";
00315 return -1;
00316 }
00317 postal.set_str3(postal_str3);
00318 } else if (words[0] == "-city") {
00319
00320 words.erase(words.begin());
00321 if (words.empty()) {
00322 error_msg = "unspecified city";
00323 return -1;
00324 }
00325 string postal_city = words[0];
00326 words.erase(words.begin());
00327 if (SheppStrUtil::quote_gathering(words, postal_city) != 0) {
00328 error_msg = "error setting city";
00329 return -1;
00330 }
00331 postal.set_city(postal_city);
00332 } else if (words[0] == "-state") {
00333
00334 words.erase(words.begin());
00335 if (words.empty()) {
00336 error_msg = "unspecified state";
00337 return -1;
00338 }
00339 string postal_sp = words[0];
00340 words.erase(words.begin());
00341 if (SheppStrUtil::quote_gathering(words, postal_sp) != 0) {
00342 error_msg = "error setting state/province";
00343 return -1;
00344 }
00345 postal.set_sp(postal_sp);
00346 } else if (words[0] == "-pc") {
00347
00348 words.erase(words.begin());
00349 if (words.empty()) {
00350 error_msg = "unspecified postal code";
00351 return -1;
00352 }
00353 string postal_pc = words[0];
00354 words.erase(words.begin());
00355 if (SheppStrUtil::quote_gathering(words, postal_pc) != 0) {
00356 error_msg = "error setting postal code";
00357 return -1;
00358 }
00359 postal.set_pc(postal_pc);
00360 } else if (words[0] == "-cc") {
00361
00362 words.erase(words.begin());
00363 if (words.empty()) {
00364 error_msg = "unspecified country code";
00365 return -1;
00366 }
00367 string postal_cc = words[0];
00368 words.erase(words.begin());
00369 if (SheppStrUtil::quote_gathering(words, postal_cc) != 0) {
00370 error_msg = "error setting country code";
00371 return -1;
00372 }
00373 postal.set_cc(postal_cc);
00374 } else {
00375 break;
00376 }
00377 }
00378
00379
00380 if (!relaxed) {
00381 if (postal.get_name() == "") {
00382 error_msg = "name is mandatory";
00383 return -1;
00384 }
00385
00386 if (postal.get_str1() == "") {
00387 error_msg = "address street/line 1 is mandatory";
00388 return -1;
00389 }
00390
00391 if (postal.get_city() == "") {
00392 error_msg = "city is mandatory";
00393 return -1;
00394 }
00395
00396 if (postal.get_cc() == "") {
00397 error_msg = "country code is mandatory";
00398 return -1;
00399 }
00400 } else {
00401 if (postal.get_name() == "" &&
00402 postal.get_org() == "" &&
00403 postal.get_str1() == "" &&
00404 postal.get_str2() == "" &&
00405 postal.get_str3() == "" &&
00406 postal.get_city() == "" &&
00407 postal.get_sp() == "" &&
00408 postal.get_pc() == "" &&
00409 postal.get_cc() == "") {
00410 error_msg = "empty postal info";
00411 return -1;
00412 }
00413 }
00414
00415 return 0;
00416 }
00417
00419
00424 static int phone(CommonData::Phone &phone, vector<string> &words)
00425 {
00426 if (words.empty() ||
00427 SheppStrUtil::split(words[0], phone.number, phone.ext, ":", true)
00428 != 0) {
00429 return -1;
00430 }
00431 words.erase(words.begin());
00432 return 0;
00433 }
00434
00436
00441 static int disclose(CommonData::Disclose &disclose, string word)
00442 {
00443 string opt1 = word;
00444 string opt2;
00445 while (opt1 != "" &&
00446 SheppStrUtil::split(opt1, opt1, opt2, ",", true) == 0) {
00447 if (opt1 == "name_int") {
00448 disclose.name_int = true;
00449 } else if (opt1 == "name_loc") {
00450 disclose.name_loc = true;
00451 } else if (opt1 == "org_int") {
00452 disclose.org_int = true;
00453 } else if (opt1 == "org_loc") {
00454 disclose.org_loc = true;
00455 } else if (opt1 == "addr_int") {
00456 disclose.addr_int = true;
00457 } else if (opt1 == "addr_loc") {
00458 disclose.addr_loc = true;
00459 } else if (opt1 == "voice") {
00460 disclose.voice = true;
00461 } else if (opt1 == "fax") {
00462 disclose.fax = true;
00463 } else if (opt1 == "email") {
00464 disclose.email = true;
00465 } else {
00466 return -1;
00467 }
00468 opt1 = opt2;
00469 }
00470 return 0;
00471 }
00472
00473
00474
00476
00482 static int contacts(map<string, string, less<string> > &contacts,
00483 string args, string &error_msg)
00484 {
00485 string one = args;
00486 string rest;
00487
00488 do {
00489 if (SheppStrUtil::split(one, one, rest, ",", true) != 0) {
00490 error_msg = "invalid contact";
00491 return -1;
00492 }
00493
00494 string key;
00495 string value;
00496 if (SheppStrUtil::split(one, key, value, "=", false) != 0) {
00497 error_msg = "invalid contact";
00498 return -1;
00499 }
00500
00501 contacts[key] = value;
00502
00503 one = rest;
00504 } while (one != "");
00505
00506 return 0;
00507 }
00508 };
00509
00510 #endif //__SHEPP_OBJ_SET_H__