Example #1
0
extern	size_t
RequestReadBLOB(
	NETFILE	*fp,
	MonObjectType	obj,
	unsigned char	**ret,
	size_t	*size)
{
	unsigned char 	*buff;
	size_t	red;
	
ENTER_FUNC;
	red = 0;
	*ret = NULL;
	RequestBLOB(fp,BLOB_READ);			ON_IO_ERROR(fp,badio);
	SendObject(fp,obj);					ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		*size = RecvLength(fp);				ON_IO_ERROR(fp,badio);
		if		(  *size  >  0  ) {
			buff = xmalloc(*size);
			red = Recv(fp,buff,*size);
			*ret = buff;
		}
	}
  badio:
LEAVE_FUNC;
	return	(red);
}
Example #2
0
static	Bool
SendTerminal(
	NETFILE		*fp,
	SessionData	*data)
{
	unsigned char	c;
	char			wname[SIZE_LONGNAME+1];
	LargeByteString	*scrdata;
	int 			i;

ENTER_FUNC;
	SendPacketClass(fp,WFC_HEADER);		ON_IO_ERROR(fp,badio);
	dbgmsg("send DATA");
	SendString(fp,data->hdr->user);		ON_IO_ERROR(fp,badio);
	SendString(fp,data->hdr->window);	ON_IO_ERROR(fp,badio);
	SendString(fp,data->hdr->widget);	ON_IO_ERROR(fp,badio);
	SendChar  (fp,data->hdr->puttype);	ON_IO_ERROR(fp,badio);
	dbgprintf("window    = [%s]",data->hdr->window);
	SendInt(fp,data->w.sp);				ON_IO_ERROR(fp,badio);
	for (i=0;i<data->w.sp;i++) {
		SendChar(fp,data->w.s[i].puttype);ON_IO_ERROR(fp,badio);
		SendString(fp,data->w.s[i].window);ON_IO_ERROR(fp,badio);
	}
	while (1) {
		c = RecvPacketClass(fp);		ON_IO_ERROR(fp,badio);
		switch (c) {
		case WFC_DATA:
			dbgmsg(">DATA");
			RecvnString(fp,SIZE_LONGNAME,wname);ON_IO_ERROR(fp,badio);
			if ((scrdata = GetScreenData(data,wname)) != NULL) {
				dbgmsg("send OK");
				SendPacketClass(fp,WFC_OK);	ON_IO_ERROR(fp,badio);
				SendLBS(fp,scrdata);		ON_IO_ERROR(fp,badio);
			} else {
				dbgmsg("send NODATA");
				SendPacketClass(fp,WFC_NODATA);	ON_IO_ERROR(fp,badio);
			}
			dbgmsg("<DATA");
			break;
		case WFC_DONE:
			dbgmsg("DONE");
			return TRUE;
		case WFC_END:
			dbgmsg("END");
			return FALSE;
		default:
			Warning("[%s] session failure packet [%X]",data->hdr->uuid,c);
			dbgprintf("c = [%X]\n",c);
			return FALSE;
		}
	}
	Warning("does not reach");
LEAVE_FUNC;
	return FALSE;
badio:
	Warning("[%s] session recv failure",data->hdr->uuid);
LEAVE_FUNC;
	return FALSE;
}
Example #3
0
static Bool Auth(NETFILE *fp) {
  Bool ret;

  SendStringDelim(fp, ThisEnv->name);
  SendStringDelim(fp, "\n");
  dbgprintf("name = [%s]\n", ThisEnv->name);
  switch (RecvPacketClass(fp)) {
  case WFCCONTROL_OK:
    ret = TRUE;
    break;
  default:
    ret = FALSE;
    break;
  }
  return (ret);
}
Example #4
0
extern	Bool
RequestAbortBLOB(
	NETFILE	*fp)
{
	Bool	rc;

ENTER_FUNC;
	rc = FALSE;
	RequestBLOB(fp,BLOB_ABORT);			ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		rc = TRUE;
	}
  badio:
LEAVE_FUNC;
	return	(rc);
}
Example #5
0
PacketClass SYSDB_GetDataAll(NETFILE *fp, int *size, ValueStruct *vals) {
  PacketClass rc;
  LargeByteString *buf;
  rc = SESSION_CONTROL_NG;
  buf = NewLBS();
  SendPacketClass(fp, SYSDATA_SYSDB);
  ON_IO_ERROR(fp, badio);
  SendPacketClass(fp, SYSDB_GET_DATA_ALL);
  ON_IO_ERROR(fp, badio);
  rc = RecvPacketClass(fp);
  *size = RecvInt(fp);
  RecvLBS(fp, buf);
  NativeUnPackValue(NULL, LBS_Body(buf), vals);
badio:
  FreeLBS(buf);
  return rc;
}
Example #6
0
static Bool
SendCommit_Redirect(
	DBG_Struct	*dbg)
{
	Bool rc = TRUE;

	if		(  dbg->fpLog  ==  NULL  ) {
		return rc;
	}
	SendPacketClass(dbg->fpLog,RED_COMMIT);	ON_IO_ERROR(dbg->fpLog,badio);
	SendInt(dbg->fpLog, dbg->ticket_id);		ON_IO_ERROR(dbg->fpLog,badio);
	if		(  RecvPacketClass(dbg->fpLog)  !=  RED_OK  ) {
badio:
		rc = FALSE;
		Warning("Redirect Commit error (%d)", dbg->ticket_id);
	}
	return rc;
}
Example #7
0
extern	MonObjectType
RequestNewBLOB(
	NETFILE	*fp,
	int		mode)
{
	MonObjectType	obj;

ENTER_FUNC;
	obj = GL_OBJ_NULL;
	RequestBLOB(fp,BLOB_CREATE);		ON_IO_ERROR(fp,badio);
	SendInt(fp,mode);					ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		obj = RecvObject(fp);			ON_IO_ERROR(fp,badio);
	}
  badio:
