+Sun Jun 3 14:21:32 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+ * 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 <priikone@poseidon.pspt.fi>
* Fixed a bug in Irssi SILC client; do not show that you are
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);
}
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;
}
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:
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:
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:
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;
}
}
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;
}
/* 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);
}
/* 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;
/* 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;
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;
}
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;
}
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;
}
}
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;
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 {
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;
}
}
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;
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 {
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;
}
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;
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 {
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;
}
}
/* 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 {
/*
/* 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);
}
/* 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);
}
/* 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;
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();
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.
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;
}
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;
}
}
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,
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;
}
}
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
/* 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;
/* 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;
/* 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;
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
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
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:
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."));
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;
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 "
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;
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 "
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."));
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."));
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);
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,
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)
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;
}
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
* 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:
/*
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."));
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;
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 "
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;
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 "
/* 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."));
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,
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)
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
}
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;
}
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);
}
}
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:
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:
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;
}
}
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;
}
}
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;
}
/* 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);
}
/* 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;
/* 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;
/* 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);
}
/* 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);
}
/* 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;
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();
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.
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;
}
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;
}
}
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,
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;
}
}
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
/* 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;
/* 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;
/* 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;
return buffer;
}
-/* Free's Command Payload */
+/* Frees Argument Payload */
void silc_argument_payload_free(SilcArgumentPayload payload)
{
-/*
-
- silcpayload.h
-
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
-
- 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 <priikone@poseidon.pspt.fi>
+ *
+ * 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);
(*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)
{
/* 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);
}
-/*
-
- silcprotocol.h
-
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
-
- 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 <priikone@poseidon.pspt.fi>
+ *
+ * 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
#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
#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. */
-/*
-
- silcsockconn.h
-
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
-
- 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 <priikone@poseidon.pspt.fi>
+ *
+ * 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
#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;
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 */
#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,