Merge /home/maan/scm/paraslash.fml/paraslash
authorAndre <maan@meins.(none)>
Sat, 30 Sep 2006 19:44:23 +0000 (21:44 +0200)
committerAndre <maan@meins.(none)>
Sat, 30 Sep 2006 19:44:23 +0000 (21:44 +0200)
NEWS
afs.c
command.c
error.h
fd.c
fd.h
server.c
server.ggo

diff --git a/NEWS b/NEWS
index 162a8a7..377065a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,8 @@ until now for reasons beyond the scope of this changelog entry.
          and --with-mad-libs
        - some robustness fixes
        - dymamic audio format recognition for audiod
+       - para_server: new command line option: --autoplay_delay
+       - para_audiod: new command line option: --clock_diff_count
 
 ---------------------------------------
 0.2.13 (2006-07-14) "sonic convolution"
diff --git a/afs.c b/afs.c
index b9d2433..2d4184d 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -37,6 +37,7 @@ extern const char *status_item_list[];
 static struct timeval announce_tv;
 static struct timeval data_send_barrier;
 static struct timeval eof_barrier;
+static struct timeval autoplay_barrier;
 
 extern struct misc_meta_data *mmd;
 extern struct audio_file_selector selectors[];
@@ -166,6 +167,14 @@ void afs_init(void)
        }
        free(hn);
        free(home);
+       if (conf.autoplay_given) {
+               struct timeval now, tmp;
+               mmd->afs_status_flags |= AFS_PLAYING;
+               mmd->new_afs_status_flags |= AFS_PLAYING;
+               gettimeofday(&now, NULL);
+               ms2tv(conf.autoplay_delay_arg, &tmp);
+               tv_add(&now, &tmp, &autoplay_barrier);
+       }
 }
 
 static int get_file_info(int i)
@@ -325,6 +334,9 @@ static struct timeval *afs_compute_timeout(void)
                return &the_timeout;
        }
        gettimeofday(&now, NULL);
