updates.
[silc.git] / lib / silccore / silcprotocol.c
index 89d6244300a31237db25361c65a1cfd4c00f7446..3703c30e0073233bc0953a0136067cc46c23db95 100644 (file)
@@ -92,6 +92,7 @@ void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol,
 
   if (!protocol) {
     SILC_LOG_ERROR(("Requested protocol does not exists"));
+    *new_protocol = NULL;
     return;
   }
 
@@ -99,12 +100,10 @@ void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol,
   (*new_protocol)->protocol = protocol;
   (*new_protocol)->state = SILC_PROTOCOL_STATE_UNKNOWN;
   (*new_protocol)->context = context;
-  (*new_protocol)->execute = silc_protocol_execute;
-  (*new_protocol)->execute_final = silc_protocol_execute_final;
   (*new_protocol)->final_callback = callback;
 }
 
-/* Free's a protocol object. */
+/* Frees a protocol object. */
 
 void silc_protocol_free(SilcProtocol protocol)
 {
@@ -115,31 +114,29 @@ void silc_protocol_free(SilcProtocol protocol)
 /* Executes next state of the protocol. The state must be set before
    calling this function. */
 
-void silc_protocol_execute(void *qptr, int type,
-                          void *context, int fd,
+void silc_protocol_execute(SilcProtocol protocol, SilcSchedule schedule,
                           long secs, long usecs)
 {
-  SilcProtocol protocol = (SilcProtocol)context;
-
-  SILC_LOG_DEBUG(("Start"));
-
   if (secs + usecs) 
-    silc_task_register(qptr, fd, protocol->protocol->callback, context, 
-                      secs, usecs, 
-                      SILC_TASK_TIMEOUT,
-                      SILC_TASK_PRI_NORMAL);
+    silc_schedule_task_add(schedule, 0, 
+                          protocol->protocol->callback, (void *)protocol, 
+                          secs, usecs, 
+                          SILC_TASK_TIMEOUT,
+                          SILC_TASK_PRI_NORMAL);
   else
-    protocol->protocol->callback(qptr, 0, context, fd);
+    protocol->protocol->callback(schedule, 0, 0, (void *)protocol);
 }
 
 /* Executes the final callback of the protocol. */
 
-void silc_protocol_execute_final(void *qptr, int type,
-                                void *context, int fd)
+void silc_protocol_execute_final(SilcProtocol protocol, SilcSchedule schedule)
 {
-  SilcProtocol protocol = (SilcProtocol)context;
-  SILC_LOG_DEBUG(("Start, state=%d", protocol->state));
+  protocol->final_callback(schedule, 0, 0, (void *)protocol);
+}
 
-  protocol->final_callback(qptr, 0, context, fd);
+/* Cancels the execution of the next state of the protocol. */
+
+void silc_protocol_cancel(SilcProtocol protocol, SilcSchedule schedule)
+{
+  silc_schedule_task_del_by_context(schedule, protocol);
 }