X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.c;h=aaaaaecf02084c188482214bebd3df433c54e72b;hp=2cac57f90637f8aa42635700a58b77a688b3ff5d;hb=23b121a85984baa9252f4b4c0b8c4f186e394bb7;hpb=1745a87654ce08b57c46ce0870d8571eacbe27c9 diff --git a/command.c b/command.c index 2cac57f9..aaaaaecf 100644 --- a/command.c +++ b/command.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2012 Andre Noll + * Copyright (C) 1997-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -36,6 +36,9 @@ #include "signal.h" #include "version.h" +struct server_command afs_cmds[] = {DEFINE_AFS_CMD_ARRAY}; +struct server_command server_cmds[] = {DEFINE_SERVER_CMD_ARRAY}; + /** Commands including options must be shorter than this. */ #define MAX_COMMAND_LEN 32768 @@ -256,6 +259,14 @@ __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band, return send_sb(scc, msg, ret, band, false); } +/** + * Send an error message to a client. + * + * \param cc Client info. + * \param err The (positive) error code. + * + * \return The return value of the underlying call to send_sb_va(). + */ int send_strerror(struct command_context *cc, int err) { return cc->use_sideband? @@ -314,7 +325,7 @@ fail: return ret; } -int com_sender(struct command_context *cc) +static int com_sender(struct command_context *cc) { int i, ret = 0; char *msg = NULL; @@ -371,7 +382,7 @@ int com_sender(struct command_context *cc) } /* server info */ -int com_si(struct command_context *cc) +static int com_si(struct command_context *cc) { int i, ret; char *msg, *ut, *sender_info = NULL; @@ -400,7 +411,7 @@ int com_si(struct command_context *cc) mmd->num_commands, mmd->num_connects, conf.loglevel_arg, - SERVER_AUDIO_FORMATS, + AUDIO_FORMAT_HANDLERS, sender_info ); mutex_unlock(mmd_mutex); @@ -414,7 +425,7 @@ int com_si(struct command_context *cc) } /* version */ -int com_version(struct command_context *cc) +static int com_version(struct command_context *cc) { char *msg; size_t len; @@ -495,7 +506,7 @@ out: #undef EMPTY_STATUS_ITEMS /* stat */ -int com_stat(struct command_context *cc) +static int com_stat(struct command_context *cc) { int i, ret; struct misc_meta_data tmp, *nmmd = &tmp; @@ -605,7 +616,7 @@ static struct server_command *get_cmd_ptr(const char *name, char **handler) } /* help */ -int com_help(struct command_context *cc) +static int com_help(struct command_context *cc) { struct server_command *cmd; char *perms, *handler, *buf; @@ -644,7 +655,7 @@ int com_help(struct command_context *cc) } /* hup */ -int com_hup(struct command_context *cc) +static int com_hup(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -653,7 +664,7 @@ int com_hup(struct command_context *cc) } /* term */ -int com_term(struct command_context *cc) +static int com_term(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -661,7 +672,7 @@ int com_term(struct command_context *cc) return 1; } -int com_play(struct command_context *cc) +static int com_play(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -673,7 +684,7 @@ int com_play(struct command_context *cc) } /* stop */ -int com_stop(struct command_context *cc) +static int com_stop(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -686,7 +697,7 @@ int com_stop(struct command_context *cc) } /* pause */ -int com_pause(struct command_context *cc) +static int com_pause(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -701,7 +712,7 @@ int com_pause(struct command_context *cc) } /* next */ -int com_next(struct command_context *cc) +static int com_next(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -713,7 +724,7 @@ int com_next(struct command_context *cc) } /* nomore */ -int com_nomore(struct command_context *cc) +static int com_nomore(struct command_context *cc) { if (cc->argc != 1) return -E_COMMAND_SYNTAX; @@ -725,7 +736,7 @@ int com_nomore(struct command_context *cc) } /* ff */ -int com_ff(struct command_context *cc) +static int com_ff(struct command_context *cc) { long promille; int ret, backwards = 0; @@ -764,7 +775,7 @@ out: } /* jmp */ -int com_jmp(struct command_context *cc) +static int com_jmp(struct command_context *cc) { long unsigned int i; int ret; @@ -981,7 +992,7 @@ __noreturn void handle_connect(int fd, const char *peername) /* send Welcome message */ ret = write_va_buffer(fd, "This is para_server, version " PACKAGE_VERSION ".\n" - "Features: sideband,foo\n" + "Features: sideband\n" ); if (ret < 0) goto net_err; @@ -1107,19 +1118,17 @@ net_err: out: free(buf); free(command); - sc_free(cc->scc.recv); - sc_free(cc->scc.send); mutex_lock(mmd_mutex); if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0) mmd->events++; mmd->active_connections--; mutex_unlock(mmd_mutex); - if (ret < 0) - exit(EXIT_FAILURE); - if (!cc->use_sideband) - exit(EXIT_SUCCESS); - ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true); - if (ret < 0) - PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); + if (ret >= 0 && cc->use_sideband) { + ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true); + if (ret < 0) + PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); + } + sc_free(cc->scc.recv); + sc_free(cc->scc.send); exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS); }