int check_location(pam_handle_t *pamh, struct options *opts, char *location_string, struct locations *geo) { struct locations *list; struct locations *loc; double distance; list = loc = parse_locations(pamh, opts, location_string); while (list) { if (list->country == NULL) { if (strcmp(geo->country, "UNKNOWN") == 0) { list = list->next; continue; } if (opts->is_city_db) { distance = calc_distance(list->latitude, list->longitude, geo->latitude, geo->longitude); if (distance <= list->radius) { pam_syslog(pamh, LOG_INFO, "distance(%.3f) < radius(%3.f)", distance, list->radius); sprintf(location_string, "%.3f {%f,%f}", distance, geo->latitude, geo->longitude); free_locations(loc); return 1; } } else pam_syslog(pamh, LOG_INFO, "not a city db edition, ignoring distance entry"); } else { if (opts->debug) pam_syslog(pamh, LOG_INFO, "location: (%s,%s) geoip: (%s,%s)", list->country, list->city, geo->country, geo->city); if ( (list->country[0] == '*' || strcmp(list->country, geo->country) == 0) && (list->city[0] == '*' || strcmp(list->city, geo->city ) == 0) ) { if (opts->debug) pam_syslog(pamh, LOG_INFO, "location [%s,%s] matched: %s,%s", geo->country, geo->city, list->country, list->city); sprintf(location_string, "%s,%s", geo->country, geo->city); free_locations(loc); return 1; } } list = list->next; } if (loc) /* may be NULL */ free_locations(loc); return 0; }
Parser::Parser(string fileName) { //INITIALIZTIONS ifstream dataFile; string line; string data; start_idx = 0; element_counter=0; elements[17]=new Element(">$<"); elements[18]=new Element(">$<"); for(int i=0 ; i < 141; i++) locations[i] = NULL; //Thanks Charlie int section = 0; dataFile.open(fileName.c_str()); if(!dataFile.eof()){ while(getline(dataFile,line)){ data += line + END_LINE; int first_number = getFirstNumberOf(line); if(SEPARATOR == first_number){ section++; } switch(section){ case LONG_DESC_SECTION: parse_locations(line, first_number); break; case SHORT_DESC_SECTION: break; case TRAVEL_TABLE: parse_travel_table(line, first_number); break; case VOCABULARY: parse_vocabulary(line); break; case ELEMENT_DESC: parse_element_desc(line); break; case ELEMENT_LOCATION: parse_element_location(line); break; case ABBR_MSG: parse_abbr_msg(line); break; case ACTIONS: parse_actions(line); break; case LIQUID_ASSET: break; case CLASS_MSG: parse_player_classification(line); break; case HINTS: break; case MAGIC_WORDS: break; }//endSwitch }//endWhile dataFile.close(); } }