On Tue, Aug 15, 2006, Keith Bennett wrote:
> My preference is to keep them separate. I find it easier reading
> through patches when they deal with one specific issue. Not that
> I always keep to this rule myself, but since they were separate
> patches to begin with then I would rather that they stayed
> separate.
> 
> I'll re-send the tags patch this evening and then all you have
> to do is diff your current tree with the repository.

Here is the tags patch against the current repository.

Keith.
# HG changeset patch
# User Keith Bennett <[EMAIL PROTECTED]>
# Node ID 280a449ed9d4f640c3cadb56b754ab3baf90a86f
# Parent  8f8416b88774ddfeeda03a8a7750316132fb48e8
Added lk_rio_update_props_from_tags() call so that lkarmafs can
update a files properties based on its tags.

diff -r 8f8416b88774 -r 280a449ed9d4 src/karma.c
--- a/src/karma.c       Tue Aug 15 13:26:03 2006
+++ b/src/karma.c       Tue Aug 15 17:06:16 2006
@@ -58,6 +58,7 @@
     set_usb_ptr(load_database),
     set_unimpl_cast(update_database, void (*)()),
     set_usb_ptr(write_smalldb),
+    set_usb_ptr(fidToPath),
 };
 
 static struct lk_ops lan_ops = 
@@ -86,6 +87,7 @@
     set_lan_ptr(load_database),
     set_lan_ptr(update_database),
     set_lan_ptr(write_smalldb),
+    set_lan_ptr(fidToPath),
 };
 
 struct lk_ops *lk_ops;
@@ -98,6 +100,11 @@
 int lk_karma_write_smalldb(void)
 {
     return lk_ops->lk_karma_write_smalldb();
+}
+
+char *lk_karma_fidToPath(int rio, uint32_t file_id)
+{
+    return lk_ops->lk_karma_fidToPath(rio, file_id);
 }
 
 /* -------------------------------------------------------------------------- 
*/
diff -r 8f8416b88774 -r 280a449ed9d4 src/karma.h
--- a/src/karma.h       Tue Aug 15 13:26:03 2006
+++ b/src/karma.h       Tue Aug 15 17:06:16 2006
@@ -17,6 +17,8 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+
+char *lk_karma_fidToPath(int rio, uint32_t file_id);
 
 /*Help-Functions:*/
 int      lk_karma_send_request           (int rio, uint32_t identifier,
@@ -76,6 +78,7 @@
     void (*lk_karma_load_database)(int rio);
     void (*lk_karma_update_database)(int rio);
     int (*lk_karma_write_smalldb)(void);
+    char *(*lk_karma_fidToPath)(int rio, uint32_t file_id);
 };
 
 #ifdef __cplusplus
diff -r 8f8416b88774 -r 280a449ed9d4 src/karmaLan.c
--- a/src/karmaLan.c    Tue Aug 15 13:26:03 2006
+++ b/src/karmaLan.c    Tue Aug 15 17:06:16 2006
@@ -33,6 +33,11 @@
 static int32_t recv_status(int rio);
 static int32_t recv_properties(int rio, uint32_t identifier, uint32_t r_id,
                                char ** properties);
+
+char *lk_karmaLan_fidToPath(int rio, uint32_t file_id)
+{
+    return NULL;
+}
 
 /* 
   Help-Functions
diff -r 8f8416b88774 -r 280a449ed9d4 src/karmaLan.h
--- a/src/karmaLan.h    Tue Aug 15 13:26:03 2006
+++ b/src/karmaLan.h    Tue Aug 15 17:06:16 2006
@@ -45,6 +45,8 @@
 #define FORMAT_STORAGE         18
 #define HANGUP                 19
 #define DEVICE_OPERATION       20
+
+char *lk_karmaLan_fidToPath(int rio, uint32_t file_id);
 
 /*Help-Functions:*/
 int      lk_karmaLan_connect                (char *ip);
diff -r 8f8416b88774 -r 280a449ed9d4 src/karmaUsb.c
--- a/src/karmaUsb.c    Tue Aug 15 13:26:03 2006
+++ b/src/karmaUsb.c    Tue Aug 15 17:06:16 2006
@@ -40,7 +40,7 @@
 /* -------------------------------------------------------------------------- 
*/
 /* Auxiliary Function */
 /* -------------------------------------------------------------------------- 
*/
-static char *fidToPath(int rio, uint32_t file_id)
+char *lk_karmaUsb_fidToPath(int rio, uint32_t file_id)
 {
     int i, len;
     char *path = NULL;
@@ -592,7 +592,7 @@
 
     /* The first entry is always the fid */
     fid = atoi(&props[4]);
-    unlink(fidToPath(0, fid));
+    unlink(lk_karmaUsb_fidToPath(0, fid));
 }
 
 static int32_t read_properties_smalldb(char **properties)
