- treat arguments of remserver command correctly (including empty strings)

This commit is contained in:
zolliker
2008-10-20 15:15:14 +00:00
parent f0573e3140
commit a04746f766

44
remob.c
View File

@ -196,7 +196,6 @@ static int RemSetInterest(RemChannel *rc) {
static void RemConnect(RemServer *remserver, int both) { static void RemConnect(RemServer *remserver, int both) {
/* open channel 0 or both channels, if not yet opened */ /* open channel 0 or both channels, if not yet opened */
int iRet; int iRet;
char buf[256];
mkChannel *chan; mkChannel *chan;
int i; int i;
RemChannel *rc; RemChannel *rc;
@ -279,9 +278,9 @@ static int RemTransact(RemServer *remserver, int nChan, SConnection *pCon,
"!blabla" skip lines starting with blabla "!blabla" skip lines starting with blabla
">" write untreated lines to pCon ">" write untreated lines to pCon
*/ */
char buf[256]; char *buffer;
int bufferLen;
int iRet; int iRet;
int i, typ;
char *arg, *val, *endp; char *arg, *val, *endp;
float *f; float *f;
va_list ap; va_list ap;
@ -296,9 +295,16 @@ static int RemTransact(RemServer *remserver, int nChan, SConnection *pCon,
} }
} }
tryagain: tryagain:
snprintf(buf, sizeof buf, "transact %s\n", cmd); bufferLen = strlen(cmd)+16;
buffer=malloc(bufferLen);
if (buffer == NULL) {
SCPrintf(pCon, eError, "ERROR: can not get another %d bytes", bufferLen);
return 0;
}
snprintf(buffer, bufferLen, "transact %s\n", cmd);
RemConnect(remserver, nChan); RemConnect(remserver, nChan);
iRet = RemWrite(rc, buf); iRet = RemWrite(rc, buffer);
free(buffer);
if (iRet < 0) goto close; if (iRet < 0) goto close;
iRet = RemRead(rc, 2000); iRet = RemRead(rc, 2000);
@ -342,20 +348,17 @@ tryagain:
close: close:
if (iRet == 0) { if (iRet == 0) {
if (try == 1) { if (try == 1) {
snprintf(buf, sizeof(buf), "ERROR: timeout on %s", remserver->name); SCPrintf(pCon, eError, "ERROR: timeout on %s", remserver->name);
SCWrite(pCon,buf,eError);
rc->timeout = 1; rc->timeout = 1;
return iRet; return iRet;
} else { } else {
snprintf(buf, sizeof(buf), "WARNING: timeout on %s", remserver->name); SCPrintf(pCon, eError, "WARNING: timeout on %s", remserver->name);
SCWrite(pCon,buf,eError);
} }
} }
RemDisconnect(remserver); RemDisconnect(remserver);
try--; try--;
if (try>0) goto tryagain; if (try>0) goto tryagain;
snprintf(buf, sizeof(buf), "ERROR: no connection to %s", remserver->name); SCPrintf(pCon, eError, "ERROR: no connection to %s", remserver->name);
SCWrite(pCon,buf,eError);
return iRet; return iRet;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
@ -637,7 +640,6 @@ static void RemobKill(void *self) {
int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData, int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]) { int argc, char *argv[]) {
RemServer *remserver = pData; RemServer *remserver = pData;
char buf[512];
TokenList *pList = NULL; TokenList *pList = NULL;
TokenList *pCurrent; TokenList *pCurrent;
TokenList *pName; TokenList *pName;
@ -652,6 +654,7 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData,
Remob *p, *next; Remob *p, *next;
int rights, nChan; int rights, nChan;
RemChannel *rc; RemChannel *rc;
char *args;
assert(pCon); assert(pCon);
assert(pSics); assert(pSics);
@ -681,13 +684,10 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData,
argv[0], remserver->host, remserver->port, thishostname, serverport); argv[0], remserver->host, remserver->port, thishostname, serverport);
} else if (argc>2 && strcasecmp(argv[1],"nowait") == 0) { } else if (argc>2 && strcasecmp(argv[1],"nowait") == 0) {
RemConnect(remserver, nChan); RemConnect(remserver, nChan);
for (i=2; i<argc; i++) { args = Arg2Tcl(argc-2, argv+2, NULL, 0);
if (i>2) { RemWrite(rc, args);
RemWrite(rc, " ");
}
RemWrite(rc, argv[i]);
}
RemWrite(rc, "\n"); RemWrite(rc, "\n");
free(args);
} else if (argc==2 && strcasecmp(argv[1],"markForDel") == 0) { } else if (argc==2 && strcasecmp(argv[1],"markForDel") == 0) {
p = remserver->objList; p = remserver->objList;
while (p) { while (p) {
@ -708,11 +708,9 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData,
p = next; p = next;
} }
} else { } else {
pos=0; args = Arg2Tcl(argc-1, argv+1, NULL, 0);
for (i=1; i<argc; i++) { iRet = RemTransact(remserver, nChan, pCon, args, ">", NULL);
pos+=snprintf(buf+pos, sizeof(buf)-pos, "%s ", argv[i]); free(args);
}
iRet = RemTransact(remserver, nChan, pCon, buf, ">", NULL);
return iRet; return iRet;
} }
return 1; return 1;