|
|
1.1 ! root 1: /* ! 2: ****************************************************************************** ! 3: * ! 4: * Module: bb_codata.c ! 5: * ! 6: * Description: ! 7: * ! 8: * Functions: ! 9: * bb_put_codata() - Place a company data entry in the structure. ! 10: * bb_get_codata() - Get a company data entry from the structure. ! 11: * bb_get_imp_cnt() - Return the number of implementations. ! 12: * bb_read_companies() - Read the company data file. ! 13: * bb_read_1_codata() - Read a single company data from the file. ! 14: * ! 15: * ! 16: ****************************************************************************** ! 17: */ ! 18: ! 19: /* ! 20: ****************************************************************************** ! 21: * Include Files ! 22: ****************************************************************************** ! 23: */ ! 24: #include <stdio.h> ! 25: #include <rpc/rpc.h> ! 26: #include "common.h" ! 27: #include "protocol.h" ! 28: #include "server.h" ! 29: ! 30: ! 31: static int co_cnt; /* The number of company data entries. */ ! 32: static BB_co_data codata[BB_MAX_IMP];/* The company data records. */ ! 33: ! 34: void bb_get_ip_lines(); ! 35: char *strtok(); ! 36: ! 37: ! 38: int ! 39: bb_put_codata( p_codata) ! 40: BB_co_data *p_codata; /* The company data to put in the table */ ! 41: { ! 42: if ( co_cnt + 1 >= BB_MAX_IMP ) ! 43: { ! 44: fprintf( stderr, "FAILURE can't install company data record: %s.\n", ! 45: p_codata->company); ! 46: return BB_FAILURE; ! 47: } ! 48: ! 49: memcpy( &codata[ co_cnt], p_codata, sizeof( *p_codata)); ! 50: return co_cnt++; ! 51: } ! 52: ! 53: int ! 54: bb_get_codata( index, p_codata) ! 55: int index; /* The index of the data to retrieve. */ ! 56: BB_co_data *p_codata; /* Space to put the data. */ ! 57: { ! 58: if ( index >= co_cnt ) ! 59: { ! 60: return BB_FAILURE; ! 61: } ! 62: ! 63: memcpy( p_codata, &codata[ index], sizeof( *p_codata)); ! 64: return BB_SUCCESS; ! 65: } ! 66: ! 67: int ! 68: bb_get_imp_cnt() ! 69: { ! 70: return co_cnt; ! 71: } ! 72: ! 73: ! 74: /************************************************************************* ! 75: ** ** ! 76: ** bb_read_companies() - Read the file containing the company data. ** ! 77: ** For each entry create a company data record, and add an entry in the** ! 78: ** hash table. The company data file also contains IP addresses, which** ! 79: ** are stored in the ip_table. ** ! 80: ** ** ! 81: *************************************************************************/ ! 82: int ! 83: bb_read_companies() ! 84: { ! 85: int status; /* Status of function call returns. */ ! 86: int index; /* Index of the company data record. */ ! 87: BB_co_data cdata; /* Space for the readding of records. */ ! 88: ! 89: while( (status = bb_read_1_codata( &cdata)) != BB_END_OF_FILE ) ! 90: { ! 91: /* ! 92: ** If the read was not successful exit. ! 93: */ ! 94: if ( status != BB_SUCCESS ) ! 95: { ! 96: fprintf( stderr, "ABORTING: Can't read company data file.\n"); ! 97: return BB_FAILURE; ! 98: } ! 99: ! 100: /* ! 101: ** Put the company data record in the array. ! 102: */ ! 103: if ( (index = bb_put_codata( &cdata)) == BB_FAILURE ) ! 104: { ! 105: fprintf( stderr, "ABORTING: Not enough company data space.\n"); ! 106: return BB_FAILURE; ! 107: } ! 108: ! 109: /* ! 110: ** Fill in the hash record for the company data record. ! 111: */ ! 112: if ( bb_put_hash( codata[index].id, index) != BB_SUCCESS ) ! 113: { ! 114: fprintf( stderr, "ABORTING: Unable to hash company: %s.\n", ! 115: cdata.company); ! 116: return BB_FAILURE; ! 117: } ! 118: } ! 119: ! 120: /* ! 121: ** Read all of the company data with no problems. ! 122: */ ! 123: return BB_SUCCESS; ! 124: } ! 125: ! 126: ! 127: /************************************************************************* ! 128: ** ** ! 129: ** bb_read_1_codata() - Read one company data record from the co data ** ! 130: ** file. If the file is not open then open it and start readding. The ** ! 131: ** file is ordered in the same manner as the BB_co_data structure. IP ** ! 132: ** means a set of internet addresses are on the same line. Each of ** ! 133: ** these addresses belongs to the companies that follow up to the next ** ! 134: ** IP specification. ** ! 135: ** ** ! 136: *************************************************************************/ ! 137: static FILE *file = NULL; /* File pointer to company data file. */ ! 138: ! 139: int ! 140: bb_read_1_codata( p_codata) ! 141: BB_co_data *p_codata; /* Output a company data record. */ ! 142: { ! 143: static int ip_count; /* Number of IP addresses for company. */ ! 144: static int ip_index; /* Place where IP addresses start. */ ! 145: bool_t done = FALSE; /* Done readding this codata record. */ ! 146: char line[BB_MAX_LINE_LEN]; /* Input line buffer. */ ! 147: ! 148: /* ! 149: ** If the file is not open then it neads to be. ! 150: */ ! 151: if ( file == NULL ) ! 152: { ! 153: if ( (file = fopen( BB_CODATA_FILE, "r")) == NULL ) ! 154: { ! 155: fprintf( stderr, "FAILED opening the company data file '%s'.\n", ! 156: BB_CODATA_FILE); ! 157: return BB_FAILURE; ! 158: } ! 159: ! 160: ip_count = ip_index = 0; ! 161: } ! 162: ! 163: while ( done != TRUE ) ! 164: { ! 165: do ! 166: { ! 167: if ( fgets( line, BB_MAX_LINE_LEN, file) == NULL ) ! 168: { ! 169: return BB_END_OF_FILE; ! 170: } ! 171: } ! 172: while ( line[0] == BB_COMMENT_DESIGNATOR ); ! 173: ! 174: switch ( line[BB_DES_CHAR] ) ! 175: { ! 176: case BB_IP_DESIGNATOR: ! 177: bb_get_ip_lines( &line[BB_DES_START], ! 178: &ip_count, &ip_index); ! 179: break; ! 180: case BB_CO_DESIGNATOR: ! 181: line[strlen(line)-1] = NUL; ! 182: strncpy( p_codata->company, &line[BB_DES_START], ! 183: BB_COMPANY_NAME_LEN); ! 184: break; ! 185: case BB_IMP_DESIGNATOR: ! 186: line[strlen(line)-1] = NUL; ! 187: strncpy( p_codata->imp, &line[BB_DES_START], ! 188: BB_IMP_NAME_LEN); ! 189: break; ! 190: case BB_ID_DESIGNATOR: ! 191: line[strlen(line)-1] = NUL; ! 192: strncpy( p_codata->id, &line[BB_DES_START], ! 193: BB_ID_NAME_LEN); ! 194: break; ! 195: case BB_BOOTH_DESIGNATOR: ! 196: p_codata->booth = atoi( &line[BB_DES_START]); ! 197: break; ! 198: case BB_FLAGS_DESIGNATOR: ! 199: p_codata->flags = atoi( &line[BB_DES_START]); ! 200: break; ! 201: case BB_END_DESIGNATOR: ! 202: done = TRUE; ! 203: break; ! 204: default : ! 205: if ( line[0] != '\n' ) ! 206: { ! 207: fprintf( stderr, "ERROR: Invalid field designator '%s'.\n", ! 208: line); ! 209: } ! 210: break; ! 211: } ! 212: } ! 213: p_codata->ip_cnt = ip_count; ! 214: p_codata->ip_idx = ip_index; ! 215: ! 216: return BB_SUCCESS; ! 217: } ! 218:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.