void conf_irc(char **keys, char **values, int items,void *optarg) { char *server, *nick, *user, *port, *pass, *ssl, *channel; ircserver_t *ircserver = NULL; // Mandatory server = parser_findkey(keys, values, items, "SERVER"); nick = parser_findkey(keys, values, items, "NICK"); user = parser_findkey(keys, values, items, "USER"); if (!server || !nick || !user) { printf("IRC Entry in conf without SERVER, NICK or USER fields.\n"); return; } port = parser_findkey(keys, values, items, "PORT"); pass = parser_findkey(keys, values, items, "PASS"); ssl = parser_findkey(keys, values, items, "SSL"); // Pull out the channel defines. while(( channel = parser_findkey_once(keys, values, items, "CHANNEL"))) { if (!ircserver) { ircserver = irc_addserver(server, port, pass, nick, user, ssl); } if (ircserver) { irc_addchannel(ircserver, channel); } } }
//SITE|NAME=foo|DIR=/tv/|USESKIP=1|INCTEST=%s-INCOMPLETE|LAST_CHECK=123123123 //NUKETEST=!NUKED-%s void conf_site(char **keys, char **values, int items,void *optarg) { char *name, *dir, *useskip, *inctest, *nuketest, *last_check, *hide; site_t *site, **tmp; char **dtmp; char *strtmp; int i; name = parser_findkey(keys, values, items, "NAME"); useskip = parser_findkey(keys, values, items, "USESKIP"); inctest = parser_findkey(keys, values, items, "INCTEST"); nuketest = parser_findkey(keys, values, items, "NUKETEST"); hide = parser_findkey(keys, values, items, "HIDE"); last_check = parser_findkey(keys, values, items, "LAST_CHECK"); if (!name) { printf("SITE Entry in conf without NAME= field\n"); return; } // Attempt to find a site already defined by name, if found, allow // HIDE to be concatenated. for (i = 0; i < num_sites; i++) { if (sites[i] && !mystrccmp(name, sites[i]->name)) { if (hide) { if (!sites[i]->hide) { SAFE_COPY(sites[i]->hide, hide); } else { strtmp = sites[i]->hide; sites[i]->hide = misc_strjoin(strtmp?strtmp:"", hide); SAFE_FREE(strtmp); } } return; } } site = calloc(1, sizeof(*site)); if (!site) return; tmp = realloc(sites, sizeof(site_t *) * (num_sites + 1)); if (!tmp) return; sites = tmp; sites[num_sites] = site; num_sites++; SAFE_COPY(site->name, name); while ((dir = parser_findkey_once(keys, values, items, "DIR"))) { dtmp = (char **) realloc(site->dirs, sizeof(char *) * (site->num_dirs + 1)); if (!dtmp) break; site->dirs = dtmp; site->dirs[ site->num_dirs ] = strdup(dir); site->num_dirs++; } SAFE_COPY(site->inctest, inctest); SAFE_COPY(site->nuketest, nuketest); SAFE_COPY(site->hide, hide); if (useskip) site->use_lists = atoi(useskip); if (last_check) { site->last_check = strtoul(last_check, NULL, 10); site->last_check -= default_age; } else { site->last_check = lion_global_time; site->last_check -= default_age; } site->num_files = 0; }
// // Take a argc/argv pair, parse out the required fields for a site // then save any optional fields for GUIs. // // Return standard error codes, or 0 for success. // int sites_parsekeys(char **keys, char **values, int items, sites_t *node) { int i, len; int xitems; unsigned long set = 0; // make sure we have seen all required fields. xitems = items; #ifdef DEBUG_VERBOSE debugf("[sites_parsekeys] parsing for %p\n", node); #endif for (i = 0; i < items; i++) { // Empty key, just loop if (!keys[i]) continue; len = strlen(keys[i]); #define tester(X) ((sizeof((X))-1 == len) && !strcasecmp(keys[i], (X))) // REQUIRED if (tester("name")) { if (!values[i]) return 1504; // Missing required field SAFE_COPY(node->name, values[i]); keys[i] = NULL; xitems--; set |= 1; } else if (tester("host")) { if (!values[i]) return 1504; SAFE_COPY(node->host, values[i]); keys[i] = NULL; xitems--; set |= 2; } else if (tester("user")) { if (!values[i]) return 1504; SAFE_COPY(node->user, values[i]); keys[i] = NULL; xitems--; set |= 4; } else if (tester("pass")) { if (!values[i]) return 1504; SAFE_COPY(node->pass, values[i]); keys[i] = NULL; xitems--; set |= 8; // OPTIONAL } else if (tester("port")) { if (!values[i]) continue; node->port = atoi(values[i]); keys[i] = NULL; xitems--; } else if (tester("passive")) { if (!values[i]) continue; node->passive = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("fxp_passive")) { if (!values[i]) continue; node->fxp_passive = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("control_TLS")) { if (!values[i]) continue; node->control_TLS = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("data_TLS")) { if (!values[i]) continue; node->data_TLS = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("iface")) { // FIXME!! Use char * if (!values[i]) continue; node->iface = lion_addr(values[i]); keys[i] = NULL; xitems--; } else if (tester("iport")) { if (!values[i]) continue; node->iport = atoi(values[i]); keys[i] = NULL; xitems--; } else if (tester("desired_type")) { if (!values[i]) continue; node->desired_type = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("resume")) { if (!values[i]) continue; node->resume = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("resume_last")) { if (!values[i]) continue; node->resume_last = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("pret")) { if (!values[i]) continue; node->pret = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("fskiplist")) { if (!values[i]) { SAFE_FREE(node->file_skiplist); continue; } SAFE_COPY(node->file_skiplist, values[i]); keys[i] = NULL; xitems--; } else if (tester("dskiplist")) { if (!values[i]) { SAFE_FREE(node->directory_skiplist); continue; } SAFE_COPY(node->directory_skiplist, values[i]); keys[i] = NULL; xitems--; } else if (tester("fpasslist")) { if (!values[i]) { SAFE_FREE(node->file_passlist); continue; } SAFE_COPY(node->file_passlist, values[i]); keys[i] = NULL; xitems--; } else if (tester("dpasslist")) { if (!values[i]) { SAFE_FREE(node->directory_passlist); continue; } SAFE_COPY(node->directory_passlist, values[i]); keys[i] = NULL; xitems--; } else if (tester("fskipempty")) { if (!values[i]) continue; node->file_skipempty = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("dskipempty")) { if (!values[i]) continue; node->directory_skipempty = str2yna(values[i]); keys[i] = NULL; xitems--; } else if (tester("fmovefirst")) { if (!values[i]) { SAFE_FREE(node->file_movefirst); continue; } SAFE_COPY(node->file_movefirst, values[i]); keys[i] = NULL; xitems--; } else if (tester("dmovefirst")) { if (!values[i]) { SAFE_FREE(node->directory_movefirst); continue; } SAFE_COPY(node->directory_movefirst, values[i]); keys[i] = NULL; xitems--; // Parser adds the "type" field to say what command we were // so we had better take it out. } else if (tester("type")) { keys[i] = NULL; xitems--; } else if (tester("SITEID")) { keys[i] = NULL; xitems--; } #undef tester } #ifdef DEBUG_VERBOSE debugf("[sites_parsekeys] saw fields %lu.\n", set); #endif // Check if we saw all required fields. // name, host, user and pass. // Save any left over fields // Subtract the number of matched fields, and allocate the arrays to // hold the remainding. if (xitems) { #ifdef DEBUG_VERBOSE debugf("[sites] %d items remaining..\r\n", xitems); #endif // We want to keep/copy the old key/pairs, and check against fields // given to remove some, or add new. // Find key/value to delete. if (node->items && node->keys) { for (i = 0; i < items; i++) { if (keys[i] && (!values[i] || !values[i][0])) { // Look for keys[i] in the site's keys. If it finds it // it sets it to NULL. (Delete). We also wipe it from // keys to not consider it as an addition. parser_findkey_once(node->keys, node->values, node->items, keys[i]); keys[i] = NULL; xitems--; } } } // All other remaining key/pairs are either changes, or, additions. // Do we need to allocate more space? if (xitems > node->items) { char **tmp; tmp = (char **) realloc(node->keys, sizeof(char *) * xitems); if (!tmp) return 401; // Out of memory node->keys = tmp; tmp = (char **) realloc(node->values, sizeof(char *) * xitems); if (!tmp) return 401; // Out of memory node->values = tmp; } //node->items = xitems; // Assign in... for (i = 0; i < items; i++) { int j, empty; if (keys[i] && values[i]) { // Still set, we should save it. // Attempt to find it, in node->keys for (j = 0, empty = -1; j < node->items; j++) { // If a key position is empty, remember it if (!node->keys[j]) { if (empty < 0) empty = j; continue; // It's empty, don't bother comparing below } if (!strcasecmp(keys[i], node->keys[j])) { // Key exists, just copy over the new value. SAFE_DUPE(node->values[j], values[i]); break; } } // Didn't find it? If so add it. if (j >= node->items) { // Did we not find an empty slot? if (empty == -1) { empty = node->items; // Add more space. node->items++; char **tmp; tmp = (char **) realloc(node->keys, sizeof(char *) * node->items); if (!tmp) return 401; // Out of memory node->keys = tmp; tmp = (char **) realloc(node->values, sizeof(char *) * node->items); if (!tmp) return 401; // Out of memory node->values = tmp; } // Ok, there is space. SAFE_DUPE(node->keys[empty], keys[i]); SAFE_DUPE(node->values[empty], values[i]); } // Added node } // both keys and values set. } // for all remaining items. // We could update node->items when there was deletion.. But they // should not be saved to disk if they are NULL, and so, next load // they are set correctly. // xitems should be 0 here, or something went wrong, but we // can just adjust out value and not panic about it. } // xitems // This check is only for siteadd, not sitemod if ((set & (15)) != 15) return 1504; return 0; }