- bug fix in coc_server.c
- bug fixes in tecs - new system to determine host:port in six and tecs_client
This commit is contained in:
@@ -1,97 +1,146 @@
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "myc_str.h"
|
||||
#include "myc_fortran.h"
|
||||
#include "instr_hosts.h"
|
||||
|
||||
typedef struct { char *instr; char *host; int port; char *user; int cod; } Instrument;
|
||||
static Instrument list[]={
|
||||
{ "DMC", "pc4629.psi.ch", 9753, "dmc" , 1},
|
||||
{ "MORPHEUS", "pc4120.psi.ch", 9753, "morpheus" , 1},
|
||||
{ "SANS", "pc4122.psi.ch", 9753, "sans" , 1},
|
||||
{ "SANS2", "sans2.psi.ch", 9753, "sans2" , 1},
|
||||
{ "HRPT", "pc4630.psi.ch", 9753, "hrpt" , 1},
|
||||
{ "TRICS", "trics.psi.ch", 9753, "trics" , 1},
|
||||
{ "AMOR", "amor.psi.ch", 9753, "amor" , 1},
|
||||
{ "FOCUS", "focus.psi.ch", 9753, "focus" , 1},
|
||||
{ "TASP", "pc4478.psi.ch", 9753, "tasp", 1},
|
||||
{ "RITA", "pc4345.psi.ch", 9753, NULL , 0},
|
||||
{ "PREP", "lns1se.psi.ch", 9753, "admin" , 0},
|
||||
{ "AREA", "lns1se.psi.ch", 9751, "admin" , 0},
|
||||
{ "PREP1", "lnsl15.psi.ch", 9753, "l_samenv", 0},
|
||||
{ "PREP2", "lnsl15.psi.ch", 9754, "l_samenv", 0},
|
||||
{ "PREP3", "lnsl15.psi.ch", 9755, "l_samenv", 0},
|
||||
{ "PREP4", "lnsl15.psi.ch", 9756, "l_samenv", 0},
|
||||
{ "TEST", "lnsa15.psi.ch", 9755, "lnslib", 2}
|
||||
};
|
||||
|
||||
int InstrHost(char *input, char *instr, char *host, char *user, char *pcod
|
||||
, int instr_len, int host_len, int user_len, int pcod_len) {
|
||||
char buf[256], *lnscode;
|
||||
int i, j;
|
||||
struct tm tim;
|
||||
time_t t;
|
||||
|
||||
j=-1;
|
||||
str_upcase(buf, input);
|
||||
for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
|
||||
if (0==strcmp(buf, list[i].instr)) {
|
||||
j=i;
|
||||
}
|
||||
static char *getItem(char *line, char *name, char *value, int value_len) {
|
||||
char find[32];
|
||||
char *found, *sp, *result;
|
||||
int l;
|
||||
|
||||
snprintf(find, sizeof find, "%s=%s", name, value);
|
||||
found = strstr(line, find);
|
||||
if (found && *value != '\0' && found[strlen(find)] > ' ') {
|
||||
/* when value is given, it must be complete */
|
||||
found = NULL;
|
||||
}
|
||||
if (j<0) {
|
||||
str_lowcase(buf, input);
|
||||
for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
|
||||
if (list[i].host==strstr(list[i].host, buf)) {
|
||||
if (j>=0) return 0;
|
||||
j=i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j<0) return 0;
|
||||
str_ncpy(instr,list[j].instr, instr_len);
|
||||
str_ncpy(host, list[j].host, host_len);
|
||||
if (list[j].user != NULL) {
|
||||
str_ncpy(user, list[j].user, user_len);
|
||||
if (list[j].cod == 1) {
|
||||
str_ncpy(pcod, instr, pcod_len);
|
||||
str_ncat(pcod, "LNS", pcod_len);
|
||||
} else if (list[j].cod == 2) {
|
||||
time(&t);
|
||||
tim=*localtime(&t);
|
||||
lnscode=getenv("LNSCODE");
|
||||
if (lnscode == NULL) {
|
||||
sprintf(pcod, "%02dlns%d", tim.tm_year % 100, tim.tm_mon/6+1);
|
||||
} else if (strlen(lnscode)==3) {
|
||||
sprintf(pcod, "%c%clns%c", lnscode[0], lnscode[1], lnscode[2]);
|
||||
} else {
|
||||
sprintf(pcod, "%02dlns%s", tim.tm_year % 100, lnscode);
|
||||
}
|
||||
if (found) {
|
||||
found += strlen(name)+1;
|
||||
if (value_len == 0) {
|
||||
result = found;
|
||||
} else {
|
||||
str_ncpy(pcod, " ", pcod_len);
|
||||
sp = strchr(found, ' ');
|
||||
if (sp && sp < found + value_len) {
|
||||
l = sp - found;
|
||||
} else {
|
||||
l = strlen(found);
|
||||
}
|
||||
if (l < value_len) {
|
||||
strncpy(value, found, l);
|
||||
value[l] = '\0';
|
||||
result = value;
|
||||
} else {
|
||||
value[0] = '\0';
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (value_len > 0) {
|
||||
*value = '\0';
|
||||
}
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int InstrHost(char *service, char *input, char *instr, int instr_len,
|
||||
char *host, int host_len, int *port) {
|
||||
int i;
|
||||
FILE *fil, *lfil;
|
||||
char *hostlist;
|
||||
char localhostlist[512];
|
||||
char line[512], lline[512], hostport[64];
|
||||
char *found, *colon, *crit;
|
||||
int dirty, home, finished;
|
||||
|
||||
home = 0;
|
||||
hostlist = getenv("InstrumentHostList");
|
||||
if (!hostlist) {
|
||||
hostlist="/afs/psi.ch/project/sinq/common/lib/sea/hostlist";
|
||||
}
|
||||
fil = fopen(hostlist, "r");
|
||||
snprintf(localhostlist, sizeof localhostlist, "%s/.six/hostlist", getenv("HOME"));
|
||||
lfil = fopen(localhostlist, "r");
|
||||
dirty = 0;
|
||||
if (fil) {
|
||||
if (!lfil) dirty = 1;
|
||||
} else {
|
||||
if (!lfil) return 0;
|
||||
fil = lfil;
|
||||
lfil = NULL;
|
||||
}
|
||||
*port = 0;
|
||||
if (input == NULL || input[0] <= ' ') {
|
||||
crit = "host";
|
||||
input = getenv("HOST");
|
||||
} else {
|
||||
crit="instr";
|
||||
}
|
||||
finished = 0;
|
||||
while (NULL != fgets(line, sizeof line, fil)) {
|
||||
if (!dirty && lfil
|
||||
&& (fgets(lline, sizeof lline, lfil) == NULL
|
||||
|| strcmp(line, lline) != 0)) {
|
||||
dirty = 1;
|
||||
}
|
||||
if (!finished && getItem(line, crit, input, 0) != NULL) {
|
||||
hostport[0]='\0';
|
||||
found = getItem(line, service, hostport, sizeof hostport);
|
||||
if (found) {
|
||||
instr[0] = '\0';
|
||||
getItem(line, "instr", instr, instr_len);
|
||||
colon = strchr(hostport, ':');
|
||||
if (colon) {
|
||||
i = atoi(colon+1);
|
||||
if (i > 0) {
|
||||
*colon='\0';
|
||||
snprintf(host, host_len, "%s", hostport);
|
||||
finished = 1;
|
||||
*port = i;
|
||||
if (getItem(line, "host", getenv("HOST"), 0) != NULL) {
|
||||
home = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list[j].port;
|
||||
if (fil) fclose(fil);
|
||||
if (lfil) fclose(lfil);
|
||||
if (dirty) {
|
||||
fil = fopen(hostlist, "r");
|
||||
if (fil) {
|
||||
lfil = fopen(localhostlist, "w");
|
||||
if (lfil) {
|
||||
while( EOF != (i = getc(fil)) ) { /* copy file to local file */
|
||||
putc(i, lfil);
|
||||
}
|
||||
fclose(lfil);
|
||||
}
|
||||
fclose(fil);
|
||||
}
|
||||
}
|
||||
return home;
|
||||
}
|
||||
|
||||
|
||||
#ifdef F_CHAR
|
||||
#ifdef MYC_FORTRAN
|
||||
/* compile only when fortran c interface stuff is defined */
|
||||
|
||||
int F_FUN(instr_host)(F_CHAR(input), F_CHAR(instr), F_CHAR(host), F_CHAR(user), F_CHAR(pcod)
|
||||
, int input_len, int instr_len, int host_len, int user_len, int pcod_len) {
|
||||
char buf[256], in[256], ho[256], us[256], pc[256];
|
||||
#include "myc_fortran.h"
|
||||
|
||||
int F_FUN(instr_host)(F_CHAR(service), F_CHAR(input), F_CHAR(instr), F_CHAR(host), int *port
|
||||
, int service_len, int input_len, int instr_len, int host_len) {
|
||||
char buf[256], in[256], ho[256], sv[256];
|
||||
int iRet;
|
||||
|
||||
STR_TO_C(sv, service);
|
||||
STR_TO_C(buf, input);
|
||||
iRet=InstrHost(buf, in, ho, us, pc, sizeof(in), sizeof(ho), sizeof(us), sizeof(pc));
|
||||
if (iRet>0) {
|
||||
iRet=InstrHost(sv, buf, in, sizeof(in), ho, sizeof(ho), port);
|
||||
if (*port>0) {
|
||||
STR_TO_F(instr, in);
|
||||
STR_TO_F(host, ho);
|
||||
STR_TO_F(user, us);
|
||||
STR_TO_F(pcod, pc);
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user