00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _GNU_SOURCE
00024
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <time.h>
00028 #include <ctype.h>
00029 #include <math.h>
00030 #include <errno.h>
00031 #include <unistd.h>
00032 #include <string.h>
00033 #include <sys/types.h>
00034 #include <sys/stat.h>
00035 #include <fcntl.h>
00036 #include <dirent.h>
00037 #include <assert.h>
00038 #include <signal.h>
00039 #include <string.h>
00040 #include <search.h>
00041
00042 #include "common.h"
00043
00044 char * configFields = "UseOif SmtpServer MailFrom MailTo ForceParameters OshRunCommand RunCommand MinPause AddPause OshGetParamCommand GetParamCommand OshGetInfoCommand GetInfoCommand OshGetErrorCommand GetErrorCommand OshGetEventListCommand GetEventListCommand OshGetLogCommand GetLogCommand OshGetTriggerCommand GetTriggerCommand PreConnectStation OshWait OshConnect OshKey OshPort OshHangUpStation";
00045
00046
00047
00048
00049
00050
00051 #define PARAMLEN 128
00052 #define NPARAM 1024
00053
00054 struct Parameter {
00055 char name[PARAMLEN];
00056 char value[PARAMLEN];
00057 };
00058
00059 struct Parameter *param;
00060
00065 int ParamCompare(const void *p1, const void *p2)
00066 {
00067 struct Parameter *pp1, *pp2;
00068 pp1=(struct Parameter*)p1;
00069 pp2=(struct Parameter*)p2;
00070 return(strcasecmp(pp1->name,pp2->name));
00071 }
00072
00076 int ReadInputParameters(int m)
00077 {
00078 struct Parameter p;
00079 char line[1024];
00080 unsigned int number=0;
00081 param=(struct Parameter*)malloc(NPARAM*sizeof(struct Parameter));
00082 if (param==NULL)
00083 {
00084 return(-1);
00085 }
00086 memset(param,0,NPARAM*sizeof(struct Parameter));
00087
00088 while (!feof(stdin))
00089 {
00090 char *sp;
00091
00092 if (NULL==fgets(line,1023,stdin))
00093 {
00094 break;
00095 }
00096
00097 sp=strchr(line,'=');
00098 if (sp)
00099 {
00100 struct Parameter *pp;
00101 *sp=' ';
00102 sscanf(line,"%s %s",p.name,p.value);
00103 if (m)
00104 {
00105 if (strlen(p.name)>6)
00106 {
00107 if (strcasecmp("mask",p.name+strlen(p.name)-4)==0)
00108 {
00109 int64_t mask;
00110 ListToMask(p.value,&mask);
00111 sprintf(p.value,"%d",(int)(mask&0xffffff));
00112 }
00113 }
00114 }
00115
00116 pp=lsearch(&p,param,&number,sizeof(struct Parameter),ParamCompare);
00117
00118 if (pp)
00119 {
00120 memcpy(pp,&p,sizeof(struct Parameter));
00121 }
00122 }
00123
00124 }
00125
00126 return((int)number);
00127 }
00128
00132 char * strlower(char *s)
00133 {
00134 char *sp=s;
00135 while (*sp)
00136 {
00137 *sp=tolower(*sp);
00138 sp++;
00139 }
00140 return(s);
00141 }
00142
00145 void DumpParameters(int number, int lower)
00146 {
00147 int i;
00148 #ifdef strcasestr
00149 if (strcasestr(configFields,param[0].name))
00150 #else
00151 if (strstr(configFields,param[0].name))
00152 #endif
00153 {
00154 lower=0;
00155 }
00156 if (lower)
00157 {
00158 for (i=0; i<number; i++)
00159 {
00160 printf("%s=%s\n",strlower(param[i].name),param[i].value);
00161 }
00162 }
00163 else
00164 {
00165 for (i=0; i<number; i++)
00166 {
00167 printf("%s=%s\n",param[i].name,param[i].value);
00168 }
00169 }
00170 }
00171
00175 void ProcessOPF(int m, int lower)
00176 {
00177 DumpParameters(ReadInputParameters(m), lower);
00178 }