Logo Search packages:      
Sourcecode: libmpdclient version File versions  Download package

bool mpd_async_send_command_v ( struct mpd_async async,
const char *  command,
va_list  args 
)

Appends a command to the output buffer.

Parameters:
async the connection
command the command name, followed by arguments, terminated by NULL
args the argument list
Returns:
true on success, false if the buffer is full

Definition at line 279 of file async.c.

References mpd_async::error, mpd_async_send_command_v(), and mpd_async::output.

Referenced by mpd_async_send_command(), mpd_async_send_command_v(), and mpd_sync_send_command_v().

{
      size_t room, length;
      char *dest, *end, *p;
      const char *arg;

      assert(async != NULL);
      assert(command != NULL);

      if (mpd_error_is_defined(&async->error))
            return false;

      room = mpd_buffer_room(&async->output);
      length = strlen(command);
      if (room <= length)
            return false;

      dest = mpd_buffer_write(&async->output);
      /* -1 because we reserve space for the \n character */
      end = dest + room - 1;

      /* copy the command (no quoting, we asumme it is "clean") */

      memcpy(dest, command, length);
      p = dest + length;

      /* now append all arguments (quoted) */

      while ((arg = va_arg(args, const char *)) != NULL) {
            /* append a space separator */

            if (p >= end)
                  return false;

            *p++ = ' ';

            /* quote the argument into the destination buffer */

            p = quote(p, end, arg);
            assert(p == NULL || (p >= dest && p <= end));
            if (p == NULL)
                  return false;
      }


      /* append the newline to finish this command */

      *p++ = '\n';

      mpd_buffer_expand(&async->output, p - dest);
      return true;
}


Generated by  Doxygen 1.6.0   Back to index