CMDLINE.C 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "opendoor.h"
  5. #include "cmdline.h"
  6. #ifndef BOOL
  7. typedef int BOOL;
  8. #endif
  9. typedef enum
  10. {
  11. kParamLocal,
  12. kParamBPS,
  13. kParamPort,
  14. kParamNode,
  15. kParamHelp,
  16. kParamPersonality,
  17. kParamMaxTime,
  18. kParamAddress,
  19. kParamIRQ,
  20. kParamNoFOSSIL,
  21. kParamNoFIFO,
  22. kParamDropFile,
  23. kParamUserName,
  24. kParamTimeLeft,
  25. kParamSecurity,
  26. kParamLocation,
  27. kParamUnknown
  28. } tCommandLineParameter;
  29. static void AdvanceToNextArg(int *pnCurrentArg, int nArgCount,
  30. char *pszOption);
  31. static void GetNextArgName(int *pnCurrentArg, int nArgCount,
  32. char *papszArguments[], char *pszString,
  33. int nStringSize);
  34. static tCommandLineParameter GetCommandLineParameter(char *pszArgument);
  35. void ParseStandardCommandLine(int nArgCount, char *papszArguments[])
  36. {
  37. char *pszCurrentArg;
  38. int nCurrentArg;
  39. for(nCurrentArg = 1; nCurrentArg < nArgCount; ++nCurrentArg)
  40. {
  41. pszCurrentArg = papszArguments[nCurrentArg];
  42. switch(GetCommandLineParameter(pszCurrentArg))
  43. {
  44. case kParamLocal:
  45. od_control.od_force_local = TRUE;
  46. break;
  47. case kParamBPS:
  48. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  49. od_control.baud = atol(papszArguments[nCurrentArg]);
  50. break;
  51. case kParamPort:
  52. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  53. od_control.port = atoi(papszArguments[nCurrentArg]);
  54. break;
  55. case kParamHelp:
  56. printf("AVALIABLE COMMAND LINE PARAMETERS:\n");
  57. printf(" -L or -LOCAL - Causes door to operate in local mode, without requiring a\n");
  58. printf(" door information (drop) file.\n");
  59. printf(" -DROPFILE x - Door information file directory or directory+filename.\n");
  60. printf(" -N x or -NODE x - Sets the node number to use.\n");
  61. printf(" -B x or -BPS x - Sets the serial port <---> modem bps (baud) rate to use.\n");
  62. printf(" -P x or -PORT x - Sets the serial port to use, were 0=COM1, 1=COM2, etc.\n");
  63. printf(" -ADDRESS x - Sets serial port address in decimal NOT hexidecimal\n");
  64. printf(" (only has effect if FOSSIL driver is not being used).\n");
  65. printf(" -IRQ x - Sets the serial port IRQ line (only has effect if FOSSIL\n");
  66. printf(" driver is not being used).\n");
  67. printf(" -NOFOSSIL - Disables use of FOSSIL driver, even if available.\n");
  68. printf(" -NOFIFO - Disables use of 16550 FIFO buffers (only if FOSSIL driver\n");
  69. printf(" is not being used).\n");
  70. printf(" -PERSONALITY x - Sets the sysop status line / function key personality to\n");
  71. printf(" use - one of Standard, PCBoard, RemoteAccess or Wildcat.\n");
  72. printf(" -MAXTIME x - Sets the maximum number of minutes that any user will be\n");
  73. printf(" permitted to access the door.\n");
  74. printf(" -USERNAME x - Name of user who is currently online.\n");
  75. printf(" -TIMELEFT x - User's time remaining online.\n");
  76. printf(" -SECURITY x - User's security level.\n");
  77. printf(" -LOCATION x - Location from which user is calling.\n");
  78. printf(" -?, -H or -HELP - Displays command-line help and exits.\n");
  79. exit(1);
  80. break;
  81. case kParamNode:
  82. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  83. od_control.od_node = atoi(papszArguments[nCurrentArg]);
  84. break;
  85. case kParamPersonality:
  86. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  87. if(stricmp(papszArguments[nCurrentArg], "Standard") == 0)
  88. {
  89. od_control.od_default_personality = PER_OPENDOORS;
  90. }
  91. else if(stricmp(papszArguments[nCurrentArg], "PCBoard") == 0)
  92. {
  93. od_control.od_default_personality = PER_PCBOARD;
  94. }
  95. else if(stricmp(papszArguments[nCurrentArg], "RemoteAccess") == 0)
  96. {
  97. od_control.od_default_personality = PER_RA;
  98. }
  99. else if(stricmp(papszArguments[nCurrentArg], "Wildcat") == 0)
  100. {
  101. od_control.od_default_personality = PER_WILDCAT;
  102. }
  103. else
  104. {
  105. printf("Unknown personality: %s\n", papszArguments[nCurrentArg]);
  106. exit(1);
  107. }
  108. break;
  109. case kParamMaxTime:
  110. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  111. od_control.od_maxtime = atoi(papszArguments[nCurrentArg]);
  112. break;
  113. case kParamAddress:
  114. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  115. od_control.od_com_address = atoi(papszArguments[nCurrentArg]);
  116. break;
  117. case kParamIRQ:
  118. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  119. od_control.od_com_irq = atoi(papszArguments[nCurrentArg]);
  120. break;
  121. case kParamNoFOSSIL:
  122. od_control.od_no_fossil = TRUE;
  123. break;
  124. case kParamNoFIFO:
  125. od_control.od_com_no_fifo = TRUE;
  126. break;
  127. case kParamDropFile:
  128. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  129. strncpy(od_control.info_path, papszArguments[nCurrentArg],
  130. sizeof(od_control.info_path) - 1);
  131. od_control.info_path[sizeof(od_control.info_path) - 1] = '\0';
  132. break;
  133. case kParamUserName:
  134. GetNextArgName(&nCurrentArg, nArgCount, papszArguments,
  135. od_control.user_name, sizeof(od_control.user_name));
  136. break;
  137. case kParamTimeLeft:
  138. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  139. od_control.user_timelimit = atoi(papszArguments[nCurrentArg]);
  140. break;
  141. case kParamSecurity:
  142. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  143. od_control.user_security = atoi(papszArguments[nCurrentArg]);
  144. break;
  145. case kParamLocation:
  146. GetNextArgName(&nCurrentArg, nArgCount, papszArguments,
  147. od_control.user_location, sizeof(od_control.user_location));
  148. break;
  149. default:
  150. printf("Unrecognized command line option: %s\n", pszCurrentArg);
  151. exit(1);
  152. break;
  153. }
  154. }
  155. }
  156. static void AdvanceToNextArg(int *pnCurrentArg, int nArgCount, char *pszOption)
  157. {
  158. if(++*pnCurrentArg >= nArgCount)
  159. {
  160. printf("Missing parameter for option: %s\n", pszOption);
  161. exit(1);
  162. }
  163. }
  164. static void GetNextArgName(int *pnCurrentArg, int nArgCount,
  165. char *papszArguments[], char *pszString,
  166. int nStringSize)
  167. {
  168. BOOL bFirst = TRUE;
  169. if((*pnCurrentArg) + 1 >= nArgCount)
  170. {
  171. printf("Missing parameter for option: %s\n",
  172. papszArguments[(*pnCurrentArg) - 1]);
  173. exit(1);
  174. }
  175. pszString[0] = '\0';
  176. while(++*pnCurrentArg < nArgCount)
  177. {
  178. if(GetCommandLineParameter(papszArguments[*pnCurrentArg])
  179. != kParamUnknown)
  180. {
  181. --*pnCurrentArg;
  182. break;
  183. }
  184. if(strlen(pszString) >= nStringSize - 1)
  185. {
  186. break;
  187. }
  188. if(!bFirst)
  189. {
  190. strcat(pszString, " ");
  191. }
  192. strncat(pszString, papszArguments[*pnCurrentArg],
  193. strlen(pszString) - nStringSize - 1);
  194. pszString[nStringSize - 1] = '\0';
  195. bFirst = FALSE;
  196. }
  197. }
  198. static tCommandLineParameter GetCommandLineParameter(char *pszArgument)
  199. {
  200. if(*pszArgument == '-' || *pszArgument == '/')
  201. {
  202. ++pszArgument;
  203. }
  204. if(stricmp(pszArgument, "L") == 0
  205. || stricmp(pszArgument, "LOCAL") == 0)
  206. {
  207. return(kParamLocal);
  208. }
  209. else if(stricmp(pszArgument, "B") == 0
  210. || stricmp(pszArgument, "BPS") == 0
  211. || stricmp(pszArgument, "BAUD") == 0)
  212. {
  213. return(kParamBPS);
  214. }
  215. else if(stricmp(pszArgument, "P") == 0
  216. || stricmp(pszArgument, "PORT") == 0)
  217. {
  218. return(kParamPort);
  219. }
  220. else if(stricmp(pszArgument, "N") == 0
  221. || stricmp(pszArgument, "NODE") == 0)
  222. {
  223. return(kParamNode);
  224. }
  225. else if(stricmp(pszArgument, "?") == 0
  226. || stricmp(pszArgument, "H") == 0
  227. || stricmp(pszArgument, "HELP") == 0)
  228. {
  229. return(kParamHelp);
  230. }
  231. else if(stricmp(pszArgument, "PERSONALITY") == 0)
  232. {
  233. return(kParamPersonality);
  234. }
  235. else if(stricmp(pszArgument, "MAXTIME") == 0)
  236. {
  237. return(kParamMaxTime);
  238. }
  239. else if(stricmp(pszArgument, "ADDRESS") == 0)
  240. {
  241. return(kParamAddress);
  242. }
  243. else if(stricmp(pszArgument, "IRQ") == 0)
  244. {
  245. return(kParamIRQ);
  246. }
  247. else if(stricmp(pszArgument, "NOFOSSIL") == 0)
  248. {
  249. return(kParamNoFOSSIL);
  250. }
  251. else if(stricmp(pszArgument, "NOFIFO") == 0)
  252. {
  253. return(kParamNoFIFO);
  254. }
  255. else if(stricmp(pszArgument, "DROPFILE") == 0)
  256. {
  257. return(kParamDropFile);
  258. }
  259. else if(stricmp(pszArgument, "USERNAME") == 0)
  260. {
  261. return(kParamUserName);
  262. }
  263. else if(stricmp(pszArgument, "TIMELEFT") == 0)
  264. {
  265. return(kParamTimeLeft);
  266. }
  267. else if(stricmp(pszArgument, "SECURITY") == 0)
  268. {
  269. return(kParamSecurity);
  270. }
  271. else if(stricmp(pszArgument, "LOCATION") == 0)
  272. {
  273. return(kParamLocation);
  274. }
  275. else
  276. {
  277. return(kParamUnknown);
  278. }
  279. }
  280. void NoDoorFileHandler(void)
  281. {
  282. /* Alter OpenDoors behaviour, so that we proceed with defaults if */
  283. /* no door information file is available, rather than exiting with */
  284. /* an error. Set od_no_file_func to point to this function. */
  285. if(strlen(od_control.user_name) == 0)
  286. {
  287. strcpy(od_control.user_name, "Unknown User");
  288. }
  289. if(strlen(od_control.user_location) == 0)
  290. {
  291. strcpy(od_control.user_location, "Unknown Location");
  292. }
  293. if(od_control.user_timelimit == 0)
  294. {
  295. od_control.user_timelimit = 30;
  296. }
  297. od_control.od_info_type = CUSTOM;
  298. }