summaryrefslogtreecommitdiff
path: root/examples/sendtr.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sendtr.c')
-rwxr-xr-xexamples/sendtr.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/examples/sendtr.c b/examples/sendtr.c
index ef1f130..a608d15 100755
--- a/examples/sendtr.c
+++ b/examples/sendtr.c
@@ -186,6 +186,7 @@ int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa
{
char *filename, *parent;
char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
+ char *to_path_copy = NULL;
char num[80];
uint64_t filesize;
uint32_t parent_id = 0;
@@ -196,22 +197,28 @@ int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa
printf("Sending track %s to %s\n", from_path, to_path);
- parent = dirname(strdup(to_path));
- filename = basename(strdup(to_path));
+ to_path_copy = strdup(to_path);
+ parent = dirname(to_path_copy);
parent_id = parse_path (parent,files,folders);
if (parent_id == -1) {
+ free (to_path_copy);
printf("Parent folder could not be found, skipping\n");
return 1;
}
+ strcpy (to_path_copy,to_path);
+ filename = basename(to_path_copy);
if (stat(from_path, &sb) == -1) {
fprintf(stderr, "%s: ", from_path);
perror("stat");
+ free (to_path_copy);
return 1;
}
- if (!S_ISREG(sb.st_mode))
+ if (!S_ISREG(sb.st_mode)) {
+ free (to_path_copy);
return 0;
+ }
filesize = sb.st_size;
@@ -220,6 +227,7 @@ int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa
if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
LIBMTP_destroy_track_t(trackmeta);
+ free (to_path_copy);
return 1;
}
@@ -374,6 +382,7 @@ int sendtrack_function(char * from_path, char * to_path, char *partist, char *pa
LIBMTP_destroy_album_t(albuminfo);
LIBMTP_destroy_track_t(trackmeta);
+ free (to_path_copy);
return ret;
}
@@ -397,24 +406,31 @@ int sendtrack_command (int argc, char **argv) {
while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
switch (opt) {
case 't':
+ free (ptitle);
ptitle = strdup(optarg);
break;
case 'a':
+ free (partist);
partist = strdup(optarg);
break;
case 'A':
+ free (palbumartist);
palbumartist = strdup(optarg);
break;
case 'w':
+ free (pcomposer);
pcomposer = strdup(optarg);
break;
case 'l':
+ free (palbum);
palbum = strdup(optarg);
break;
case 'c':
+ free (pcodec);
pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
break;
case 'g':
+ free (pgenre);
pgenre = strdup(optarg);
break;
case 'n':
@@ -442,13 +458,12 @@ int sendtrack_command (int argc, char **argv) {
if ( argc != 2 ) {
printf("You need to pass a filename and destination.\n");
sendtrack_usage();
- return 0;
+ ret = 0;
+ } else {
+ checklang();
+ printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u,%d\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid, quiet);
+ ret = sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid, quiet);
}
-
- checklang();
-
- printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u,%d\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid, quiet);
- ret = sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid, quiet);
free (ptitle);
free (partist);
free (palbumartist);