Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ambrop72/badvpn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/flow
diff options
context:
space:
mode:
authorambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2011-03-20 12:37:44 +0300
committerambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2011-03-20 12:37:44 +0300
commitbd2f1db00c0bec779c651242a5193351d5445e0b (patch)
tree6675c150da9f08bb0759b938f9a058ee40cf5b7f /flow
parent81b1c0e14a8315b95f21fbeb853fe8528d11fc50 (diff)
DatagramPeerIO: allow setting and unsetting handlers
Diffstat (limited to 'flow')
-rw-r--r--flow/SPProtoDecoder.c13
-rw-r--r--flow/SPProtoDecoder.h13
-rw-r--r--flow/SPProtoEncoder.c22
-rw-r--r--flow/SPProtoEncoder.h13
4 files changed, 47 insertions, 14 deletions
diff --git a/flow/SPProtoDecoder.c b/flow/SPProtoDecoder.c
index 88fa882..78915f6 100644
--- a/flow/SPProtoDecoder.c
+++ b/flow/SPProtoDecoder.c
@@ -214,7 +214,7 @@ static void maybe_stop_work_and_ignore (SPProtoDecoder *o)
}
}
-int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct spproto_security_params sp_params, int num_otp_seeds, BPendingGroup *pg, BThreadWorkDispatcher *twd, SPProtoDecoder_otp_handler otp_handler, void *user)
+int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct spproto_security_params sp_params, int num_otp_seeds, BPendingGroup *pg, BThreadWorkDispatcher *twd)
{
spproto_assert_security_params(sp_params);
ASSERT(spproto_carrier_mtu_for_payload_mtu(sp_params, PacketPassInterface_GetMTU(output)) >= 0)
@@ -258,7 +258,7 @@ int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct
// init OTP checker
if (SPPROTO_HAVE_OTP(o->sp_params)) {
- if (!OTPChecker_Init(&o->otpchecker, o->sp_params.otp_num, o->sp_params.otp_mode, num_otp_seeds, o->twd, otp_handler, user)) {
+ if (!OTPChecker_Init(&o->otpchecker, o->sp_params.otp_num, o->sp_params.otp_mode, num_otp_seeds, o->twd)) {
goto fail1;
}
}
@@ -374,3 +374,12 @@ void SPProtoDecoder_RemoveOTPSeeds (SPProtoDecoder *o)
OTPChecker_RemoveSeeds(&o->otpchecker);
}
+
+void SPProtoDecoder_SetHandlers (SPProtoDecoder *o, SPProtoDecoder_otp_handler otp_handler, void *user)
+{
+ DebugObject_Access(&o->d_obj);
+
+ if (SPPROTO_HAVE_OTP(o->sp_params)) {
+ OTPChecker_SetHandlers(&o->otpchecker, otp_handler, user);
+ }
+}
diff --git a/flow/SPProtoDecoder.h b/flow/SPProtoDecoder.h
index 5cb6d8f..5bf747e 100644
--- a/flow/SPProtoDecoder.h
+++ b/flow/SPProtoDecoder.h
@@ -87,11 +87,9 @@ typedef struct {
* receiving packets. Must be >=2 if using OTPs.
* @param pg pending group
* @param twd thread work dispatcher
- * @param otp_handler handler called when OTP generation is finished
- * @param user argument to handler
* @return 1 on success, 0 on failure
*/
-int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct spproto_security_params sp_params, int num_otp_seeds, BPendingGroup *pg, BThreadWorkDispatcher *twd, SPProtoDecoder_otp_handler otp_handler, void *user) WARN_UNUSED;
+int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct spproto_security_params sp_params, int num_otp_seeds, BPendingGroup *pg, BThreadWorkDispatcher *twd) WARN_UNUSED;
/**
* Frees the object.
@@ -149,4 +147,13 @@ void SPProtoDecoder_AddOTPSeed (SPProtoDecoder *o, uint16_t seed_id, uint8_t *ke
*/
void SPProtoDecoder_RemoveOTPSeeds (SPProtoDecoder *o);
+/**
+ * Sets handlers.
+ *
+ * @param o the object
+ * @param otp_handler handler called when OTP generation is finished
+ * @param user argument to handler
+ */
+void SPProtoDecoder_SetHandlers (SPProtoDecoder *o, SPProtoDecoder_otp_handler otp_handler, void *user);
+
#endif
diff --git a/flow/SPProtoEncoder.c b/flow/SPProtoEncoder.c
index 6113d39..0316215 100644
--- a/flow/SPProtoEncoder.c
+++ b/flow/SPProtoEncoder.c
@@ -208,8 +208,10 @@ static void handler_job_hander (SPProtoEncoder *o)
ASSERT(SPPROTO_HAVE_OTP(o->sp_params))
DebugObject_Access(&o->d_obj);
- o->handler(o->user);
- return;
+ if (o->handler) {
+ o->handler(o->user);
+ return;
+ }
}
static void otpgenerator_handler (SPProtoEncoder *o)
@@ -233,24 +235,24 @@ static void maybe_stop_work (SPProtoEncoder *o)
}
}
-int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct spproto_security_params sp_params, int otp_warning_count, SPProtoEncoder_handler handler, void *user, BPendingGroup *pg, BThreadWorkDispatcher *twd)
+int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct spproto_security_params sp_params, int otp_warning_count, BPendingGroup *pg, BThreadWorkDispatcher *twd)
{
spproto_assert_security_params(sp_params);
ASSERT(spproto_carrier_mtu_for_payload_mtu(sp_params, PacketRecvInterface_GetMTU(input)) >= 0)
if (SPPROTO_HAVE_OTP(sp_params)) {
ASSERT(otp_warning_count > 0)
ASSERT(otp_warning_count <= sp_params.otp_num)
- ASSERT(handler)
}
// init arguments
o->input = input;
o->sp_params = sp_params;
o->otp_warning_count = otp_warning_count;
- o->handler = handler;
- o->user = user;
o->twd = twd;
+ // set no handlers
+ o->handler = NULL;
+
// calculate hash size
if (SPPROTO_HAVE_HASH(o->sp_params)) {
o->hash_size = BHash_size(o->sp_params.hash_mode);
@@ -417,3 +419,11 @@ void SPProtoEncoder_RemoveOTPSeed (SPProtoEncoder *o)
// reset OTP generator
OTPGenerator_Reset(&o->otpgen);
}
+
+void SPProtoEncoder_SetHandlers (SPProtoEncoder *o, SPProtoEncoder_handler handler, void *user)
+{
+ DebugObject_Access(&o->d_obj);
+
+ o->handler = handler;
+ o->user = user;
+}
diff --git a/flow/SPProtoEncoder.h b/flow/SPProtoEncoder.h
index 041123c..c23357a 100644
--- a/flow/SPProtoEncoder.h
+++ b/flow/SPProtoEncoder.h
@@ -94,13 +94,11 @@ typedef struct {
* @param sp_params SPProto security parameters
* @param otp_warning_count If using OTPs, after how many encoded packets to call the handler.
* In this case, must be >0 and <=sp_params.otp_num.
- * @param handler OTP warning handler
- * @param user value to pass to handler
* @param pg pending group
* @param twd thread work dispatcher
* @return 1 on success, 0 on failure
*/
-int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct spproto_security_params sp_params, int otp_warning_count, SPProtoEncoder_handler handler, void *user, BPendingGroup *pg, BThreadWorkDispatcher *twd) WARN_UNUSED;
+int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct spproto_security_params sp_params, int otp_warning_count, BPendingGroup *pg, BThreadWorkDispatcher *twd) WARN_UNUSED;
/**
* Frees the object.
@@ -155,4 +153,13 @@ void SPProtoEncoder_SetOTPSeed (SPProtoEncoder *o, uint16_t seed_id, uint8_t *ke
*/
void SPProtoEncoder_RemoveOTPSeed (SPProtoEncoder *o);
+/**
+ * Sets handlers.
+ *
+ * @param o the object
+ * @param handler OTP warning handler
+ * @param user value to pass to handler
+ */
+void SPProtoEncoder_SetHandlers (SPProtoEncoder *o, SPProtoEncoder_handler handler, void *user);
+
#endif