+       if (chk_barrier("autoplay_delay", &now, &autoplay_barrier,
+                       &the_timeout, 1) < 0)
+               return &the_timeout;
        if (chk_barrier("eof", &now, &eof_barrier, &the_timeout, 1) < 0)
                return &the_timeout;
        if (chk_barrier("data send", &now, &data_send_barrier,
index 55070a3..ad3f504 100644 (file)
--- a/command.c
+++ b/command.c
@@ -31,6 +31,7 @@
 #include "net.h"
 #include "daemon.h"
 #include "string.h"
+#include "fd.h"
 
 static RC4_KEY rc4_recv_key;
 static RC4_KEY rc4_send_key;
@@ -1011,51 +1012,48 @@ static int get_user(struct user *user) {
        char line[MAXLINE];
        /* keyword, user, key, perms */
        char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
-       int num;
+       int num, ret;
 
        file_ptr = open_user_list(user_list);
        if (!file_ptr)
                return -E_USERLIST;
-       while (fgets(line, MAXLINE, file_ptr)) {
-//             PARA_DEBUG_LOG("%s: Read line (%i bytes) "
-//                     "from config file\n", __func__, strlen(line));
+       for (;;) {
+               ret = para_fgets(line, MAXLINE, file_ptr);
+               if (ret < 0)
+                       PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+               if (ret <= 0)
+                       break;
                if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
                        continue;
-               if (!strcmp(w, "user") && !strcmp(user->name, n)) {
-                       PARA_DEBUG_LOG("found entry for %s\n", n);
-                       strcpy(user->name, n);
-                       strcpy(user->pubkey_file, k);
-                       user->perms = 0;
-                       char_ptr = p;
-                       num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
-                               tmp[0], tmp[1], tmp[2], tmp[3]);
-                       PARA_DEBUG_LOG("found %i perm entries\n",
-                               num);
-                       user->perms = 0;
-                       while (num > 0) {
-                               num--;
-                               //PARA_DEBUG_LOG("%s: tmp[%i]=%s\n", __func__,
-                               //      num, tmp[num]);
-                               if (!strcmp(tmp[num], "AFS_READ"))
-                                       user->perms =
-                                               user->perms | AFS_READ;
-                               else if (!strcmp(tmp[num], "AFS_WRITE"))
-                                       user->perms =
-                                               user->perms | AFS_WRITE;
-                               else if (!strcmp(tmp[num], "DB_READ"))
-                                       user->perms = user->perms | DB_READ;
-                               else if (!strcmp(tmp[num], "DB_WRITE"))
-                                       user->perms = user->perms | DB_WRITE;
-                               else /* unknown permission */
-                                       PARA_WARNING_LOG("unknown permission:"
-                                               "%s\n", tmp[num]);
-                       }
-                       fclose(file_ptr);
-                       return 1;
+               if (strcmp(w, "user") || strcmp(user->name, n))
+                       continue;
+               PARA_DEBUG_LOG("found entry for %s\n", n);
+               strcpy(user->name, n);
+               strcpy(user->pubkey_file, k);
+               user->perms = 0;
+               char_ptr = p;
+               num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
+                       tmp[0], tmp[1], tmp[2], tmp[3]);
+               PARA_DEBUG_LOG("found %i perm entries\n", num);
+               user->perms = 0;
+               while (num > 0) {
+                       num--;
+                       if (!strcmp(tmp[num], "AFS_READ"))
+                               user->perms = user->perms | AFS_READ;
+                       else if (!strcmp(tmp[num], "AFS_WRITE"))
+                               user->perms = user->perms | AFS_WRITE;
+                       else if (!strcmp(tmp[num], "DB_READ"))
+                               user->perms = user->perms | DB_READ;
+                       else if (!strcmp(tmp[num], "DB_WRITE"))
+                               user->perms = user->perms | DB_WRITE;
+                       else /* unknown permission */
+                               PARA_WARNING_LOG("unknown permission: %s\n",
+                                       tmp[num]);
                }
+               break;
        }
        fclose(file_ptr);
-       return 0;
+       return ret;
 }
 
 static void init_rc4_keys(void)
diff --git a/error.h b/error.h
index cb5e2b0..05efb79 100644 (file)
--- a/error.h
+++ b/error.h
@@ -396,6 +396,7 @@ extern const char **para_errlist[];
 #define FD_ERRORS \
        PARA_ERROR(F_GETFL, "failed to get fd flags"), \
        PARA_ERROR(F_SETFL, "failed to set fd flags"), \
+       PARA_ERROR(FGETS, "fgets error"), \
 
 
 #define WRITE_ERRORS \
diff --git a/fd.c b/fd.c
index dd07466..d53a3b4 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -140,3 +140,29 @@ __must_check int para_fread(void *dest, size_t nbytes, size_t nmemb, FILE *strea
                return 0;
        return -E_FREAD;
 }
+/**
+* paraslash's wrapper for fgets(3)  
+* \param line pointer to the buffer to store the line
+* \param size the size of the buffer given by \a line
+* \param f the stream to read from
+*
+* \return Unlike the standard fgets() function, an integer value
+* is returned. On success, this function returns 1. On errors, -E_FGETS
+* is returned. A zero return value indicates an end of file condition.
+*/
+__must_check int para_fgets(char *line, int size, FILE *f)
+{
+again:
+       if (fgets(line, size, f))
+               return 1;
+       if (feof(f))
+               return 0;
+       if (!ferror(f))
+               return -E_FGETS;
+       if (errno != EINTR) {
+               PARA_ERROR_LOG("%s\n", strerror(errno));
+               return -E_FGETS;
+       }
+       clearerr(f);
+       goto again;
+}
diff --git a/fd.h b/fd.h
index 46178bd..6cb3cba 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -23,4 +23,6 @@ int para_select(int n, fd_set *readfds, fd_set *writefds,
                struct timeval *timeout_tv);
 int mark_fd_nonblock(int fd);
 void para_fd_set(int fd, fd_set *fds, int *max_fileno);
-__must_check int para_fread(void *dest, size_t nbytes, size_t nmemb, FILE *stream);
+__must_check int para_fread(void *dest, size_t nbytes, size_t nmemb,
+               FILE *stream);
+__must_check int para_fgets(char *line, int size, FILE *f);
index ce56494..c7e6812 100644 (file)
--- a/server.c
+++ b/server.c
@@ -359,10 +359,6 @@ static unsigned do_inits(int argc, char **argv)
        /* init network socket */
        PARA_NOTICE_LOG("%s", "initializing tcp command socket\n");
        sockfd = init_network();
-       if (conf.autoplay_given) {
-               mmd->afs_status_flags |= AFS_PLAYING;
-               mmd->new_afs_status_flags |= AFS_PLAYING;
-       }
        PARA_NOTICE_LOG("%s", "init complete\n");
        return sockfd;
 }
index c524009..a32673d 100644 (file)
@@ -105,6 +105,15 @@ option "autoplay" a
 
        flag off
 
+option "autoplay_delay" -
+#~~~~~~~~~~~~~~~~~~~~~~~~
+"Time to wait before autoplay starts. Ignored if
+autoplay is off."
+       int typestr="milliseconds"
+       default="0"
+       optional
+
+
 option "announce_time" A
 #~~~~~~~~~~~~~~~~~~~~~~~