--- gvpe/src/util.h 2008/08/10 01:34:36 1.27 +++ gvpe/src/util.h 2013/07/17 16:40:58 1.33 @@ -2,7 +2,7 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003-2008 Marc Lehmann + 2003-2013 Marc Lehmann This file is part of GVPE. @@ -37,13 +37,12 @@ #include #include -#include - #include "gettext.h" #include "slog.h" #include "ev_cpp.h" #include "callback.h" +#include "global.h" typedef ev_tstamp tstamp; @@ -86,13 +85,13 @@ seq = seqno; } - // 0 == ok, 1 == silently ignore, 2 == error, reset + // 0 == ok, 1 == far history, 2 == duplicate in-window, 3 == far future int seqno_classify (u32 seqno) { if (seqno <= seq - WINDOWSIZE) return 1; else if (seqno > seq + WINDOWSIZE * 16) - return 2; + return 3; else { while (seqno > seq) @@ -111,7 +110,7 @@ u32 mask = 1 << (s & 31); if (*cell & mask) - return 1; + return 2; else { *cell |= mask; @@ -121,36 +120,32 @@ } }; -typedef callback run_script_cb; +typedef callback run_script_cb; // run a shell script (or actually an external program). pid_t run_script (const run_script_cb &cb, bool wait); +void hexdump (const char *header, void *data, int len); + #if ENABLE_HTTP_PROXY u8 *base64_encode (const u8 *data, unsigned int len); #endif /*****************************************************************************/ -typedef u8 rsaclear[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; -typedef u8 rsacrypt[RSA_KEYLEN]; // encrypted challenge +void rand_fill (void *data, int len); -static inline void -rsa_encrypt (RSA *key, const rsaclear &chg, rsacrypt &encr) +template +inline void rand_fill (T &t) { - if (RSA_public_encrypt (sizeof chg, - (unsigned char *)&chg, (unsigned char *)&encr, - key, RSA_PKCS1_OAEP_PADDING) < 0) - fatal ("RSA_public_encrypt error"); + rand_fill (&t, sizeof (T)); } -static inline bool -rsa_decrypt (RSA *key, const rsacrypt &encr, rsaclear &chg) -{ - return RSA_private_decrypt (sizeof encr, - (unsigned char *)&encr, (unsigned char *)&chg, - key, RSA_PKCS1_OAEP_PADDING) > 0; -} +/*****************************************************************************/ + +// run work_cb in another thread, call done_cb in main thread when finished +// only one work_cb will execute at any one time. +void async (callback work_cb, callback done_cb); #endif