]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Get rid of mmd->filename.
authorAndre Noll <maan@systemlinux.org>
Tue, 23 Oct 2007 21:36:40 +0000 (23:36 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 23 Oct 2007 21:36:40 +0000 (23:36 +0200)
The info is also contained in afd, but this was a pointer to data in
the shared memory area. We must copy into the static mmd buffer anyway,
since com_stat() must be able to see it. So make afd.path a static
array rather than a pointer and use afd->path instead of mmd->filename.
This simplifies save_afd() and load_afd() a bit since now only the
chunk table is of variable length.

afs.h
aft.c
command.c
server.c
server.h
vss.c

diff --git a/afs.h b/afs.h
index a4624ba2b9d0a8a5a994e52695c14ecb9fd2f8f8..b5e9d56b2764e4befd5573f7d7c84062fab2df7a 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -73,11 +73,11 @@ enum play_mode {PLAY_MODE_MOOD, PLAY_MODE_PLAYLIST};
 struct audio_file_data {
        enum play_mode current_play_mode;
        char attributes_string[MAXLINE];
+       char path[_POSIX_PATH_MAX];
        int fd;
        long score;
        struct afs_info afsi;
        struct audio_format_info afhi;
-       char *path;
 };
 
 enum afs_server_code {
diff --git a/aft.c b/aft.c
index f81c48569d23a83c6e863f7b23e1d72e7f137926..d0580bba8a5fa3c271c0119d368794c09b7c81b3 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -524,7 +524,10 @@ int get_afsi_of_path(const char *path, struct afs_info *afsi)
  * \param row Pointer to a row in the audio file table.
  * \param path Result pointer.
  *
- * \return Positive on success, negative on errors.
+ * The result is a pointer to mmapped data. The caller must not attempt
+ * to free it.
+ *
+ * \return Standard.
  */
 int get_audio_file_path_of_row(const struct osl_row *row, char **path)
 {
@@ -598,8 +601,7 @@ int get_afhi_of_row(const struct osl_row *row, struct audio_format_info *afhi)
 /* returns shmid on success */
 static int save_afd(struct audio_file_data *afd)
 {
-       size_t path_size = strlen(afd->path) + 1;
-       size_t size = sizeof(*afd) + path_size
+       size_t size = sizeof(*afd)
                + 4 * (afd->afhi.chunks_total + 1);
 
        PARA_NOTICE_LOG("size: %zu\n", size);
@@ -616,8 +618,6 @@ static int save_afd(struct audio_file_data *afd)
        *(struct audio_file_data *)shm_afd = *afd;
        buf = shm_afd;
        buf += sizeof(*afd);
-       strcpy(buf, afd->path);
-       buf += path_size;
        save_chunk_table(&afd->afhi, buf);
        shm_detach(shm_afd);
        return shmid;
@@ -638,8 +638,6 @@ int load_afd(int shmid, struct audio_file_data *afd)
        *afd = *(struct audio_file_data *)shm_afd;
        buf = shm_afd;
        buf += sizeof(*afd);
-       afd->path = para_strdup(buf);
-       buf += strlen(buf) + 1;
        afd->afhi.chunk_table = para_malloc((afd->afhi.chunks_total + 1) * 4);
        load_chunk_table(&afd->afhi, buf);
        shm_detach(shm_afd);
@@ -666,13 +664,15 @@ int open_and_update_audio_file(struct osl_row *aft_row, struct audio_file_data *
        int ret = get_hash_of_row(aft_row, &aft_hash);
        struct afsi_change_event_data aced;
        struct osl_object map, chunk_table_obj;
-       char *tmp;
+       char *tmp, *path;
 
        if (ret < 0)
                return ret;
-       ret = get_audio_file_path_of_row(aft_row, &afd->path);
+       ret = get_audio_file_path_of_row(aft_row, &path);
        if (ret < 0)
                return ret;
+       strncpy(afd->path, path, sizeof(afd->path) - 1);
+       afd->path[sizeof(afd->path) - 1] = '\0';
        ret = get_afsi_object_of_row(aft_row, &afsi_obj);
        if (ret < 0)
                return ret;
@@ -686,7 +686,7 @@ int open_and_update_audio_file(struct osl_row *aft_row, struct audio_file_data *
                AFTCOL_CHUNKS, &chunk_table_obj);
        if (ret < 0)
                return ret;
-       ret = mmap_full_file(afd->path, O_RDONLY, &map.data,
+       ret = mmap_full_file(path, O_RDONLY, &map.data,
                &map.size, &afd->fd);
        if (ret < 0)
                goto err;
@@ -711,6 +711,7 @@ int open_and_update_audio_file(struct osl_row *aft_row, struct audio_file_data *
        tmp[sizeof(afd->attributes_string) - 1] = '\0';
        strcpy(afd->attributes_string, tmp); /* OK */
        free(tmp);
+
        aced.aft_row = aft_row;
        aced.old_afsi = &afd->afsi;
        afs_event(AFSI_CHANGE, NULL, &aced);
index 7962cc79d99926c5731981c80636c145d59b7c10..2ccbe394b7119f70d4baad1c77d52b300c85e818 100644 (file)
--- a/command.c
+++ b/command.c
@@ -109,8 +109,8 @@ static char *get_status(struct misc_meta_data *nmmd)
        /* report real status */
        status = vss_status_tohuman(nmmd->vss_status_flags);
        flags = vss_get_status_flags(nmmd->vss_status_flags);
-       basename = para_basename(nmmd->filename);
-       dirname = para_dirname(nmmd->filename);
+       basename = para_basename(nmmd->afd.path);
+       dirname = para_dirname(nmmd->afd.path);
        gettimeofday(&now, NULL);
        ret = make_message(
                "%s:%zu\n"      "%s:%s\n"               "%s:%lu\n"      "%s:%u\n"
index 005a29b63219e20f8c78a57f279cd42403bc7bd7..c7760de1167e56bc1388f05da46aeb2d2999944e 100644 (file)
--- a/server.c
+++ b/server.c
@@ -152,7 +152,7 @@ static void shm_init(void)
        mmd->events = 0;
        mmd->num_connects = 0;
        mmd->active_connections = 0;
-       strcpy(mmd->filename, "(none)");
+       strcpy(mmd->afd.path, "(none)");
        mmd->vss_status_flags = VSS_NEXT;
        mmd->new_vss_status_flags = VSS_NEXT;
        mmd->sender_cmd_data.cmd_num = -1;
index 5e049179c37c96a406d4504767705c1a9925cd73..a83aaae29aa59362f9665c08c1abcb899cbfdb6c 100644 (file)
--- a/server.h
+++ b/server.h
@@ -61,8 +61,6 @@ struct sender_command_data{
 struct misc_meta_data {
        /** the size of the current audio file in bytes */
        size_t size;
-       /** the full path of the current audio file */
-       char filename[_POSIX_PATH_MAX];
        /** the last modification time of the current audio file */
        time_t mtime;
        /** the "old" status flags -- commands may only read them */
diff --git a/vss.c b/vss.c
index 27520ded29a8a4c8c330269c9f0b9b9a775844f9..c676ead505671f1a145f950620742a299a594fb6 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -201,7 +201,7 @@ static void vss_eof(void)
                status_item_list[SI_AUDIO_INFO2], status_item_list[SI_AUDIO_INFO3]);
        strcpy(mmd->afd.afhi.info_string, tmp);
        free(tmp);
-       mmd->filename[0] = '\0';
+       mmd->afd.path[0] = '\0';
        mmd->size = 0;
        mmd->events++;
 }
@@ -391,7 +391,6 @@ static void recv_afs_result(void)
        map = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE,
                passed_fd, 0);
        close(passed_fd);
-       strcpy(mmd->filename, mmd->afd.path); /* FIXME: check length */
        mmd->afd.afhi.header_len = 0; /* default: no header */
        mmd->chunks_sent = 0;
        mmd->current_chunk = 0;