From: Pekka Riikonen Date: Sun, 3 Jun 2001 13:33:12 +0000 (+0000) Subject: updates. X-Git-Tag: robodoc-323~243 X-Git-Url: http://git.silc.fi/gitweb/?a=commitdiff_plain;h=aeab65da14382a8c910389dbab6e68051fadc92b;p=silc.git updates. --- diff --git a/CHANGES b/CHANGES index 4b785a4f..b5422db7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,16 @@ +Sun Jun 3 14:21:32 EEST 2001 Pekka Riikonen + + * Changed the protocol API a bit more consistent in the + lib/silccore/silcprotocol.[ch]. + + * Changed the following headers to ROBODoc format: + + lib/silccore/silcpayload.h + lib/silccore/silcprotocol.h + lib/silccore/silcsockconn.h + + All core library headers are now formatted. + Sat Jun 2 10:45:09 EEST 2001 Pekka Riikonen * Fixed a bug in Irssi SILC client; do not show that you are diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 9f175376..fe420c61 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -2065,5 +2065,5 @@ void silc_server_rekey(SilcServer server, if (proto_ctx->pfs == FALSE) /* Run the protocol */ - protocol->execute(server->timeout_queue, 0, protocol, sock->sock, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); } diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index dbda9d84..df0ba412 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -220,7 +220,7 @@ static void silc_server_protocol_ke_finish(SilcSKE ske, void *context) ske->status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, 0, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } @@ -299,14 +299,14 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } /* Advance protocol state and call the next state if we are responder */ protocol->state++; if (ctx->responder == TRUE) - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 100000); } break; case 2: @@ -341,14 +341,14 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } /* Advance protocol state and call next state if we are initiator */ protocol->state++; if (ctx->responder == FALSE) - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 100000); } break; case 3: @@ -391,14 +391,14 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } /* Advance protocol state and call the next state if we are responder */ protocol->state++; if (ctx->responder == TRUE) - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 100000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 100000); } break; case 4: @@ -439,7 +439,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } } @@ -460,7 +460,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) keymat); if (status != SILC_SKE_STATUS_OK) { protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); silc_ske_free_key_material(keymat); return; } @@ -479,7 +479,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) /* Call the final callback */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); } @@ -503,7 +503,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; @@ -521,7 +521,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; @@ -679,14 +679,14 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) if (ret == -1) { SILC_LOG_DEBUG(("Bad payload in authentication packet")); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } if (payload_len != ctx->packet->buffer->len) { SILC_LOG_DEBUG(("Bad payload in authentication packet")); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } @@ -696,7 +696,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) conn_type > SILC_SOCKET_TYPE_ROUTER) { SILC_LOG_ERROR(("Bad connection type %d", conn_type)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } @@ -710,8 +710,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) if (ret == -1) { SILC_LOG_DEBUG(("Bad payload in authentication packet")); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } } @@ -749,8 +748,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; break; @@ -770,8 +769,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; } } else { @@ -780,8 +779,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_ERROR(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; } } @@ -811,8 +810,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; break; @@ -832,8 +831,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; } } else { @@ -841,8 +840,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_ERROR(("Remote connection not configured")); SILC_LOG_ERROR(("Authentication failed")); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); silc_free(auth_data); return; } @@ -873,8 +872,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; break; @@ -894,8 +893,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; } } else { @@ -904,8 +903,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_ERROR(("Authentication failed")); silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, + 0, 300000); return; } } @@ -918,7 +917,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Advance protocol state. */ protocol->state = SILC_PROTOCOL_STATE_END; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); } else { /* @@ -1009,7 +1008,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Protocol has ended, call the final callback */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); } @@ -1035,7 +1034,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); } @@ -1054,7 +1053,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; @@ -1241,8 +1240,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_1) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, - 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); } ctx->ske = silc_ske_alloc(); @@ -1258,14 +1256,13 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } /* Advance the protocol state */ protocol->state++; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); } else { /* * Do normal and simple re-key. @@ -1314,8 +1311,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } @@ -1364,8 +1360,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } } @@ -1378,7 +1373,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_2) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); } status = silc_ske_initiator_finish(ctx->ske, ctx->packet->buffer, @@ -1388,8 +1383,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, server->timeout_queue, 0, 300000); return; } } @@ -1417,7 +1411,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) if (ctx->packet->type != SILC_PACKET_REKEY_DONE) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); } /* We received the REKEY_DONE packet and all packets after this is @@ -1426,7 +1420,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) /* Protocol has ended, call the final callback */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; @@ -1445,7 +1439,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; @@ -1457,7 +1451,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(server->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, server->timeout_queue); else silc_protocol_free(protocol); break; diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 56d107c0..7737b12f 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -603,7 +603,7 @@ SILC_TASK_CALLBACK(silc_server_connect_router) SILC_REGISTER_CONNECTION_FOR_IO(sock); /* Run the protocol */ - protocol->execute(server->timeout_queue, 0, protocol, sock, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); } /* This function connects to our primary router or if we are a router this @@ -813,8 +813,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_second) SILC_TASK_PRI_LOW); /* Run the protocol */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); } /* Finalizes the connection to router. Registers a server task to the @@ -1652,10 +1651,8 @@ void silc_server_packet_parse_type(SilcServer server, SILC_LOG_DEBUG(("Success packet")); if (packet->flags & SILC_PACKET_FLAG_LIST) break; - if (sock->protocol) { - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); - } + if (sock->protocol) + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); break; case SILC_PACKET_FAILURE: @@ -1793,8 +1790,7 @@ void silc_server_packet_parse_type(SilcServer server, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 100000); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 100000); } else { SILC_LOG_ERROR(("Received Key Exchange packet but no key exchange " "protocol active, packet dropped.")); @@ -1822,8 +1818,7 @@ void silc_server_packet_parse_type(SilcServer server, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); } else { SilcServerKEInternalContext *proto_ctx = (SilcServerKEInternalContext *)sock->protocol->context; @@ -1839,9 +1834,8 @@ void silc_server_packet_parse_type(SilcServer server, break; /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, - 0, 100000); + silc_protocol_execute(sock->protocol, server->timeout_queue, + 0, 100000); } } else { SILC_LOG_ERROR(("Received Key Exchange 1 packet but no key exchange " @@ -1868,8 +1862,7 @@ void silc_server_packet_parse_type(SilcServer server, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); } else { SilcServerKEInternalContext *proto_ctx = (SilcServerKEInternalContext *)sock->protocol->context; @@ -1885,9 +1878,8 @@ void silc_server_packet_parse_type(SilcServer server, break; /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, - 0, 100000); + silc_protocol_execute(sock->protocol, server->timeout_queue, + 0, 100000); } } else { SILC_LOG_ERROR(("Received Key Exchange 2 packet but no key exchange " @@ -1927,8 +1919,7 @@ void silc_server_packet_parse_type(SilcServer server, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); } else { SILC_LOG_ERROR(("Received Connection Auth packet but no authentication " "protocol active, packet dropped.")); @@ -2035,8 +2026,7 @@ void silc_server_packet_parse_type(SilcServer server, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(server->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, server->timeout_queue, 0, 0); } else { SILC_LOG_ERROR(("Received Re-key done packet but no re-key " "protocol active, packet dropped.")); @@ -3423,8 +3413,7 @@ SILC_TASK_CALLBACK(silc_server_failure_callback) if (f->sock->protocol) { f->sock->protocol->state = SILC_PROTOCOL_STATE_FAILURE; - f->sock->protocol->execute(f->server->timeout_queue, 0, - f->sock->protocol, f->sock->sock, 0, 0); + silc_protocol_execute(f->sock->protocol, f->server->timeout_queue, 0, 0); } silc_free(f); @@ -3754,8 +3743,7 @@ SILC_TASK_CALLBACK(silc_server_rekey_callback) sock->protocol = protocol; /* Run the protocol */ - protocol->execute(server->timeout_queue, 0, protocol, - sock->sock, 0, 0); + silc_protocol_execute(protocol, server->timeout_queue, 0, 0); /* Re-register re-key timeout */ silc_task_register(server->timeout_queue, sock->sock, @@ -3780,7 +3768,7 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_rekey_final) if (protocol->state == SILC_PROTOCOL_STATE_ERROR || protocol->state == SILC_PROTOCOL_STATE_FAILURE) { /* Error occured during protocol */ - silc_protocol_cancel(server->timeout_queue, protocol); + silc_protocol_cancel(protocol, server->timeout_queue); silc_protocol_free(protocol); sock->protocol = NULL; if (ctx->packet) diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index ac029e2b..ed3e3855 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -348,7 +348,7 @@ int silc_client_start_key_exchange(SilcClient client, SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(fd); /* Execute the protocol */ - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return TRUE; } @@ -483,7 +483,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_second) silc_client_connect_to_server_final); /* Execute the protocol */ - sock->protocol->execute(client->timeout_queue, 0, sock->protocol, fd, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } /* Finalizes the connection to the remote SILC server. This is called @@ -798,10 +798,8 @@ void silc_client_packet_parse_type(SilcClient client, * one protocol for connection executing at once hence this * success message is for whatever protocol is executing currently. */ - if (sock->protocol) { - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); - } + if (sock->protocol) + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); break; case SILC_PACKET_FAILURE: /* @@ -876,8 +874,7 @@ void silc_client_packet_parse_type(SilcClient client, break; /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } else { SILC_LOG_ERROR(("Received Key Exchange packet but no key exchange " "protocol active, packet dropped.")); @@ -899,8 +896,7 @@ void silc_client_packet_parse_type(SilcClient client, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } else { SilcClientKEInternalContext *proto_ctx = (SilcClientKEInternalContext *)sock->protocol->context; @@ -916,8 +912,7 @@ void silc_client_packet_parse_type(SilcClient client, break; /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } } else { SILC_LOG_ERROR(("Received Key Exchange 1 packet but no key exchange " @@ -939,8 +934,7 @@ void silc_client_packet_parse_type(SilcClient client, proto_ctx->packet = silc_packet_context_dup(packet); /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } else { SilcClientKEInternalContext *proto_ctx = (SilcClientKEInternalContext *)sock->protocol->context; @@ -956,8 +950,7 @@ void silc_client_packet_parse_type(SilcClient client, break; /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); } } else { SILC_LOG_ERROR(("Received Key Exchange 2 packet but no key exchange " @@ -1022,12 +1015,11 @@ void silc_client_packet_parse_type(SilcClient client, /* Let the protocol handle the packet */ if (proto_ctx->responder == FALSE) - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 0); + silc_protocol_execute(sock->protocol, client->timeout_queue, 0, 0); else /* Let the protocol handle the packet */ - sock->protocol->execute(client->timeout_queue, 0, - sock->protocol, sock->sock, 0, 100000); + silc_protocol_execute(sock->protocol, client->timeout_queue, + 0, 100000); } else { SILC_LOG_ERROR(("Received Re-key done packet but no re-key " "protocol active, packet dropped.")); @@ -1556,8 +1548,7 @@ SILC_TASK_CALLBACK(silc_client_rekey_callback) sock->protocol = protocol; /* Run the protocol */ - protocol->execute(client->timeout_queue, 0, protocol, - sock->sock, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); /* Re-register re-key timeout */ silc_task_register(client->timeout_queue, sock->sock, @@ -1582,7 +1573,7 @@ SILC_TASK_CALLBACK(silc_client_rekey_final) if (protocol->state == SILC_PROTOCOL_STATE_ERROR || protocol->state == SILC_PROTOCOL_STATE_FAILURE) { /* Error occured during protocol */ - silc_protocol_cancel(client->timeout_queue, protocol); + silc_protocol_cancel(protocol, client->timeout_queue); silc_protocol_free(protocol); sock->protocol = NULL; if (ctx->packet) diff --git a/lib/silcclient/client_keyagr.c b/lib/silcclient/client_keyagr.c index e05db76c..3d859cf7 100644 --- a/lib/silcclient/client_keyagr.c +++ b/lib/silcclient/client_keyagr.c @@ -579,7 +579,7 @@ void silc_client_perform_key_agreement_fd(SilcClient client, SILC_CLIENT_REGISTER_CONNECTION_FOR_IO(sock); /* Execute the protocol */ - protocol->execute(client->timeout_queue, 0, protocol, sock, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); } /* This function can be called to unbind the hostname and the port for diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index f82bbbeb..9231f8cf 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -255,7 +255,7 @@ static void silc_client_protocol_ke_continue(SilcSKE ske, } protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, 0, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return; } @@ -275,7 +275,7 @@ static void silc_client_protocol_ke_continue(SilcSKE ske, function. */ if (ctx->responder == TRUE) { protocol->state++; - protocol->execute(client->timeout_queue, 0, protocol, 0, 0, 100000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 100000); } } @@ -344,14 +344,14 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return; } /* Advance protocol state and call the next state if we are responder */ protocol->state++; if (ctx->responder == TRUE) - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 100000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 100000); } break; case 2: @@ -382,14 +382,14 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return; } /* Advance protocol state and call next state if we are initiator */ protocol->state++; if (ctx->responder == FALSE) - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 100000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 100000); } break; case 3: @@ -429,7 +429,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return; } } @@ -476,7 +476,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) ctx->sock->hostname); } protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); return; } } @@ -497,7 +497,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) keymat); if (status != SILC_SKE_STATUS_OK) { protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); silc_ske_free_key_material(keymat); return; } @@ -516,7 +516,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) /* Protocol has ended, call the final callback */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); } @@ -533,7 +533,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; @@ -551,7 +551,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; @@ -724,7 +724,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_connection_auth) /* Protocol has ended, call the final callback */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); } @@ -746,7 +746,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_connection_auth) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); } @@ -758,7 +758,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_connection_auth) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; @@ -948,8 +948,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_1) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, - 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); } ctx->ske = silc_ske_alloc(); @@ -965,14 +964,13 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); return; } /* Advance the protocol state */ protocol->state++; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); } else { /* * Do normal and simple re-key. @@ -1022,8 +1020,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); return; } @@ -1073,8 +1070,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); return; } } @@ -1087,7 +1083,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_2) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); } status = silc_ske_initiator_finish(ctx->ske, ctx->packet->buffer, @@ -1097,8 +1093,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) status)); protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, - protocol, fd, 0, 300000); + silc_protocol_execute(protocol, client->timeout_queue, 0, 300000); return; } } @@ -1126,7 +1121,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) if (ctx->packet->type != SILC_PACKET_REKEY_DONE) { /* Error in protocol */ protocol->state = SILC_PROTOCOL_STATE_ERROR; - protocol->execute(client->timeout_queue, 0, protocol, fd, 0, 0); + silc_protocol_execute(protocol, client->timeout_queue, 0, 0); } /* We received the REKEY_DONE packet and all packets after this is @@ -1135,7 +1130,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) /* Protocol has ended, call the final callback */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; @@ -1154,7 +1149,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; @@ -1166,7 +1161,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_rekey) /* On error the final callback is always called. */ if (protocol->final_callback) - protocol->execute_final(client->timeout_queue, 0, protocol, fd); + silc_protocol_execute_final(protocol, client->timeout_queue); else silc_protocol_free(protocol); break; diff --git a/lib/silccore/silcpayload.c b/lib/silccore/silcpayload.c index 1dc8f830..1d6e99f0 100644 --- a/lib/silccore/silcpayload.c +++ b/lib/silccore/silcpayload.c @@ -394,7 +394,7 @@ SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload) return buffer; } -/* Free's Command Payload */ +/* Frees Argument Payload */ void silc_argument_payload_free(SilcArgumentPayload payload) { diff --git a/lib/silccore/silcpayload.h b/lib/silccore/silcpayload.h index ea193128..861a6008 100644 --- a/lib/silccore/silcpayload.h +++ b/lib/silccore/silcpayload.h @@ -1,54 +1,334 @@ -/* - - silcpayload.h - - Author: Pekka Riikonen - - Copyright (C) 2000 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ +/****h* silccore/silcpayload.h + * + * NAME + * + * silcpayload.h + * + * COPYRIGHT + * + * Author: Pekka Riikonen + * + * Copyright (C) 2000 Pekka Riikonen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION + * + * Implementation of the generic payloads described in the protocol + * specification; ID Payload and Argument Payload. The ID Payload is + * used to represent an ID. The Argument Payload is used to include + * arguments to other payloads that needs arguments. + * + ***/ #ifndef SILCPAYLOAD_H #define SILCPAYLOAD_H -/* Forward declarations */ +/****s* silccore/SilcGenericPayloadAPI/SilcIDPayload + * + * NAME + * + * typedef struct SilcIDPayloadStruct *SilcIDPayload; + * + * DESCRIPTION + * + * This context is the actual ID Payload and is allocated + * by silc_id_payload_parse and given as argument usually to + * all silc_id_payload_* functions. It is freed by the + * silc_id_payload_free function. + * + ***/ typedef struct SilcIDPayloadStruct *SilcIDPayload; + +/****s* silccore/SilcGenericPayloadAPI/SilcArgumentPayload + * + * NAME + * + * typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; + * + * DESCRIPTION + * + * This context is the actual Argument Payload and is allocated + * by silc_argument_payload_parse and given as argument usually to + * all silc_argument_payload_* functions. It is freed by the + * silc_argument_payload_free function. + * + ***/ typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; /* Prototypes */ + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_parse + * + * SYNOPSIS + * + * SilcIDPayload silc_id_payload_parse(SilcBuffer buffer); + * + * DESCRIPTION + * + * Parses buffer and return ID payload into payload structure. The + * `buffer' is raw payload buffer. + * + ***/ SilcIDPayload silc_id_payload_parse(SilcBuffer buffer); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_parse_data + * + * SYNOPSIS + * + * SilcIDPayload silc_id_payload_parse_data(unsigned char *data, + * uint32 len); + * + * DESCRIPTION + * + * Parses buffer and return ID payload into payload structure. The + * `data' and `len' are the raw payload buffer. This is equivalent + * to the silc_id_payload_parse function. + * + ***/ SilcIDPayload silc_id_payload_parse_data(unsigned char *data, uint32 len); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_parse_id + * + * SYNOPSIS + * + * void *silc_id_payload_parse_id(unsigned char *data, uint32 len); + * + * DESCRIPTION + * + * Return ID directly from the raw ID Payload data buffer. The + * caller must free the returned ID. + * + ***/ void *silc_id_payload_parse_id(unsigned char *data, uint32 len); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_encode + * + * SYNOPSIS + * + * SilcBuffer silc_id_payload_encode(void *id, SilcIdType type); + * + * DESCRIPTION + * + * Encodes ID Payload. The `id' is the ID of the type `type' to put + * into the payload. Returns the encoded payload buffer. + * + ***/ SilcBuffer silc_id_payload_encode(void *id, SilcIdType type); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_free + * + * SYNOPSIS + * + * void silc_id_payload_free(SilcIDPayload payload); + * + * DESCRIPTION + * + * Frees the ID Payload and all data in it. + * + ***/ void silc_id_payload_free(SilcIDPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_type + * + * SYNOPSIS + * + * SilcIdType silc_id_payload_get_type(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the ID type from the ID Payload. The type tells the + * type of the ID in the payload. + * + ***/ SilcIdType silc_id_payload_get_type(SilcIDPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_id + * + * SYNOPSIS + * + * void *silc_id_payload_get_id(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the ID in the ID Payload. The caller must free the + * returned ID. + * + ***/ void *silc_id_payload_get_id(SilcIDPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_data + * + * SYNOPSIS + * + * unsigned char *silc_id_payload_get_data(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the raw ID data from the ID Payload. The data is duplicated + * and the caller must free it. + * + ***/ unsigned char *silc_id_payload_get_data(SilcIDPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_len + * + * SYNOPSIS + * + * uint32 silc_id_payload_get_len(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the length of the ID in the ID Payload. + * + ***/ uint32 silc_id_payload_get_len(SilcIDPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_parse + * + * SYNOPSIS + * + * SilcArgumentPayload silc_argument_payload_parse(SilcBuffer buffer, + * uint32 argc); + * + * DESCRIPTION + * + * Parses arguments and returns them into Argument Payload structure. + * the `buffer' is raw Argument Payload data buffer. The `argc' is + * the number of arguments in the Argument Payload. The caller must + * know the number of the arguments. This is always known as the + * Argument payload is associated with other payloads which defines + * the number of the arguments. + * + ***/ SilcArgumentPayload silc_argument_payload_parse(SilcBuffer buffer, uint32 argc); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_encode + * + * SYNOPSIS + * + * SilcBuffer silc_argument_payload_encode(uint32 argc, + * unsigned char **argv, + * uint32 *argv_lens, + * uint32 *argv_types); + * + * DESCRIPTION + * + * Encodes arguments in to Argument Paylods returning them to SilcBuffer. + * The `argv' is the array of the arguments, the `argv_lens' array of + * the length of the `argv' arguments and the `argv_types' array of + * the argument types of the `argv' arguments. The `argc' is the + * number of arguments. + * + ***/ SilcBuffer silc_argument_payload_encode(uint32 argc, unsigned char **argv, uint32 *argv_lens, uint32 *argv_types); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_encode_payload + * + * SYNOPSIS + * + * SilcBuffer + * silc_argument_payload_encode_payload(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Same as silc_argument_payload_encode but encodes the payload from + * already allocated SilcArgumentPayload structure instead of raw data. + * + ***/ SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_free + * + * SYNOPSIS + * + * void silc_argument_payload_free(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Frees the Argument Payload and all data in it. + * + ***/ void silc_argument_payload_free(SilcArgumentPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_arg_num + * + * SYNOPSIS + * + * uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Returns the number of argument in the Argument Payload. + * + ***/ uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_first_arg + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns the first argument in the Argument Payload. The lenght + * of the argument is returned to `ret_len'. The caller must not + * free the returned argument. Returns NULL on error. + * + ***/ unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, uint32 *ret_len); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_next_arg + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns next argument from the Argument Payload. The length of + * the argument is returned to `ret_len'. The caller must not free + * the returned argument. This returns NULL when there are no more + * arguments in the payload. + * + ***/ unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, uint32 *ret_len); + +/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_arg_type + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, + * uint32 type, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns argument by type. The returned argument has type `type' + * in the Argument Payload. Each argument has their own type (or zero + * if no specific type is set). The length of the argument is returned + * to the `ret_len'. The caller must not free the returned argument. + * Returns NULL on error. + * + ***/ unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, uint32 type, uint32 *ret_len); diff --git a/lib/silccore/silcprotocol.c b/lib/silccore/silcprotocol.c index 9eb50898..9f091e6a 100644 --- a/lib/silccore/silcprotocol.c +++ b/lib/silccore/silcprotocol.c @@ -100,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) { @@ -116,42 +114,30 @@ 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, void *timeout_queue, long secs, long usecs) { - SilcProtocol protocol = (SilcProtocol)context; - - SILC_LOG_DEBUG(("Start")); - if (secs + usecs) - silc_task_register(qptr, fd, protocol->protocol->callback, context, + silc_task_register(timeout_queue, 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(timeout_queue, 0, (void *)protocol, 0); } /* 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, void *timeout_queue) { - SilcProtocol protocol = (SilcProtocol)context; - - SILC_LOG_DEBUG(("Start, state=%d", protocol->state)); - - protocol->final_callback(qptr, 0, context, fd); + protocol->final_callback(timeout_queue, 0, (void *)protocol, 0); } /* Cancels the execution of the next state of the protocol. */ -void silc_protocol_cancel(void *qptr, void *context) +void silc_protocol_cancel(SilcProtocol protocol, void *timeout_queue) { - SilcProtocol protocol = (SilcProtocol)context; - - SILC_LOG_DEBUG(("Start")); - - silc_task_unregister_by_callback(qptr, protocol->protocol->callback); + silc_task_unregister_by_callback(timeout_queue, + protocol->protocol->callback); } diff --git a/lib/silccore/silcprotocol.h b/lib/silccore/silcprotocol.h index 534aa493..197307c2 100644 --- a/lib/silccore/silcprotocol.h +++ b/lib/silccore/silcprotocol.h @@ -1,30 +1,92 @@ -/* - - silcprotocol.h - - Author: Pekka Riikonen - - Copyright (C) 1997 - 2000 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ +/****h* silccore/silcprotocol.h + * + * NAME + * + * silcprotocol.h + * + * COPYRIGHT + * + * Author: Pekka Riikonen + * + * Copyright (C) 1997 - 2000 Pekka Riikonen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION + * + * Implementation of the protocol handling routines for SILC applications. + * These routines allow execution of arbitrary protocols in the application. + * New protocols may be registered by type and allocated later by that + * type for the execution. The protocols implements a state machine style + * execution where each state is executed one after the other. The + * application controls these states and their order of execution. + * + * After the protocol has been executed, an final callback is called + * which the application may use to do post-protocol work or to start + * perhaps other protocols. These routines are generic and the actual + * protocols, their types, callback and final callbacks functions must + * be implemented in the application. + * + ***/ #ifndef SILCPROTOCOL_H #define SILCPROTOCOL_H -/* Protocol type definition. */ +/****d* silccore/SilcProtocolAPI/SilcProtocolType + * + * NAME + * + * typedef unsigned char SilcProtocolType; + * + * DESCRIPTION + * + * Protocol type definition. The protocol types are application + * specific and this is just a generic type for them. + * + ***/ typedef unsigned char SilcProtocolType; -/* Protocol state definition. */ +/****d* silccore/SilcProtocolAPI/SilcProtocolState + * + * NAME + * + * typedef unsigned char SilcProtocolState; + * + * DESCRIPTION + * + * Protocol state definition and the defined protocol states. These + * states are the generic states. However, each protocol actually + * implements the states. The state after SILC_PROTOCOL_STATE_START + * would be state 2 in the application. These states can be easily + * used for example inside switch() statement. + * + * EXAMPLE + * + * switch (protocol->state) { + * case SILC_PROTOCOL_STATE_START: + * protocol_starts_here(); + * case 2: + * ... + * case 3: + * ... + * case SILC_PROTOCOL_STATE_END: + * protocol_ends_here(); + * case SILC_PROTOCOL_STATE_FAILURE: + * remote_end_sent_failure(); + * case SILC_PROTOCOL_STATE_ERROR: + * local_error_during_protocol(); + * } + * + * SOURCE + */ typedef unsigned char SilcProtocolState; /* Protocol states. Do NOT change the values of these states, especially @@ -34,96 +96,255 @@ typedef unsigned char SilcProtocolState; #define SILC_PROTOCOL_STATE_END 252 #define SILC_PROTOCOL_STATE_FAILURE 253 /* Received failure from remote */ #define SILC_PROTOCOL_STATE_ERROR 254 /* Local error at our end */ +/***/ -/* Type definition for above auth methods */ +/* Type definition for authentication protocol's auth methods. */ +/* XXX strictly speaking this belongs to application */ typedef unsigned char SilcProtocolAuthMeth; -/* - SILC Protocol Object. - - Short description of the field following: - - SilcProtocolType type - - Protocol type. This is enumeration. - - SilcProtocolCallback callback; - - Callback function for the protocol. This is SilcTaskCallback function - pointer as the protocols in SILC are executed as timeout tasks. - - The object expands to another structure as well. Short description of - these fields following: - - SilcProtocolObject *protocol - - This is the pointer to the protocol object defined above. - - SilcProtocolState state - - Protocol state. This is enumeration. The state of the protocol can - be changed in the callback function. - - void *context - - Context to be sent for the callback function. This is usually - object for either SILC client or server. However, this abstraction - makes it possible that this pointer could be some other object as well. - - SilcProtocolExecute execute; - - Executes the protocol and its states. The correct state must be set - before calling this function. The state is usually set in the protocol - specific routines. - - SilcProtocolExecute execute_final; - - Executes the final callback function of the protocol. Read on. - - SilcProtocolFinalCallback final_callback; - - This is a callback function that is called with timeout _after_ the - protocol has finished or error occurs. If this is NULL, naturally - nothing will be executed. Protocol should call this function only at - SILC_PROTOCOL_STATE_END and SILC_PROTOCOL_STATE_ERROR states. - -*/ +/****f* silccore/SilcProtocolAPI/SilcProtocolCallback + * + * SYNOPSIS + * + * typedef SilcTaskCallback SilcProtocolCallback; + * + * DESCRIPTION + * + * Protocol callback. This callback is set when registering new + * protocol. The callback is called everytime the protocol is executed. + * The `context' delivered to this callback function is the SilcProtocol + * context and needs to be explicitly type casted to SilcProtocol in + * the callback function. + * + ***/ typedef SilcTaskCallback SilcProtocolCallback; +/****f* silccore/SilcProtocolAPI/SilcProtocolFinalCallback + * + * SYNOPSIS + * + * typedef SilcTaskCallback SilcProtocolFinalCallback; + * + * DESCRIPTION + * + * Final protocol callback. This callback is set when allocating + * protocol for execution. This is called when the protocol has ended. + * The `context' delivered to this callback function is the SilcProtocol + * context and needs to be explicitly type casted to SilcProtocol in + * the callback function. + * + ***/ +typedef SilcTaskCallback SilcProtocolFinalCallback; + +/****s* silccore/SilcProtocolAPI/SilcProtocolObject + * + * NAME + * + * typedef struct SilcProtocolObjectStruct { ... } SilcProtocolObject; + * + * DESCRIPTION + * + * The object for one protocol. This hold the information of one + * registered protocol. Application must not allocate this type + * directly. It is used by the protocol routines. + * + * Short description of the field following: + * + * SilcProtocolType type + * + * Protocol type. + * + * SilcProtocolCallback callback; + * + * Callback function for the protocol. This is SilcTaskCallback function + * pointer as the protocols in SILC are executed as timeout tasks. + * + * struct SilcProtocolObjectStruct *next; + * + * Pointer to the next protocol. + * + ***/ typedef struct SilcProtocolObjectStruct { SilcProtocolType type; SilcProtocolCallback callback; - struct SilcProtocolObjectStruct *next; } SilcProtocolObject; -typedef SilcTaskCallback SilcProtocolFinalCallback; -typedef SilcTaskCallback SilcProtocolExecute; - +/****s* silccore/SilcProtocolAPI/SilcProtocol + * + * NAME + * + * typedef struct SilcProtocolStruct { ... } *SilcProtocol; + * + * DESCRIPTION + * + * The actual protocol object. This is allocated by the silc_protocol_alloc + * and holds the information about the current protocol. Information + * such as the current state, execution callback and final callback. + * The context is freed by silc_protocol_free function. + * + * Short description of the field following: + * + * SilcProtocolObject *protocol + * + * This is the pointer to the SilcProtocolObject and holds the + * protocol specific information. + * + * SilcProtocolState state + * + * Protocol state. The state of the protocol can be changed in the + * callback function. + * + * void *context + * + * Context to be sent for the callback function. This is usually + * object for either SILC client or server. However, this abstraction + * makes it possible that this pointer could be some other object as + * well. Note that the context is not delivered in any callback + * function. Application can access it through this context. + * + * SilcProtocolFinalCallback final_callback; + * + * This is a callback function that is called with timeout _after_ the + * protocol has finished or error occurs. If this is NULL, naturally + * nothing will be executed. Protocol should call this function only at + * SILC_PROTOCOL_STATE_END and SILC_PROTOCOL_STATE_ERROR states. + * + ***/ typedef struct SilcProtocolStruct { SilcProtocolObject *protocol; SilcProtocolState state; void *context; - - // SilcProtocolExecute execute; - void (*execute)(void *, int, void *, int, long, long); - SilcProtocolExecute execute_final; SilcProtocolFinalCallback final_callback; } *SilcProtocol; /* Prototypes */ + +/****f* silccore/SilcProtocolAPI/silc_protocol_register + * + * SYNOPSIS + * + * void silc_protocol_register(SilcProtocolType type, + * SilcProtocolCallback callback); + * + * DESCRIPTION + * + * Dynamically registers new protocol. The protocol is added into protocol + * list and can be unregistered with silc_protocol_unregister. The + * `type' is the type of the protocol and is used to identify the + * protocol when allocating it with silc_protocol_alloc. The `callback' + * is the actual protocol function that is called when protocol is + * executed (and it performes the actual protocol). The protocol + * is unregistered by silc_protocol_unregister function. + * + ***/ void silc_protocol_register(SilcProtocolType type, SilcProtocolCallback callback); + +/****f* silccore/SilcProtocolAPI/silc_protocol_unregister + * + * SYNOPSIS + * + * void silc_protocol_unregister(SilcProtocolType type, + * SilcProtocolCallback callback); + * + * DESCRIPTION + * + * Unregisters protocol. The unregistering is done by both protocol type + * and the protocol callback. Every registered protocol must be + * unregistered using this function. + * + ***/ void silc_protocol_unregister(SilcProtocolType type, SilcProtocolCallback callback); + +/****f* silccore/SilcProtocolAPI/silc_protocol_alloc + * + * SYNOPSIS + * + * void silc_protocol_alloc(SilcProtocolType type, + * SilcProtocol *new_protocol, + * void *context, + * SilcProtocolFinalCallback callback); + * + * DESCRIPTION + * + * Allocates a new protocol. The new allocated and initialized + * protocol is returned to the `new_protocol' argument. The argument + * context `context' is the context to be sent as argument for the + * protocol callback function. The `callback' argument is the function + * to be called after the protocol has finished. + * + ***/ void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol, void *context, SilcProtocolFinalCallback callback); + +/****f* silccore/SilcProtocolAPI/silc_protocol_free + * + * SYNOPSIS + * + * void silc_protocol_free(SilcProtocol protocol); + * + * DESCRIPTION + * + * Frees the protocol context. This must be called for all allocated + * protocols. + * + ***/ void silc_protocol_free(SilcProtocol protocol); -void silc_protocol_execute(void *qptr, int type, - void *context, int fd, + +/****f* silccore/SilcProtocolAPI/silc_protocol_execute + * + * SYNOPSIS + * + * void silc_protocol_execute(SilcProtocol protocol, void *timeout_queue, + * long secs, long usecs); + * + * DESCRIPTION + * + * Executes the protocol. This calls the state that has been set. + * The state must be set before calling this function. This is then + * also used to call always the next state after changing the state + * of the protocol. The `timeout_queue' is a timeout task queue from + * the application. It is passed to the protocol callback functions. + * The `secs' and `usecs' are the timeout before the protocol is + * executed. If both zero the protocol is executed immediately. + * + ***/ +void silc_protocol_execute(SilcProtocol protocol, void *timeout_queue, long secs, long usecs); -void silc_protocol_execute_final(void *qptr, int type, - void *context, int fd); -void silc_protocol_cancel(void *qptr, void *context); + +/****f* silccore/SilcProtocolAPI/silc_protocol_execute_final + * + * SYNOPSIS + * + * void + * silc_protocol_execute_final(SilcProtocol protocol, void *timeout_queue); + * + * DESCRIPTION + * + * Executes the final callback for the protocol. The `timeout_queue' is + * a timeout task queue from the application. It is passed to the + * protocol callback functions. The final callback is executed + * immediately. + * + ***/ +void silc_protocol_execute_final(SilcProtocol protocol, void *timeout_queue); + +/****f* silccore/SilcProtocolAPI/silc_protocol_cancel + * + * SYNOPSIS + * + * void silc_protocol_cancel(SilcProtocol protocol, void *timeout_queue); + * + * DESCRIPTION + * + * Cancels the execution of the next state of the protocol. This has + * effect only if the silc_protocol_execute was called with timeout. + * It is guaranteed that if the protocol is cancelled before the timeout + * has elapsed the protocol callback won't be called. + * + ***/ +void silc_protocol_cancel(SilcProtocol protocol, void *timeout_queue); #endif diff --git a/lib/silccore/silcsockconn.c b/lib/silccore/silcsockconn.c index a239d06c..5111980b 100644 --- a/lib/silccore/silcsockconn.c +++ b/lib/silccore/silcsockconn.c @@ -21,6 +21,16 @@ #include "silcincludes.h" +/* Heartbeat context */ +struct SilcSocketConnectionHB { + uint32 heartbeat; + SilcSocketConnectionHBCb hb_callback; + void *hb_context; + void *timeout_queue; + SilcTask hb_task; + SilcSocketConnection sock; +}; + /* Allocates a new socket connection object. The allocated object is returned to the new_socket argument. */ diff --git a/lib/silccore/silcsockconn.h b/lib/silccore/silcsockconn.h index f77ea997..5d9781af 100644 --- a/lib/silccore/silcsockconn.h +++ b/lib/silccore/silcsockconn.h @@ -1,37 +1,96 @@ -/* - - silcsockconn.h - - Author: Pekka Riikonen - - Copyright (C) 1997 - 2000 Pekka Riikonen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ +/****h* silccore/silcsockconn.h + * + * NAME + * + * silcsockconn.h + * + * COPYRIGHT + * + * Author: Pekka Riikonen + * + * Copyright (C) 1997 - 2000 Pekka Riikonen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * DESCRIPTION + * + * Implementation of the Socket Connection object. The SilcSocketConnection + * is used by all applications to represent a socket based connection + * to the network. The Socket Connection object handles inbound and outbound + * data buffers, can perform keepalive actions for the connection and + * supports connection based protocols as well. + * + ***/ #ifndef SILCSOCKCONN_H #define SILCSOCKCONN_H -/* Forward declarations */ +/****s* silccore/SilcSocketConnectionAPI/SilcSocketConnection + * + * NAME + * + * typedef struct SilcSocketConnectionStruct *SilcSocketConnection; + * + * DESCRIPTION + * + * This context is forward declaration for the SilcSocketConnectionStruct. + * This is allocated by the silc_socket_alloc and freed by the + * silc_socket_free function. The silc_socket_dup can be used to + * increase the reference counter of the context. The data is freed + * by the silc_socket_free function only after the reference counter + * hits zero. + * + ***/ typedef struct SilcSocketConnectionStruct *SilcSocketConnection; + +/****s* silccore/SilcSocketConnectionAPI/SilcSocketConnectionHB + * + * NAME + * + * typedef struct SilcSocketConnectionHB *SilcSocketConnectionHB; + * + * DESCRIPTION + * + * This context is the heartbeat context for the SilcSockeConnection. + * It is meant to hold the keepalive information for the connection. + * This is allocated internally and freed internally by the + * interface routines. + * + ***/ typedef struct SilcSocketConnectionHB *SilcSocketConnectionHB; -/* Socket types. These identifies the socket connection. */ +/****d* silccore/SilcSocketConnectionAPI/SilcSocketType + * + * NAME + * + * typedef enum { ... } SilcSocketType; + * + * DESCRIPTION + * + * Socket types. These identifies the socket connection. There + * are four different types; unknown, client, server and router. + * Unknown connections are connections that hasn't advanced long + * enough so that we might know which type of connection it is. + * It is the applications responsibility to update the type + * information when it becomes available. + * + * SOURCE + */ typedef enum { SILC_SOCKET_TYPE_UNKNOWN = 0, SILC_SOCKET_TYPE_CLIENT = 1, SILC_SOCKET_TYPE_SERVER = 2, SILC_SOCKET_TYPE_ROUTER = 3 } SilcSocketType; +/***/ /* Socket flags */ #define SILC_SF_NONE 0 @@ -40,77 +99,94 @@ typedef enum { #define SILC_SF_DISCONNECTING 3 #define SILC_SF_DISCONNECTED 4 -/* Heartbeat callback function. This is the function in the application - that this library will call when it is time to send the keepalive - packet SILC_PACKET_HEARTBEAT. */ +/****f* silccore/SilcSocketConnectionAPI/SilcSocketConnectionHBCb + * + * SYNOPSIS + * + * typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, + * void *context); + * + * DESCRIPTION + * + * Heartbeat callback function. This is the function in the application + * that this library will call when it is time to send the keepalive + * packet SILC_PACKET_HEARTBEAT. + * + ***/ typedef void (*SilcSocketConnectionHBCb)(SilcSocketConnection sock, void *context); -/* - SILC Socket Connection object. - - This object holds information about the connected sockets to the server. - This is quite important object since this is referenced by the server all - the time when figuring out what the connection is supposed to be doing - and to whom we should send a message. - - Following short description of the fields: - - int sock - - The actual connected socket. This is usually saved when accepting - new connection to the server. - - SilcSocketType type - - Type of the socket. This identifies the type of the connection. This - is mainly used to identify whether the connection is a client or a - server connection. - - void *user_data - - This is a pointer to a data that is is saved here at the same - time a new connection object is allocated. Usually this is a - back-pointer to some important data for fast referencing. For - SILC server this is a pointer to the ID list and for SILC client - to object holding active connections (windows). - - SilcProtocol protocol - - Protocol object for the socket. Currently only one protocol can be - executing at a time for a particular socket. - - uint32 flags - - Socket flags that indicate the status of the socket. This can - indicate several different status that can affect the use of the - socket object. - - int users - - Reference counter. When allocated it is set to one (1) and it won't - be freed until it hits zero (0). - - char *hostname - char *ip - uint16 port - - Resolved hostname, IP address and port of the connection who owns - this object. - - SilcBuffer inbuf - SilcBuffer outbuf - - Incoming and outgoing buffers for the particular socket connection. - Incoming data from the socket is put after decryption in to the - inbuf buffer and outgoing data after encryption is put to the outbuf - buffer. - - SilcSocketConnectionHB hb - - The heartbeat context. If NULL, heartbeat is not performed. - -*/ +/****s* silccore/SilcSocketConnectionAPI/SilcSocketConnectionStruct + * + * NAME + * + * struct SilcSocketConnectionStruct { ... }; + * + * DESCRIPTION + * + * This object holds information about the connected sockets to the server. + * This is quite important object since this is referenced by the server all + * the time when figuring out what the connection is supposed to be doing + * and to whom we should send a message. This structure is the structure + * for the SilcSocketConnection forward declaration. + * + * Following short description of the fields: + * + * int sock + * + * The actual connected socket. This is usually saved when accepting + * new connection to the server. + * + * SilcSocketType type + * + * Type of the socket. This identifies the type of the connection. This + * is mainly used to identify whether the connection is a client or a + * server connection. + * + * void *user_data + * + * This is a pointer to a data that is is saved here at the same + * time a new connection object is allocated. Usually this is a + * back-pointer to some important data for fast referencing. For + * SILC server this is a pointer to the ID list and for SILC client + * to object holding active connections (windows). + * + * SilcProtocol protocol + * + * Protocol object for the socket. Currently only one protocol can be + * executing at a time for a particular socket. + * + * uint32 flags + * + * Socket flags that indicate the status of the socket. This can + * indicate several different status that can affect the use of the + * socket object. + * + * int users + * + * Reference counter. When allocated it is set to one (1) and it won't + * be freed until it hits zero (0). + * + * char *hostname + * char *ip + * uint16 port + * + * Resolved hostname, IP address and port of the connection who owns + * this object. + * + * SilcBuffer inbuf + * SilcBuffer outbuf + * + * Incoming and outgoing buffers for the particular socket connection. + * Incoming data from the socket is put after decryption in to the + * inbuf buffer and outgoing data after encryption is put to the outbuf + * buffer. + * + * SilcSocketConnectionHB hb + * + * The heartbeat context. If NULL, heartbeat is not performed. + * + ***/ struct SilcSocketConnectionStruct { int sock; SilcSocketType type; @@ -129,16 +205,6 @@ struct SilcSocketConnectionStruct { SilcSocketConnectionHB hb; }; -/* Heartbeat context */ -struct SilcSocketConnectionHB { - uint32 heartbeat; - SilcSocketConnectionHBCb hb_callback; - void *hb_context; - void *timeout_queue; - SilcTask hb_task; - SilcSocketConnection sock; -}; - /* Macros */ /* Generic manipulation of flags */ @@ -163,10 +229,78 @@ struct SilcSocketConnectionHB { #define SILC_IS_DISCONNECTED(x) SF_IS((x), SILC_SF_DISCONNECTED) /* Prototypes */ + +/****f* silccore/SilcSocketConnectionAPI/silc_socket_alloc + * + * SYNOPSIS + * + * void silc_socket_alloc(int sock, SilcSocketType type, void *user_data, + * SilcSocketConnection *new_socket); + * + * DESCRIPTION + * + * Allocates a new socket connection object. The allocated object is + * returned to the new_socket argument. The `sock' is the socket + * for the connection, the `type' the initial type of the connection and + * the `user_data' a application specific pointer. + * + ***/ void silc_socket_alloc(int sock, SilcSocketType type, void *user_data, SilcSocketConnection *new_socket); + +/****f* silccore/SilcSocketConnectionAPI/silc_socket_free + * + * SYNOPSIS + * + * void silc_socket_free(SilcSocketConnection sock); + * + * DESCRIPTION + * + * Frees the socket connection context. This frees it only if the + * reference counter of the socket is zero, otherwise it decreases the + * reference counter. + * + ***/ void silc_socket_free(SilcSocketConnection sock); + +/****f* silccore/SilcSocketConnectionAPI/silc_socket_dup + * + * SYNOPSIS + * + * SilcSocketConnection silc_socket_dup(SilcSocketConnection sock); + * + * DESCRIPTION + * + * Duplicates the socket context. This actually does not duplicate + * any data, instead this increases the reference counter of the + * context. The reference counter is decreased by calling the + * silc_socket_free function and it frees the data when the counter + * hits zero. + * + ***/ SilcSocketConnection silc_socket_dup(SilcSocketConnection sock); + +/****f* silccore/SilcSocketConnectionAPI/silc_socket_set_heartbeat + * + * SYNOPSIS + * + * void silc_socket_set_heartbeat(SilcSocketConnection sock, + * uint32 heartbeat, + * void *hb_context, + * SilcSocketConnectionHBCb hb_callback, + * void *timeout_queue); + * + * DESCRIPTION + * + * Sets the heartbeat timeout and prepares the socket for performing + * heartbeat in `heartbeat' intervals (seconds). The `hb_context' is + * allocated by the application and will be sent as argument to the + * `hb_callback' function that is called when the `heartbeat' timeout + * expires. The callback `hb_context' won't be touched by the library + * but will be freed automatically when calling silc_socket_free. The + * `timeout_queue' is the application's scheduler timeout queue. + * + ***/ void silc_socket_set_heartbeat(SilcSocketConnection sock, uint32 heartbeat, void *hb_context,