LEAVE_FUNC;
	return	(obj);
}
Example #8
0
extern	Bool
RequestDestroyBLOB(
	NETFILE	*fp,
	MonObjectType	obj)
{
	Bool	rc;

ENTER_FUNC;
	rc = FALSE;
	RequestBLOB(fp,BLOB_DESTROY);		ON_IO_ERROR(fp,badio);
	SendObject(fp,obj);					ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		rc = TRUE;
	}
  badio:
LEAVE_FUNC;
	return	(rc);
}
Example #9
0
static PacketClass SYSDB_RequestCommon(NETFILE *fp, PacketClass pc,
                                       ValueStruct *val) {
  PacketClass rc;
  LargeByteString *buf;
  rc = SESSION_CONTROL_NG;
  buf = NewLBS();
  LBS_ReserveSize(buf, NativeSizeValue(NULL, val), FALSE);
  NativePackValue(NULL, LBS_Body(buf), val);
  SendPacketClass(fp, SYSDATA_SYSDB);
  ON_IO_ERROR(fp, badio);
  SendPacketClass(fp, pc);
  ON_IO_ERROR(fp, badio);
  SendLBS(fp, buf);
  ON_IO_ERROR(fp, badio);
  rc = RecvPacketClass(fp);
  RecvLBS(fp, buf);
  NativeUnPackValue(NULL, LBS_Body(buf), val);
badio:
  FreeLBS(buf);
  return rc;
}
Example #10
0
extern	MonObjectType
RequestImportBLOB(
	NETFILE	*fp,
	char			*fname)
{
	MonObjectType	obj;
	char	buff[SIZE_BUFF];
	FILE	*fpf;
	struct	stat	sb;
	size_t	size
		,	left;

ENTER_FUNC;
	obj = GL_OBJ_NULL;
	RequestBLOB(fp,BLOB_IMPORT);		ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		obj = RecvObject(fp);				ON_IO_ERROR(fp,badio);
		if		(  ( fpf = fopen(fname,"r") )  !=  NULL  ) {
			fstat(fileno(fpf),&sb);
			left = sb.st_size;
			SendLength(fp,left);
			Flush(fp);
			while	(  left  >  0  ) {
				size = (  left  >  SIZE_BUFF  ) ? SIZE_BUFF : left;
				fread(buff,size,1,fpf);
				Send(fp,buff,size);			ON_IO_ERROR(fp,badio);
				Flush(fp);
				left -= size;
			}
			fclose(fpf);
		} else {
			dbgprintf("could not open for read: %s", fname);
			SendLength(fp,0);
			Flush(fp);
		}
	}
  badio:
LEAVE_FUNC;
	return	(obj);
}
Example #11
0
extern	Bool
CheckDB_Redirect(
	DBG_Struct	*dbg)
{
	Bool	rc = TRUE;
ENTER_FUNC;
	if (  dbg->redirect == NULL )
		return rc;
	if		(  dbg->redirectData  !=  NULL  ) {
		if		(  dbg->fpLog  !=  NULL  ) {
			SendPacketClass(dbg->fpLog,RED_PING); ON_IO_ERROR(dbg->fpLog,badio);
			if		(  RecvPacketClass(dbg->fpLog)  !=  RED_PONG  ) {
			badio:
				Warning("dbredirect server down?");
				ChangeDBStatus_Redirect(dbg, DB_STATUS_REDFAILURE);
				CloseDB_RedirectPort(dbg);
				rc = FALSE;
			}
		}
	}
LEAVE_FUNC;
	return	(rc);
}
Example #12
0
static	void
TermThread(
	TermNode	*term)
{
	PacketClass klass;

ENTER_FUNC;
	klass = RecvPacketClass(term->fp);
	switch (klass) {
	case WFC_TERM_INIT:
		TermInit(term);
		break;
	case WFC_TERM:
		TermSession(term);
		break;
	case WFC_API:
		APISession(term);
		break;
	}
	FreeQueue(term->que);
	xfree(term);
LEAVE_FUNC;
}
Example #13
0
extern	size_t
RequestWriteBLOB(
	NETFILE	*fp,
	MonObjectType	obj,
	unsigned char	*buff,
	size_t	size)
{
	size_t	wrote;
	
ENTER_FUNC;
	wrote = 0;
	RequestBLOB(fp,BLOB_WRITE);			ON_IO_ERROR(fp,badio);
	SendObject(fp,obj);					ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		SendLength(fp,size);				ON_IO_ERROR(fp,badio);
		if		(  size  >  0  ) {
			Send(fp,buff,size);					ON_IO_ERROR(fp,badio);
			wrote = RecvLength(fp);				ON_IO_ERROR(fp,badio);
		}
	}
  badio:
