Merge branch 'afh_cleanup' into next.
authorAndre Noll <maan@systemlinux.org>
Sat, 4 Jul 2009 15:15:50 +0000 (17:15 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 4 Jul 2009 15:15:50 +0000 (17:15 +0200)
Quite a few conflicts, but no real problem. git rerere rulez!

Conflicts:
afs.c
afs.cmd
aft.c
attribute.c
audiod_command.c
blob.c
command.c
para.h
server.c
server.cmd
stat.c

20 files changed:
1  2 
Makefile.in
aac_afh.c
afs.c
afs.cmd
afs.h
aft.c
attribute.c
audiod.c
blob.c
command.c
configure.ac
error.h
mp3_afh.c
ogg_afh.c
para.h
send_common.c
server.c
server.cmd
string.c
string.h

diff --cc Makefile.in
Simple merge
diff --cc aac_afh.c
+++ b/aac_afh.c
  
  /** \file aac_afh.c para_server's aac audio format handler */
  
+ #include <osl.h>
++
  #include "para.h"
  #include "error.h"
--#include "string.h"
  #include "afh.h"
--#include "afs.h"
--#include "server.h"
++#include "string.h"
  #include "aac.h"
  
  static int aac_find_stsz(unsigned char *buf, size_t buflen, off_t *skip)
diff --cc afs.c
--- 1/afs.c
--- 2/afs.c
+++ b/afs.c
@@@ -8,8 -8,7 +8,9 @@@
  
  #include <signal.h>
  #include <fnmatch.h>
 +#include <openssl/rc4.h>
+ #include <osl.h>
 +
  #include "server.cmdline.h"
  #include "para.h"
  #include "error.h"
diff --cc afs.cmd
+++ b/afs.cmd
@@@ -3,8 -3,8 +3,8 @@@ SF: afs.c aft.c attribute.
  HC: Prototypes for the commands of the audio file selector.
  CC: Array of commands for the audio file selector.
  AT: server_command
- SI: openssl/rc4
 -SI: osl
 -IN: para error string afh afs server list user_list
++SI: openssl/rc4 osl
 +IN: para error crypt command string afh afs server list user_list
  SN: list of afs commands
  TM: mood lyr img pl
  ---
diff --cc afs.h
--- 1/afs.h
--- 2/afs.h
+++ b/afs.h
@@@ -118,10 -117,7 +117,7 @@@ struct ls_data 
        HASH_TYPE *hash;
  };
  
- void make_empty_status_items(char *buf);
- /** At most that many bytes will be passed from afs to para_server. */
- #define VERBOSE_LS_OUTPUT_SIZE 4096
 -int send_afs_status(int fd, int parser_friendly);
