+/* Timeout for pending command. If reply to pending command never arrives
+ this is called to free resources. */
+
+SILC_TASK_CALLBACK(silc_server_command_pending_timeout)
+{
+ SilcServer server = app_context;
+ SilcServerCommandPending *reply = context;
+ SilcServerCommandReplyContext cmdr;
+ SilcBuffer tmpreply;
+ int i;
+
+ SILC_LOG_DEBUG(("Timeout pending command"));
+
+ /* Allocate temporary and bogus command reply context */
+ cmdr = silc_calloc(1, sizeof(*cmdr));
+ cmdr->server = server;
+ cmdr->ident = reply->ident;
+
+ /* Check for pending commands and mark to be exeucted */
+ cmdr->callbacks =
+ silc_server_command_pending_check(server, reply->reply_cmd,
+ reply->ident, &cmdr->callbacks_count);
+
+ /* Create bogus command reply with an error inside */
+ tmpreply =
+ silc_command_reply_payload_encode_va(reply->reply_cmd,
+ SILC_STATUS_ERR_TIMEDOUT, 0,
+ reply->ident, 0);
+ cmdr->payload = silc_command_payload_parse(tmpreply->data, tmpreply->len);
+ silc_buffer_free(tmpreply);
+
+ /* Call all callbacks. Same as SILC_SERVER_PENDING_EXEC macro. */
+ for (i = 0; i < cmdr->callbacks_count; i++)
+ if (cmdr->callbacks[i].callback)
+ (*cmdr->callbacks[i].callback)(cmdr->callbacks[i].context, cmdr);
+
+ silc_server_command_pending_del(server, reply->reply_cmd, reply->ident);
+ silc_server_command_reply_free(cmdr);
+}
+