- improvements and bug fixes

This commit is contained in:
zolliker
2010-04-13 14:32:18 +00:00
parent 410166572b
commit 9e4eabeed1
6 changed files with 144 additions and 71 deletions

58
ease.c
View File

@ -934,11 +934,63 @@ void EaseMsgPar(void *object)
int EaseRestartWrapper(void *object, void *userarg, int argc, char *argv[])
{
EaseBase *eab = EaseBaseCast(object);
char *colon;
char *hostpos;
int port, i;
char host[64], hostport[80];
char *cCmd;
/* short string with length 0 or 1: connect to previous host/port */
if (argc > 0 && strlen(argv[0]) > 1) {
colon = strchr(argv[0], ':');
if (!colon || argc > 1) {
ParPrintf(object, eError, "ERROR: illegal syntax for: %s restart",
eab->p.name);
return 0;
}
port = atoi(colon + 1);
i = colon - argv[0];
if (i >= sizeof host) {
ParPrintf(object, eError, "ERROR: host name too long");
return 0;
}
strncpy(host, argv[0], i);
host[i] = '\0';
if (eab->p.creationCmd != NULL) {
hostpos = strstr(eab->p.creationCmd, eab->ser->pHost);
if (hostpos != NULL) {
/* replace the second part of creationCmd with new host/port */
snprintf(hostport, sizeof hostport, "%s:%d", host, port);
hostpos[0]='\0';
cCmd = calloc(1, strlen(eab->p.creationCmd) + strlen(hostport) + 1);
strcpy(cCmd, eab->p.creationCmd);
strcat(cCmd, hostport);
free(eab->p.creationCmd);
eab->p.creationCmd = cCmd;
}
}
if (eab->ser->pHost != NULL) {
free(eab->ser->pHost);
}
eab->ser->pHost = strdup(host);
eab->ser->iPort = port;
}
EaseStop(eab);
EaseRestart(eab);
return 0;
}
/*----------------------------------------------------------------------------*/
int EaseDisconnectWrapper(void *object, void *userarg, int argc, char *argv[])
{
EaseBase *eab = EaseBaseCast(object);
ParPrintf(object, eWarning, "%s disabled (enable with: %s restart)",
eab->p.name, eab->p.name);
EaseStop(eab);
return 0;
}
/*----------------------------------------------------------------------------*/
void EaseBasePar(void *object)
{
@ -950,6 +1002,10 @@ void EaseBasePar(void *object)
ParAccess(usUser);
ParCmd(EaseRestartWrapper, NULL);
ParName("disconnect");
ParAccess(usUser);
ParCmd(EaseDisconnectWrapper, NULL);
if (ParActionIs(PAR_KILL)) {
if (eab->ser) {
KillRS232(eab->ser);