- /* Allocate command context. This must be free'd by the
- command routine receiving it. */
- ctx = silc_server_command_alloc();
- ctx->server = server;
- ctx->sock = silc_socket_dup(sock);
- ctx->packet = silc_packet_context_dup(packet); /* Save original packet */
-
- /* Parse the command payload in the packet */
- ctx->payload = silc_command_payload_parse(packet->buffer);
- if (!ctx->payload) {
- SILC_LOG_ERROR(("Bad command payload, packet dropped"));
- silc_buffer_free(packet->buffer);
- silc_packet_context_free(packet);
- silc_socket_free(ctx->sock);
- silc_free(ctx);
- return;
- }
- ctx->args = silc_command_get_args(ctx->payload);
-
- /* Execute command. If this fails the packet is dropped. */
- for (cmd = silc_command_list; cmd->cb; cmd++)
- if (cmd->cmd == silc_command_get(ctx->payload)) {
-
- if (!(cmd->flags & SILC_CF_REG)) {
- cmd->cb(ctx);
- break;
- }
-
- if (silc_server_is_registered(server, sock, ctx, cmd->cmd)) {
- cmd->cb(ctx);
- break;
- }
- }