++int send_afs_status(struct rc4_context *rc4c, int parser_friendly);
  
  /** Data about the current audio file, passed from afs to server. */
  struct audio_file_data {
diff --cc aft.c
--- 1/aft.c
--- 2/aft.c
+++ b/aft.c
@@@ -7,11 -7,9 +7,12 @@@
  /** \file aft.c Audio file table functions. */
  
  #include <dirent.h> /* readdir() */
 +#include <openssl/rc4.h>
 +
+ #include <osl.h>
  #include "para.h"
  #include "error.h"
 +#include "crypt.h"
  #include "string.h"
  #include <sys/mman.h>
  #include <fnmatch.h>
@@@ -805,26 -853,20 +858,25 @@@ static int print_list_item(struct ls_da
                goto out;
        }
        get_attribute_bitmap(&afsi->attributes, att_buf);
 -      ret = get_local_time(&afsi->last_played, last_played_time,
 -              sizeof(last_played_time), current_time, opts->mode);
 -      if (ret < 0)
 -              goto out;
 +      if (opts->flags & LS_FLAG_UNIXDATE)
 +              sprintf(last_played_time, "%llu",
 +                      (long long unsigned)afsi->last_played);
 +      else {
 +              ret = get_local_time(&afsi->last_played, last_played_time,
 +                      sizeof(last_played_time), current_time, opts->mode);
 +              if (ret < 0)
 +                      goto out;
 +      }
        get_duration_buf(afhi->seconds_total, duration_buf, opts);
-       if (have_score) {
-               if (opts->mode == LS_MODE_LONG)
-                       sprintf(score_buf, "%*li ", w->score_width, d->score);
-               else
-                       sprintf(score_buf, "%li ", d->score);
-       }
        if (opts->mode == LS_MODE_LONG) {
+               struct ls_widths *w = &opts->widths;
+               if (opts->flags & LS_FLAG_ADMISSIBLE_ONLY) {
+                       ret = para_printf(b, "%*li ",
+                               opts->widths.score_width, d->score);
+                       if (ret < 0)
+                               goto out;
+               }
                ret = para_printf(b,
-                       "%s"    /* score */
                        "%s "   /* attributes */
                        "%*u "  /* amp */
                        "%*d "  /* image_id  */
@@@ -2469,6 -2420,25 +2435,25 @@@ int com_cpsi(struct rc4_context *rc4c, 
        return ret;
  }
  
 -int send_afs_status(int fd, int parser_friendly)
+ void afs_stat_callback(int fd, const struct osl_object *query)
+ {
+       int *parser_friendly = query->data;
+       char *buf = *parser_friendly?
+               parser_friendly_status_items : status_items;
+       if (!buf)
+               return;
+       pass_buffer_as_shm(buf, strlen(buf), &fd);
+ }
 -      return send_callback_request(afs_stat_callback, &query, send_result, &fd);
++int send_afs_status(struct rc4_context *rc4c, int parser_friendly)
+ {
+       struct osl_object query = {.data = &parser_friendly,
+               .size = sizeof(parser_friendly)};
++      return send_callback_request(afs_stat_callback, &query, rc4_send_result, rc4c);
+ }
  /* TODO: optionally fix problems by removing offending rows */
  static int check_audio_file(struct osl_row *row, void *data)
  {
diff --cc attribute.c
@@@ -5,12 -5,9 +5,13 @@@
   */
  
  /** \file attribute.c Attribute handling functions. */
 +
 +#include <openssl/rc4.h>
+ #include <osl.h>
 +
  #include "para.h"
  #include "error.h"
 +#include "crypt.h"
  #include "string.h"
  #include "afh.h"
  #include "afs.h"
diff --cc audiod.c
Simple merge
diff --cc blob.c
--- 1/blob.c
--- 2/blob.c
+++ b/blob.c
@@@ -7,11 -7,9 +7,12 @@@
  /** \file blob.c Macros and functions for blob handling. */
  
  #include <fnmatch.h>
 +#include <openssl/rc4.h>
+ #include <osl.h>
 +
  #include "para.h"
  #include "error.h"
 +#include "crypt.h"
  #include "string.h"
  #include "afh.h"
  #include "afs.h"
diff --cc command.c
+++ b/command.c
@@@ -294,27 -290,109 +280,109 @@@ int com_version(struct rc4_context *rc4
        );
  }
  
+ #define EMPTY_STATUS_ITEMS \
+       ITEM(PATH) \
+       ITEM(DIRECTORY) \
+       ITEM(BASENAME) \
+       ITEM(SCORE) \
+       ITEM(ATTRIBUTES_BITMAP) \
+       ITEM(ATTRIBUTES_TXT) \
+       ITEM(HASH) \
+       ITEM(IMAGE_ID) \
+       ITEM(IMAGE_NAME) \
+       ITEM(LYRICS_ID) \
+       ITEM(LYRICS_NAME) \
+       ITEM(BITRATE) \
+       ITEM(FORMAT) \
+       ITEM(FREQUENCY) \
+       ITEM(CHANNELS) \
+       ITEM(DURATION) \
+       ITEM(SECONDS_TOTAL) \
+       ITEM(NUM_PLAYED) \
+       ITEM(LAST_PLAYED) \
+       ITEM(TECHINFO) \
+       ITEM(ARTIST) \
+       ITEM(TITLE) \
+       ITEM(YEAR) \
+       ITEM(ALBUM) \
+       ITEM(COMMENT) \
+       ITEM(AMPLIFICATION)
+ /**
+  * Write a list of audio-file related status items with empty values.
+  *
+  * This is used by vss when currently no audio file is open.
+  */
+ static char *empty_status_items(int parser_friendly)
+ {
+       if (parser_friendly)
+               return make_message(
+                       #define ITEM(x) "0004 %02x:\n"
+                       EMPTY_STATUS_ITEMS
+                       #undef ITEM
+                       #define ITEM(x) , SI_ ## x
+                       EMPTY_STATUS_ITEMS
+                       #undef ITEM
+               );
+       return make_message(
+               #define ITEM(x) "%s:\n"
+               EMPTY_STATUS_ITEMS
+               #undef ITEM
+               #define ITEM(x) ,status_item_list[SI_ ## x]
+               EMPTY_STATUS_ITEMS
+               #undef ITEM
+       );
+ }
+ #undef EMPTY_STATUS_ITEMS
  /* stat */
 -int com_stat(int fd, int argc, char * const * argv)
 +int com_stat(struct rc4_context *rc4c, int argc, char * const * argv)
  {
-       int ret, num = 0;/* status will be printed that many
-                         * times. num <= 0 means: print forever
-                         */
+       int i, ret;
        struct misc_meta_data tmp, *nmmd = &tmp;
        char *s;
+       int32_t num = 0;
+       int parser_friendly = 0;
  
        para_sigaction(SIGUSR1, dummy);
  
-       if (argc > 1)
-               num = atoi(argv[1]);
+       for (i = 1; i < argc; i++) {
+               const char *arg = argv[i];
+               if (arg[0] != '-')
+                       break;
+               if (!strcmp(arg, "--")) {
+                       i++;
+                       break;
+               }
+               if (!strncmp(arg, "-n=", 3)) {
+                       ret = para_atoi32(arg + 3, &num);
+                       if (ret < 0)
+                               return ret;
+                       continue;
+               }
+               if (!strcmp(arg, "-p")) {
+                       parser_friendly = 1;
+                       continue;
+               }
+       }
+       if (i != argc)
+               return -E_COMMAND_SYNTAX;
        for (;;) {
                mmd_dup(nmmd);
-               s = get_status(nmmd);
+               s = get_status(nmmd, parser_friendly);
 -              ret = send_buffer(fd, s);
 +              ret = rc4_send_buffer(rc4c, s);
                free(s);
                if (ret < 0)
                        goto out;
 -                      ret = send_buffer(fd, esi);
+               if (nmmd->vss_status_flags & VSS_NEXT) {
+                       static char *esi;
+                       if (!esi)
+                               esi = empty_status_items(parser_friendly);
 -                      send_afs_status(fd, parser_friendly);
++                      ret = rc4_send_buffer(rc4c, esi);
+                       if (ret < 0)
+                               goto out;
+               } else
++                      send_afs_status(rc4c, parser_friendly);
                ret = 1;
                if (num > 0 && !--num)
                        goto out;
diff --cc configure.ac
@@@ -138,13 -138,9 +138,10 @@@ writers=" file
  default_writer="FILE_WRITE"
  
  client_cmdline_objs="client.cmdline"
 -client_errlist_objs="client net string crypt fd sched stdin stdout client_common"
 +client_errlist_objs="client net string crypt fd sched stdin stdout
 +      client_common sha1"
  client_ldflags=""
  
- fsck_cmdline_objs="fsck.cmdline"
- fsck_errlist_objs="osl rbtree fsck string sha1 fd"
  gui_cmdline_objs="gui.cmdline"
  gui_errlist_objs="exec signal string stat ringbuffer fd"
  gui_other_objs="gui gui_theme"
diff --cc error.h
Simple merge
diff --cc mp3_afh.c
+++ b/mp3_afh.c
@@@ -20,8 -21,8 +21,6 @@@
  #include "error.h"
  #include "afh.h"
  #include "string.h"
--#include "afs.h"
--#include "server.h"
  
  /** \cond some defines and structs which are only used in this file */
  
diff --cc ogg_afh.c
+++ b/ogg_afh.c
@@@ -9,13 -9,14 +9,12 @@@
  #include <ogg/ogg.h>
  #include <vorbis/codec.h>
  #include <vorbis/vorbisfile.h>
+ #include <osl.h>
  
  #include "para.h"
--#include "afh.h"
  #include "error.h"
++#include "afh.h"
  #include "string.h"
--#include "afs.h"
--#include "server.h"
  
  /** must be big enough to hold header */
  #define CHUNK_SIZE 32768
diff --cc para.h
Simple merge
diff --cc send_common.c
Simple merge
diff --cc server.c
+++ b/server.c
@@@ -65,7 -63,7 +63,8 @@@
  #include <signal.h>
  #include <dirent.h>
  #include <sys/time.h>
 +#include <openssl/rc4.h>
+ #include <osl.h>
  
  #include "para.h"
  #include "error.h"
@@@ -374,15 -369,16 +371,15 @@@ static void command_post_select(struct 
        PARA_INFO_LOG("got connection from %s, forking\n", peer_name);
        mmd->num_connects++;
        mmd->active_connections++;
-       /* The chunk table and the info_string are pointers located in the
-        * mmd struct that point to dynamically allocated memory that must be
-        * freed by the parent and the child. However, as the mmd struct is in
-        * a shared memory area, there's no guarantee that after the fork these
-        * pointers are still valid in child context. As these two pointers are
-        * not used in the child anyway, we save them to local variables and
-        * free the memory via that copy in the child.
 -      random();
+       /*
 -       * The chunk table is a pointer located in the mmd struct that point to
 -       * dynamically allocated memory that must be freed by the parent and
 -       * the child. However, as the mmd struct is in a shared memory area,
 -       * there's no guarantee that after the fork these pointers are still
 -       * valid in child context. As this pointer is not used in the child
 -       * anyway, we save it to a local variable and free the memory via that
 -       * copy in the child.
++       * The chunk table is a pointer located in the mmd struct that points
++       * to dynamically allocated memory, i.e. it must be freed by the parent
++       * and the child. However, as the mmd struct is in a shared memory
++       * area, there's no guarantee that after the fork this pointer is still
++       * valid in child context. As it is not used in the child anyway, we
++       * save it to a local variable before the fork and free the memory via
++       * that copy in the child directly after the fork.
         */
-       info_string = mmd->afd.afhi.info_string;
        chunk_table = mmd->afd.afhi.chunk_table;
        child_pid = fork();
        if (child_pid < 0) {
diff --cc server.cmd
@@@ -3,8 -3,8 +3,8 @@@ SF: command.
  HC: prototypes for the server command handlers
  CC: array of server commands
  AT: server_command
- SI: openssl/rc4
 -IN: para error string afh afs server list user_list
 -SI: osl
++SI: openssl/rc4 osl
 +IN: para error crypt command string afh afs server list user_list
  SN: list of server commands
  ---
  N: ff
diff --cc string.c
Simple merge
diff --cc string.h
+++ b/string.h
@@@ -33,8 -63,9 +63,8 @@@ __must_check __malloc char *para_strdup
  __must_check __malloc __printf_1_2 char *make_message(const char *fmt, ...);
  __must_check __malloc char *para_strcat(char *a, const char *b);
  __must_check __malloc char *para_dirname(const char *name);
- __must_check const char *para_basename(const char *name);
+ __must_check char *para_basename(const char *name);
  void chop(char *buf);
 -__must_check __malloc char *para_tmpname(void);
  __must_check __malloc char *para_logname(void);
  __must_check __malloc char *para_homedir(void);
  unsigned split_args(char *args, char *** const argv_ptr, const char *delim);