@@ -772,7 +772,7 @@
     int res;
     char *path = NULL;
 
-    path = fidToPath(rio, file_id);
+    path = lk_karmaUsb_fidToPath(rio, file_id);
     fd = open(path, O_RDONLY);
     free(path);
 /*
@@ -811,7 +811,7 @@
     int res, ret;
     char *path = NULL;
 
-    path = fidToPath(rio, file_id);
+    path = lk_karmaUsb_fidToPath(rio, file_id);
 /*
     if(offset==0)
         fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id);
@@ -863,7 +863,7 @@
         return -1;
     }
 
-    path = fidToPath(rio, file_id);
+    path = lk_karmaUsb_fidToPath(rio, file_id);
     path[strlen(path) - 1] = '1';
 /*  fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id); */
 
@@ -906,7 +906,7 @@
     int ret = 0;
     char *path = NULL;
 
-    path = fidToPath(rio, file_id);
+    path = lk_karmaUsb_fidToPath(rio, file_id);
 /*  fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id); */
     if(unlink(path))
         ret = -1;
diff -r 8f8416b88774 -r 280a449ed9d4 src/karmaUsb.h
--- a/src/karmaUsb.h    Tue Aug 15 13:26:03 2006
+++ b/src/karmaUsb.h    Tue Aug 15 17:06:16 2006
@@ -17,6 +17,7 @@
 extern "C" {
 #endif
 
+char *lk_karmaUsb_fidToPath(int rio, uint32_t file_id);
 
 /*Help-Functions:*/
 int      lk_karmaUsb_connect                (char *ip);
diff -r 8f8416b88774 -r 280a449ed9d4 src/lkarma.h
--- a/src/lkarma.h      Tue Aug 15 13:26:03 2006
+++ b/src/lkarma.h      Tue Aug 15 17:06:16 2006
@@ -177,6 +177,7 @@
 int lk_synchronize_necessary(int rio);
 uint32_t lk_rio_write(int rio, const char * filename);
 void lk_karma_write_dupes(int set);
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname);
 
 
 /*
diff -r 8f8416b88774 -r 280a449ed9d4 src/rio_rw.c
--- a/src/rio_rw.c      Tue Aug 15 13:26:03 2006
+++ b/src/rio_rw.c      Tue Aug 15 17:06:16 2006
@@ -24,6 +24,7 @@
 #include "wav.h"
 
 #include "lkarma.h"
+#include "karma.h"
 #include "properties.h"
 #include "util.h"
 #include "rio_rw.h"
@@ -44,7 +45,7 @@
 static int get_taxi_props(HASH *p);
 static int get_wave_props(HASH *p, const char *filename);
 static void add_tag(HASH *p, char *key, char *value);
-static void set_tag_props(HASH *p, const char *filename);
+static void set_tag_props(HASH *p, const char *filename, int type);
 static int get_file_type(mp3info *mp3);
 
 int lk_synchronize_necessary(int rio)
@@ -128,29 +129,29 @@
     return 0;
 }
 
-/*
-     To use that function properly:
-         1. Get an IO Lock for Writing
-         2. call synchronize_necessary 
-            and synchronize the properties if necessary ;)
-         3. use rio_write as often as you need to :)
-         4. release the IO Lock.
-*/
-uint32_t lk_rio_write(int rio, const char * filename)
-{
-    int got=-1,fd;
-    uint32_t new_fid;
-    uint64_t offs=0;
-    const uint64_t siz=BLOCKSIZE;
-    char * p, tmp[BLOCKSIZE], *rid;
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
+{
+    int got=-1, usb=0;
+    char *rid, *filename;
     struct stat len;
     HASH * props;
     int type, rid_fd;
     mp3info mp3;
     uint32_t *fids;
 
-    if(lstat(filename, &len)==-1)
+    if (fname == NULL) {
+        filename = lk_karma_fidToPath(rio, fid);
+        usb = 1;
+    } else
+        filename = (char*)fname;
+
+    if(lstat(filename, &len)==-1) {
+        if (usb) {
+            unlink(filename);
+            free(filename);
+        }
         return -1;
+    }
 
     memset(&mp3, 0, sizeof(mp3info));
     mp3.filename = (char*)filename;
@@ -164,6 +165,10 @@
         fids = lk_properties_andOrSearch(EXACT|ORS, NULL, "rid", rid);
 
         if (fids != NULL) {
+            if (usb) {
+                unlink(filename);
+                free(filename);
+            }
             free(fids);
             lk_errors_set(E_DUPE);
             return -1;
@@ -174,6 +179,10 @@
     /* uses lk_properties_getnextfid()...*/
     props=lk_properties_idsearch(new_fid);
     if(props==NULL){
+        if (usb) {
+            unlink(filename);
+            free(filename);
+        }
         printf("huh, no hash found?\n");
         return -1;
     }
@@ -197,33 +206,64 @@
     else
         got=get_taxi_props(props);
 
-    if(got==0){
-        fd=open(filename, O_RDONLY);
-        while((got=read(fd, &tmp, siz)) > 0){
-            /*
-            if(got < siz) 
-                memset(&tmp[got], 0, (siz-got)%4);
-            if(lk_karma_write_file_chunk(rio, offs, got+((siz-got)%4),
-                                         new_fid, 0, tmp) != 0)
-            */
-            if(lk_karma_write_file_chunk(rio, offs, got, new_fid, 0, tmp)!=0) {
-                printf("lk_karma_write_file_chunk: %u of %llu\n", got, siz);
-                lk_properties_del_property(new_fid);
-                return -1;
-            }
-            offs+=got;
-        }
+    if (usb)
+        free(filename);
+
+    if (got != 0)
+        lk_properties_del_property(fid);
+
+    return got;
+}
+
+/*
+     To use that function properly:
+         1. Get an IO Lock for Writing
+         2. call synchronize_necessary 
+            and synchronize the properties if necessary ;)
+         3. use rio_write as often as you need to :)
+         4. release the IO Lock.
+*/
+uint32_t lk_rio_write(int rio, const char * filename)
+{
+    int got, fd;
+    uint32_t fid;
+    uint64_t offs=0;
+    char *p, tmp[BLOCKSIZE];
+    const uint64_t siz=BLOCKSIZE;
+
+    fd=open(filename, O_RDONLY);
+    if (fd == -1)
+        return -1;
+
+    fid = lk_properties_new_property(); 
+    got = lk_rio_update_props_from_tags(rio, fid, filename);
+
+    if (got != 0) {
         close(fd);
-        
-        p=lk_properties_export(new_fid);
-        got=lk_karma_update_file_details(rio, new_fid, p);
-        free(p);
-/*      return got; */
-        return new_fid;
-    }else{
-        lk_properties_del_property(new_fid);
         return -1;
     }
+
+    while((got=read(fd, &tmp, siz)) > 0){
+        /*
+        if(got < siz) 
+            memset(&tmp[got], 0, (siz-got)%4);
+        if(lk_karma_write_file_chunk(rio, offs, got+((siz-got)%4),
+                                     fid, 0, tmp) != 0)
+        */
+        if(lk_karma_write_file_chunk(rio, offs, got, fid, 0, tmp)!=0) {
+            printf("lk_karma_write_file_chunk: %u of %llu\n", got, siz);
+            lk_properties_del_property(fid);
+            return -1;
+        }
+        offs+=got;
+    }
+    close(fd);
+
+    p=lk_properties_export(fid);
+    got=lk_karma_update_file_details(rio, fid, p);
+    free(p);
+
+    return fid;
 }
 
 static void add_general(HASH * p, const char *filename)
@@ -252,7 +292,7 @@
     lk_properties_set_property_hash(p, "codec", "vorbis");
     lk_properties_set_property_hash(p, "type", "tune");
     
-    set_tag_props(p, filename);
+    set_tag_props(p, filename, TagLib_File_OggVorbis);
     return 0;
 }
 
@@ -265,7 +305,7 @@
     lk_properties_set_property_hash(p, "codec", "flac");
     lk_properties_set_property_hash(p, "type", "tune");
     
-    set_tag_props(p, filename);
+    set_tag_props(p, filename, TagLib_File_FLAC);
     return 0;
 }
 
@@ -279,7 +319,7 @@
     lk_properties_set_property_hash(p, "artist", NOT_TAGGED);
     lk_properties_set_property_hash(p, "source", NOT_TAGGED);
     
-    set_tag_props(p, mp3->filename);
+    set_tag_props(p, mp3->filename, TagLib_File_MPEG);
     
     if(!mp3->vbr){
         strcpy(bitrate, "fs");
@@ -341,7 +381,7 @@
 
 /*** You can use this with all tag-formats, which taglib supports.
   */
-static void set_tag_props(HASH *p, const char *filename)
+static void set_tag_props(HASH *p, const char *filename, int type)
 {
     TagLib_File *tl_file;
     TagLib_Tag *tl_tag;
@@ -349,7 +389,7 @@
     int i;
     char bitrate[6];
 
-    tl_file = taglib_file_new(filename);
+    tl_file = taglib_file_new_type(filename, type);
     tl_tag = taglib_file_tag(tl_file);
     tl_audio = taglib_file_audioproperties(tl_file);
 
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-karma-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-karma-devel

Reply via email to