データ構造 | |
struct | myFILE |
関数 | |
static int | mygetc (myFILE *f) |
static void | myfile_close (myFILE *f) |
static int | FindSectionEnd (myFILE *f) |
static int | AtSectionEnd (myFILE *f) |
static int | EatWhitespace (myFILE *InFile) |
static int | EatComment (myFILE *InFile) |
static int | Continuation (char *line, int pos) |
static BOOL | Section (myFILE *InFile, BOOL(*sfunc)(const char *)) |
static BOOL | Parameter (myFILE *InFile, BOOL(*pfunc)(const char *, const char *), int c) |
static BOOL | Parse (myFILE *InFile, BOOL(*sfunc)(const char *), BOOL(*pfunc)(const char *, const char *)) |
static myFILE * | OpenConfFile (const char *FileName) |
BOOL | pm_process (const char *FileName, BOOL(*sfunc)(const char *), BOOL(*pfunc)(const char *, const char *)) |
変数 | |
BOOL | in_client |
static char * | bufr = NULL |
static int | bSize = 0 |
static int mygetc | ( | myFILE * | f | ) | [static] |
参照先 myFILE::buf・myFILE::p・myFILE::size.
参照元 EatComment()・EatWhitespace()・Parameter()・Section().
00116 { 00117 if (f->p >= f->buf+f->size) 00118 return EOF; 00119 /* be sure to return chars >127 as positive values */ 00120 return (int)( *(f->p++) & 0x00FF ); 00121 }
static void myfile_close | ( | myFILE * | f | ) | [static] |
参照先 myFILE::buf.
参照元 pm_process().
00124 { 00125 if (!f) 00126 return; 00127 SAFE_FREE(f->buf); 00128 SAFE_FREE(f); 00129 }
static int FindSectionEnd | ( | myFILE * | f | ) | [static] |
参照先 myFILE::end_section_p・myFILE::p・strchr_m().
参照元 Section().
00133 { 00134 f->end_section_p = strchr_m(f->p, ']'); 00135 return f->end_section_p ? 1 : 0; 00136 }
static int AtSectionEnd | ( | myFILE * | f | ) | [static] |
参照先 myFILE::end_section_p・myFILE::p.
参照元 Section().
00139 { 00140 if (f->p == f->end_section_p + 1) { 00141 f->end_section_p = NULL; 00142 return 1; 00143 } 00144 return 0; 00145 }
static int EatWhitespace | ( | myFILE * | InFile | ) | [static] |
static int EatComment | ( | myFILE * | InFile | ) | [static] |
static int Continuation | ( | char * | line, | |
int | pos | |||
) | [static] |
参照先 AtSectionEnd()・bSize・bufr・c・Continuation()・EatComment()・EatWhitespace()・FindSectionEnd()・mygetc().
参照元 Parse().
00240 { 00241 int c; 00242 int i; 00243 int end; 00244 const char *func = "params.c:Section() -"; 00245 00246 i = 0; /* <i> is the offset of the next free byte in bufr[] and */ 00247 end = 0; /* <end> is the current "end of string" offset. In most */ 00248 /* cases these will be the same, but if the last */ 00249 /* character written to bufr[] is a space, then <end> */ 00250 /* will be one less than <i>. */ 00251 00252 00253 /* Find the end of the section. We must use mb functions for this. */ 00254 if (!FindSectionEnd(InFile)) { 00255 DEBUG(0, ("%s No terminating ']' character in section.\n", func) ); 00256 return False; 00257 } 00258 00259 c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ 00260 /* past initial white space. */ 00261 00262 while( (EOF != c) && (c > 0) ) { 00263 /* Check that the buffer is big enough for the next character. */ 00264 if( i > (bSize - 2) ) { 00265 char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize +BUFR_INC ); 00266 if(!tb) { 00267 DEBUG(0, ("%s Memory re-allocation failure.", func) ); 00268 return False; 00269 } 00270 bufr = tb; 00271 bSize += BUFR_INC; 00272 } 00273 00274 /* Handle a single character other than section end. */ 00275 switch( c ) { 00276 case '\n': /* Got newline before closing ']'. */ 00277 i = Continuation( bufr, i ); /* Check for line continuation. */ 00278 if( i < 0 ) { 00279 bufr[end] = '\0'; 00280 DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, bufr )); 00281 return False; 00282 } 00283 end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); 00284 c = mygetc( InFile ); /* Continue with next line. */ 00285 break; 00286 00287 default: /* All else are a valid name chars. */ 00288 if(isspace( c )) { 00289 /* One space per whitespace region. */ 00290 bufr[end] = ' '; 00291 i = end + 1; 00292 c = EatWhitespace( InFile ); 00293 } else { 00294 bufr[i++] = c; 00295 end = i; 00296 c = mygetc( InFile ); 00297 } 00298 } 00299 00300 if (AtSectionEnd(InFile)) { 00301 /* Got to the closing bracket. */ 00302 bufr[end] = '\0'; 00303 if( 0 == end ) { 00304 /* Don't allow an empty name. */ 00305 DEBUG(0, ("%s Empty section name in configuration file.\n", func )); 00306 return False; 00307 } 00308 if( !sfunc(bufr) ) /* Got a valid name. Deal with it. */ 00309 return False; 00310 EatComment( InFile ); /* Finish off the line. */ 00311 return True; 00312 } 00313 00314 } 00315 00316 /* We arrive here if we've met the EOF before the closing bracket. */ 00317 DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr )); 00318 return False; 00319 }
static BOOL Parameter | ( | myFILE * | InFile, | |
BOOL(*)(const char *, const char *) | pfunc, | |||
int | c | |||
) | [static] |
参照先 bSize・bufr・Continuation()・EatWhitespace()・mygetc().
参照元 Parse().
00346 { 00347 int i = 0; /* Position within bufr. */ 00348 int end = 0; /* bufr[end] is current end-of-string. */ 00349 int vstart = 0; /* Starting position of the parameter value. */ 00350 const char *func = "params.c:Parameter() -"; 00351 00352 /* Read the parameter name. */ 00353 while( 0 == vstart ) { 00354 /* Loop until we've found the start of the value. */ 00355 if( i > (bSize - 2) ) { 00356 /* Ensure there's space for next char. */ 00357 char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); 00358 if (!tb) { 00359 DEBUG(0, ("%s Memory re-allocation failure.", func) ); 00360 return False; 00361 } 00362 bufr = tb; 00363 bSize += BUFR_INC; 00364 } 00365 00366 switch(c) { 00367 case '=': /* Equal sign marks end of param name. */ 00368 if( 0 == end ) { 00369 /* Don't allow an empty name. */ 00370 DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); 00371 return False; 00372 } 00373 bufr[end++] = '\0'; /* Mark end of string & advance. */ 00374 i = end; /* New string starts here. */ 00375 vstart = end; /* New string is parameter value. */ 00376 bufr[i] = '\0'; /* New string is nul, for now. */ 00377 break; 00378 00379 case '\n': /* Find continuation char, else error. */ 00380 i = Continuation( bufr, i ); 00381 if( i < 0 ) { 00382 bufr[end] = '\0'; 00383 DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, bufr )); 00384 return True; 00385 } 00386 end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); 00387 c = mygetc( InFile ); /* Read past eoln. */ 00388 break; 00389 00390 case '\0': /* Shouldn't have EOF within param name. */ 00391 case EOF: 00392 bufr[i] = '\0'; 00393 DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); 00394 return True; 00395 00396 default: 00397 if(isspace( c )) { 00398 /* One ' ' per whitespace region. */ 00399 bufr[end] = ' '; 00400 i = end + 1; 00401 c = EatWhitespace( InFile ); 00402 } else { 00403 bufr[i++] = c; 00404 end = i; 00405 c = mygetc( InFile ); 00406 } 00407 } 00408 } 00409 00410 /* Now parse the value. */ 00411 c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ 00412 while( (EOF !=c) && (c > 0) ) { 00413 if( i > (bSize - 2) ) { 00414 /* Make sure there's enough room. */ 00415 char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); 00416 if (!tb) { 00417 DEBUG(0, ("%s Memory re-allocation failure.", func)); 00418 return False; 00419 } 00420 bufr = tb; 00421 bSize += BUFR_INC; 00422 } 00423 00424 switch(c) { 00425 case '\r': /* Explicitly remove '\r' because the older */ 00426 c = mygetc( InFile ); /* version called fgets_slash() which also */ 00427 break; /* removes them. */ 00428 00429 case '\n': /* Marks end of value unless there's a '\'. */ 00430 i = Continuation( bufr, i ); 00431 if( i < 0 ) { 00432 c = 0; 00433 } else { 00434 for( end = i; (end >= 0) && isspace((int)bufr[end]); end-- ) 00435 ; 00436 c = mygetc( InFile ); 00437 } 00438 break; 00439 00440 default: /* All others verbatim. Note that spaces do not advance <end>. This allows trimming */ 00441 bufr[i++] = c; 00442 if( !isspace( c ) ) /* of whitespace at the end of the line. */ 00443 end = i; 00444 c = mygetc( InFile ); 00445 break; 00446 } 00447 } 00448 bufr[end] = '\0'; /* End of value. */ 00449 00450 return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ 00451 }
static BOOL Parse | ( | myFILE * | InFile, | |
BOOL(*)(const char *) | sfunc, | |||
BOOL(*)(const char *, const char *) | pfunc | |||
) | [static] |
参照先 c・EatComment()・EatWhitespace()・Parameter()・Section().
参照元 pm_process().
00478 { 00479 int c; 00480 00481 c = EatWhitespace( InFile ); 00482 while( (EOF != c) && (c > 0) ) { 00483 switch( c ) { 00484 case '\n': /* Blank line. */ 00485 c = EatWhitespace( InFile ); 00486 break; 00487 00488 case ';': /* Comment line. */ 00489 case '#': 00490 c = EatComment( InFile ); 00491 break; 00492 00493 case '[': /* Section Header. */ 00494 if( !Section( InFile, sfunc ) ) 00495 return False; 00496 c = EatWhitespace( InFile ); 00497 break; 00498 00499 case '\\': /* Bogus backslash. */ 00500 c = EatWhitespace( InFile ); 00501 break; 00502 00503 default: /* Parameter line. */ 00504 if( !Parameter( InFile, pfunc, c ) ) 00505 return False; 00506 c = EatWhitespace( InFile ); 00507 break; 00508 } 00509 } 00510 return True; 00511 }
static myFILE* OpenConfFile | ( | const char * | FileName | ) | [static] |
参照先 myFILE::buf・myFILE::end_section_p・errno・file_load()・in_client・myFILE::p・myFILE::size・strerror().
参照元 pm_process().
00524 { 00525 const char *func = "params.c:OpenConfFile() -"; 00526 int lvl = in_client?1:0; 00527 myFILE *ret; 00528 00529 ret = SMB_MALLOC_P(myFILE); 00530 if (!ret) 00531 return NULL; 00532 00533 ret->buf = file_load(FileName, &ret->size, 0); 00534 if( NULL == ret->buf ) { 00535 DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", 00536 func, FileName, strerror(errno)) ); 00537 SAFE_FREE(ret); 00538 return NULL; 00539 } 00540 00541 ret->p = ret->buf; 00542 ret->end_section_p = NULL; 00543 return( ret ); 00544 }
BOOL pm_process | ( | const char * | FileName, | |
BOOL(*)(const char *) | sfunc, | |||
BOOL(*)(const char *, const char *) | pfunc | |||
) |
参照先 bSize・bufr・myfile_close()・OpenConfFile()・Parse()・result.
参照元 handle_include().
00563 { 00564 int result; 00565 myFILE *InFile; 00566 const char *func = "params.c:pm_process() -"; 00567 00568 InFile = OpenConfFile( FileName ); /* Open the config file. */ 00569 if( NULL == InFile ) 00570 return False; 00571 00572 DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); 00573 00574 if( NULL != bufr ) { 00575 /* If we already have a buffer */ 00576 /* (recursive call), then just */ 00577 /* use it. */ 00578 result = Parse( InFile, sfunc, pfunc ); 00579 } else { 00580 bSize = BUFR_INC; 00581 bufr = (char *)SMB_MALLOC( bSize ); 00582 if( NULL == bufr ) { 00583 DEBUG(0,("%s memory allocation failure.\n", func)); 00584 myfile_close(InFile); 00585 return False; 00586 } 00587 00588 result = Parse( InFile, sfunc, pfunc ); 00589 SAFE_FREE( bufr ); 00590 bSize = 0; 00591 } 00592 00593 myfile_close(InFile); 00594 00595 if( !result ) { 00596 DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); 00597 return False; 00598 } 00599 00600 return True; 00601 }
loadparm.c の 56 行で定義されています。
char* bufr = NULL [static] |
int bSize = 0 [static] |