LEAVE_FUNC;
	return	(wrote);
}
Example #14
0
extern	Bool
RequestExportBLOB(
	NETFILE	*fp,
	MonObjectType	obj,
	char			*fname)
{
	Bool	rc;
	char	buff[SIZE_BUFF];
	FILE	*fpf;
	size_t	size
		,	left;

ENTER_FUNC;
	rc = FALSE;
	RequestBLOB(fp,BLOB_EXPORT);		ON_IO_ERROR(fp,badio);
	SendObject(fp,obj);					ON_IO_ERROR(fp,badio);
	if		(  RecvPacketClass(fp)  ==  BLOB_OK  ) {
		if		(  ( fpf = Fopen(fname,"w") )  !=  NULL  ) {
			fchmod(fileno(fpf),0600);
			left = RecvLength(fp);
			while	(  left  >  0  ) {
				size = (  left  >  SIZE_BUFF  ) ? SIZE_BUFF : left;
				Recv(fp,buff,size);			ON_IO_ERROR(fp,badio);
				fwrite(buff,size,1,fpf);
				left -= size;
			}
			fclose(fpf);
			rc = TRUE;
		} else {
			Warning("could not open for write: %s", fname);
		}
	}
  badio:
LEAVE_FUNC;
	return	(rc);
}
Example #15
0
static	SessionData	*
ReadTerminal(
	NETFILE		*fp,
	SessionData	*data)
{
	LD_Node			*ld;
	Bool			fExit;
	int				c;
	LargeByteString	*scrdata;
	int				i;
ENTER_FUNC;
	fExit = FALSE;
	while (!fExit) {
		switch (c = RecvPacketClass(fp)) {
		case WFC_DATA:
			dbgmsg("recv DATA");
			if (data != NULL) {
				RecvnString(fp,SIZE_NAME,data->hdr->window);
					ON_IO_ERROR(fp,badio);
				RecvnString(fp,SIZE_NAME,data->hdr->widget);
					ON_IO_ERROR(fp,badio);
				RecvnString(fp,SIZE_NAME,data->hdr->event);
					ON_IO_ERROR(fp,badio);

				data->w.sp = RecvInt(fp);					
					ON_IO_ERROR(fp,badio);
				for (i=0;i<data->w.sp ;i++) {
					data->w.s[i].puttype = RecvChar(fp);
						ON_IO_ERROR(fp,badio);
					RecvnString(fp,SIZE_NAME,data->w.s[i].window);
						ON_IO_ERROR(fp,badio);
				}

				dbgprintf("window = [%s]",data->hdr->window);
				dbgprintf("widget = [%s]",data->hdr->widget);
				dbgprintf("event  = [%s]",data->hdr->event);
				ld = g_hash_table_lookup(ComponentHash,data->hdr->window);
				if (ld != NULL) {
					dbgprintf("ld = [%s]",ld->info->name);
					dbgprintf("window = [%s]",data->hdr->window);
					scrdata = GetScreenData(data,data->hdr->window);
					if (scrdata != NULL) {
						SendPacketClass(fp,WFC_OK);	ON_IO_ERROR(fp,badio);
						dbgmsg("send OK");
						if (RecvPacketClass(fp) == WFC_DATA) {
							RecvLBS(fp,scrdata);ON_IO_ERROR(fp,badio);
						}
						data->hdr->puttype = SCREEN_NULL;
					} else {
						Error("invalid window [%s]",data->hdr->window);
					}
					if (data->ld != ld) {
						ChangeLD(data,ld);
					}
				} else {
					Error("component [%s] not found.",data->hdr->window);
					fExit = TRUE;
				}
			} else {
				fExit = TRUE;
			}
			break;
		case WFC_OK:
			dbgmsg("OK");
			fExit = TRUE;
			break;
		case WFC_END:
			dbgmsg("END");
			if ((ld = g_hash_table_lookup(APS_Hash, "session"))  !=  NULL) {
				strncpy(data->hdr->window,"session_end",
					sizeof(data->hdr->window));
				data->hdr->widget[0] = 0;
				sprintf(data->hdr->event,"SESSIONEND");
				data->hdr->puttype = SCREEN_NULL;
				ChangeLD(data,ld);
				data->status = SESSION_STATUS_END;
			} else {
				data->status = SESSION_STATUS_ABORT;
			}
			fExit = TRUE;
			break;
		default:
			Warning("Invalid PacketClass in ReadTerminal [%X]", c);
			SendPacketClass(fp,WFC_NOT);ON_IO_ERROR(fp,badio);
			fExit = TRUE;
			data->status = SESSION_STATUS_ABORT;
			break;
		}
	}
badio:
LEAVE_FUNC;
	return(data);
}