Пример #1
0
int db2orbpkt(Dbptr db,int orb) {

	char			srcname[ORBSRCNAME_SIZE];
	static int		packetsz=0,nbytes;
	double			t;
	static char		*packet=0;
	static Packet	*pkt=0;
	int retcode = 0;
	
	if (pkt == 0) {
		pkt=newPkt();
	} else {
		clrPkt(pkt);
	}
	pkt->pkttype=suffix2pkttype("db");
	pkt->db=db;
	if (stuffPkt(pkt,srcname,&t,&packet,&nbytes,&packetsz) < 0) {
		complain(0,"stuffPkt failed for %s\\n",pkt->pkttype);
		retcode = -1;
	} else if (orbput(orb,srcname,t,packet,nbytes)) {
		complain (0, "orbput fails\n");
		retcode = -1;
	}
	return retcode;
}
Пример #2
0
void
send_log( char *log, char *srcname )
{
	static Packet *pkt = 0;
	static char *buf = 0;
	static int nbytes = 0;
	static int packetsz = 0;
	char	auto_srcname[STRSZ];
	double	time;

	if( ! strcmp( log, "" ) ) {
		
		return;
	}

	if( pkt == (Packet *) NULL ) {

		pkt = newPkt();
		pkt->pkttype = suffix2pkttype( "log" );
	}

	pkt->string = strdup( log );
	pkt->string_size = strlen(log) + 1;

	pkt->time = now();

	if( pkt->string_size > 512 ) {
		elog_complain( 0, "Warning: log message exceeds 512 bytes\n" );
	}

	if( buf == 0 ) {
		/* stuff_log appears not to allocate correctly? */
		allot( char *, buf, 1024 );
		packetsz = 1024;
	}
Пример #3
0
static int
dbrows2orb(Dbptr db, int orb, char *prefix)
{
	Packet         *pkt;
	char            srcname[ORBSRCNAME_SIZE];
	double          time;
	char           *packet;
	int             nbytes, packetsize = 0;
	Dbptr           tmpdb;
	long            t, nrecords, r, ntables;
	Arr            *records = NULL;
	Tbl            *tables = NULL, *static_tables;
	char           *thistablename;
	Stbl           *stbl;
	char           *s;

	dbuntangle(db, &records);
	tables = keysarr(records);
	ntables = maxtbl(tables);
	if (ntables > 0)
		pkt = newPkt();
	if (prefix)
		strncpy(pkt->parts.src_net, prefix, PKT_TYPESIZE);
	pkt->pkttype = suffix2pkttype("db");
	for (t = 0; t < ntables; t++) {
		thistablename = gettbl(tables, t);
		tmpdb = dblookup(db, 0, thistablename, 0, 0);
		stbl = (Stbl *) getarr(records, thistablename);
		nrecords = maxstbl(stbl);
		if (nrecords > 0) {
			for (r = 0; r < nrecords; r++) {
				tmpdb.record = (long) getstbl(stbl, r);
				pkt->db = tmpdb;
				if (stuffPkt(pkt, srcname, &time, &packet, &nbytes, &packetsize) < 0) {
					elog_complain(0, "stuffPkt fails for pf packet");
					return (-1);
				}
				if (orbput(orb, srcname, time, packet, nbytes) < 0) {
					elog_complain(0, "Couldn't send packet to orb\n");
					return (-1);
				}
			}
		}
	}
	freetbl(tables, 0);
	dbfree_untangle(records);
	freePkt(pkt);
	if (verbose) {
		elog_notify(0, "%s: %d patcket(s) sent with sourcename: %s\n", s = strtime(now()), nrecords, srcname);
		free(s);
	}
	return (0);




}
Пример #4
0
void InitPkt()
{
    Pkt = newPkt ();
    Pkt->pkttype = suffix2pkttype ("GENC");

    PktChan = newPktChannel ();
    Pkt->nchannels=1;
    settbl(Pkt->channels, 0, PktChan);
}