static void id_clients( Pf *pf ) { Pf *pfclients; Pf *pfclient; char client_summary[STRSZ]; char *serveraddress; char *serverport; Tbl *client_keys; int ikey; char *client_key; char clientid_key[STRSZ]; char *clientaddress; char *what; char clientid[33]; pfeval( pf, "server{address}", &serveraddress ); pfeval( pf, "server{port}", &serverport ); pfget( pf, "clients", (void **) &pfclients ); client_keys = pfkeys( pfclients ); for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) { client_key = gettbl( client_keys, ikey ); pfget( pfclients, client_key, (void **) &pfclient ); clientaddress = pfget_string( pfclient, "address" ); what = pfget_string( pfclient, "what" ); sprintf( client_summary, "%s %s %s %s", serveraddress, serverport, clientaddress, what ); sprintf( clientid_key, "clients{%s}{clientid}", client_key ); mdhex( clientid, client_summary, strlen( client_summary ) ); pfset( pf, clientid_key, clientid ); } freetbl( client_keys, 0 ); return; }
static Pf * orbdatabases2pf( Pf *pfanalyze ) { Pf *pf; Pf *pfdatabases; Pf *pfdatabase; Pf *pfclients; Pf *pfclient; double atime; Tbl *client_keys; int ikey; char *client_key; char *what; char *serverhost; char *clientid; char *clientaddress; char *serveraddress; char *serverport; char dbprogram[STRSZ]; char dbpath[STRSZ]; char dir[STRSZ]; char dfile[STRSZ]; char formal_name[STRSZ]; int formal_count = 0; char *delim = ":"; char *hostdir; char *serverhostcopy; char *abspath; pf = pfnew( PFFILE ); pfdatabases = pfnew( PFTBL ); atime = pfget_time( pfanalyze, "client_when" ); pfput_time( pf, "databases_when", atime ); pfeval( pfanalyze, "server{address}", &serveraddress ); pfeval( pfanalyze, "server{port}", &serverport ); pfeval( pfanalyze, "server{host}", &serverhost ); serverhostcopy = strdup( serverhost ); strtok_r( serverhostcopy, delim, &hostdir ); pfget( pfanalyze, "clients", (void **) &pfclients ); client_keys = pfkeys( pfclients ); for( ikey = 0; ikey < maxtbl( client_keys ); ikey++ ) { client_key = gettbl( client_keys, ikey ); pfget( pfclients, client_key, (void **) &pfclient ); what = pfget_string( pfclient, "what" ); clientaddress = pfget_string( pfclient, "address" ); clientid = pfget_string( pfclient, "clientid" ); if( is_dbprogram( what, dbprogram, dbpath ) ) { pfdatabase = pfnew( PFARR ); pfput_string( pfdatabase, "clientid", clientid ); pfput_string( pfdatabase, "serveraddress", serveraddress ); pfput_string( pfdatabase, "serverport", serverport ); pfput_string( pfdatabase, "dbprogram", dbprogram ); if( is_localhost( clientaddress ) ) { pfput_string( pfdatabase, "dbmachine", serveraddress ); abspath = concatpaths( hostdir, dbpath, 0 ); parsepath( abspath, dir, dfile, 0 ); free( abspath ); } else { pfput_string( pfdatabase, "dbmachine", clientaddress ); abspath = concatpaths( "", dbpath, 0 ); parsepath( abspath, dir, dfile, 0 ); free( abspath ); } pfput_string( pfdatabase, "dir", dir ); pfput_string( pfdatabase, "dfile", dfile ); sprintf( formal_name, "client%03d", ++formal_count ); pfput( pfdatabases, formal_name, pfdatabase, PFPF ); } } free( serverhostcopy ); pfput( pf, "databases", pfdatabases, PFPF ); return pf; }