Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
8.3 KiB

  1. #include "convlog.h"
  2. INT
  3. ParseArgs (
  4. IN INT argc,
  5. IN PCHAR argv[]
  6. )
  7. {
  8. INT nCount;
  9. UINT nIndex;
  10. CHAR szTemp[MAX_PATH];
  11. //
  12. // Parse the command line and set flags for requested information
  13. // elements. If parameters are incorrect or nonexistant, show usage.
  14. //
  15. if (argc > 1) {
  16. //
  17. // Get command line switches
  18. //
  19. for (nCount = 1; nCount < argc; nCount++) {
  20. PCHAR p;
  21. CHAR c;
  22. p=argv[nCount];
  23. if ((*p == '-') || (*p == '/')) {
  24. p++;
  25. c = *p;
  26. if (c == '\0') {
  27. continue;
  28. }
  29. p++;
  30. switch (tolower(c)) { // Process switches
  31. // They specified the -s switch, cancel default
  32. // services to be processed.
  33. //
  34. case 'i':
  35. //
  36. // Get input logfile type
  37. //
  38. if ( *p != '\0' ) {
  39. switch (tolower(*p)) {
  40. case 'i':
  41. LogFileFormat = LOGFILE_MSINET;
  42. break;
  43. case 'n':
  44. LogFileFormat = LOGFILE_NCSA;
  45. NoFormatConversion = TRUE;
  46. break;
  47. case 'e':
  48. LogFileFormat = LOGFILE_CUSTOM;
  49. break;
  50. default:
  51. LogFileFormat = LOGFILE_INVALID;
  52. }
  53. } else {
  54. return (ILLEGAL_COMMAND_LINE);
  55. }
  56. break;
  57. case 'l':
  58. //
  59. // Get date format/valid for MS INET Log only
  60. //
  61. if ( *p != '\0' ) {
  62. switch (*p) {
  63. case '0':
  64. dwDateFormat = DateFormatUsa;
  65. break;
  66. case '1':
  67. dwDateFormat = DateFormatJapan;
  68. break;
  69. case '2':
  70. dwDateFormat = DateFormatGermany;
  71. break;
  72. default:
  73. return (ILLEGAL_COMMAND_LINE);
  74. }
  75. } else {
  76. return (ILLEGAL_COMMAND_LINE);
  77. }
  78. break;
  79. case 't':
  80. if ((nCount+1) < argc) {
  81. if ((*argv[nCount+1] != '-') &&
  82. (*argv[nCount+1] != '/')) {
  83. PCHAR pTmp;
  84. strcpy(szTemp, argv[++nCount]);
  85. pTmp = strstr(_strlwr(szTemp), "ncsa");
  86. if (pTmp != NULL ) {
  87. pTmp = strstr(szTemp, ":" );
  88. if (NULL != pTmp ) {
  89. strncpy(NCSAGMTOffset,pTmp+1,6);
  90. if (strlen(NCSAGMTOffset) != 5) {
  91. return (ILLEGAL_COMMAND_LINE);
  92. }
  93. if (('+' != NCSAGMTOffset[0]) &&
  94. ('-' != NCSAGMTOffset[0])) {
  95. return (ILLEGAL_COMMAND_LINE);
  96. }
  97. }
  98. } else if (0 == _stricmp(szTemp, "none")) {
  99. NoFormatConversion = TRUE;
  100. DoDNSConversion = TRUE;
  101. } else {
  102. return (ILLEGAL_COMMAND_LINE);
  103. }
  104. } else {
  105. return (ILLEGAL_COMMAND_LINE);
  106. }
  107. }
  108. break;
  109. case 's':
  110. case 'f':
  111. //
  112. // Do nothing. For compatibility with old convlog versions.
  113. //
  114. break;
  115. case 'n':
  116. case 'd':
  117. //
  118. // doing NCSA dns convertion
  119. //
  120. DoDNSConversion = TRUE;
  121. break;
  122. case 'x':
  123. //
  124. // doing NCSA dns convertion
  125. //
  126. SaveFTPEntries = TRUE;
  127. break;
  128. case 'o':
  129. //
  130. // output directory
  131. //
  132. if ((nCount+1) < argc) {
  133. if ((*argv[nCount+1] != '-') &&
  134. (*argv[nCount+1] != '/')) {
  135. strcpy(OutputDir, argv[++nCount]);
  136. if (-1 == _access(OutputDir, 6)) {
  137. return (OUT_DIR_NOT_OK);
  138. }
  139. if ('\\' != *CharPrev(OutputDir, &OutputDir[strlen(OutputDir)])) {
  140. strcat(OutputDir, "\\");
  141. }
  142. }
  143. } else {
  144. return (ILLEGAL_COMMAND_LINE);
  145. }
  146. break;
  147. case 'c':
  148. //
  149. // on error, continue processing file // WinSE 9148
  150. //
  151. bOnErrorContinue = TRUE;
  152. break;
  153. default:
  154. return(ILLEGAL_COMMAND_LINE);
  155. } //end switch
  156. } else {
  157. strcpy(InputFileName, argv[nCount]);
  158. }
  159. } //end for
  160. if ('\0' == InputFileName[0]) {
  161. return (ILLEGAL_COMMAND_LINE);
  162. }
  163. } else {
  164. return (ILLEGAL_COMMAND_LINE);
  165. }
  166. if ( LogFileFormat == LOGFILE_INVALID ) {
  167. return (ILLEGAL_COMMAND_LINE);
  168. }
  169. if ( NoFormatConversion &&
  170. ((LogFileFormat != LOGFILE_MSINET) &&
  171. (LogFileFormat != LOGFILE_NCSA)) ) {
  172. return (ERROR_BAD_NONE);
  173. }
  174. if (('\0' == NCSAGMTOffset[0])) {
  175. DWORD dwRet;
  176. INT nMinOffset;
  177. TIME_ZONE_INFORMATION tzTimeZone;
  178. DWORD minutes;
  179. DWORD hours;
  180. LONG bias;
  181. dwRet = GetTimeZoneInformation (&tzTimeZone);
  182. if ( dwRet == 0xffffffff ) {
  183. bias = 0;
  184. } else {
  185. bias = tzTimeZone.Bias;
  186. //
  187. // Use real bias to be compatible with how IIS writes its log
  188. // file (see bugs 29002 and 415318).
  189. //
  190. switch (dwRet) {
  191. case TIME_ZONE_ID_STANDARD:
  192. if ( tzTimeZone.StandardDate.wMonth != 0 ) {
  193. bias += tzTimeZone.StandardBias;
  194. }
  195. break;
  196. case TIME_ZONE_ID_DAYLIGHT:
  197. if ( tzTimeZone.DaylightDate.wMonth != 0 ) {
  198. bias += tzTimeZone.DaylightBias;
  199. }
  200. break;
  201. case TIME_ZONE_ID_UNKNOWN:
  202. default:
  203. break;
  204. }
  205. }
  206. if ( bias > 0 ) {
  207. strcat(NCSAGMTOffset, "-");
  208. } else {
  209. strcat(NCSAGMTOffset, "+");
  210. bias *= -1;
  211. }
  212. hours = bias/60;
  213. minutes = bias % 60;
  214. sprintf (szTemp, "%02lu", hours);
  215. strcat (NCSAGMTOffset, szTemp);
  216. sprintf (szTemp, "%02lu", minutes);
  217. strcat (NCSAGMTOffset, szTemp);
  218. if ( LogFileFormat == LOGFILE_CUSTOM ) {
  219. strcpy(NCSAGMTOffset,"+0000");
  220. }
  221. }
  222. return COMMAND_LINE_OK;
  223. } //end of ParseArgs