comparison src/scrobbler/scrobbler.c @ 2315:8f3476f7a696

prevent segfault
author Tomasz Mon <desowin@gmail.com>
date Mon, 14 Jan 2008 19:20:57 +0100
parents 6eef090b5114
children 447dce6f59f3
comparison
equal deleted inserted replaced
2314:6eef090b5114 2315:8f3476f7a696
54 54
55 #define I_ARTIST(i) i->artist 55 #define I_ARTIST(i) i->artist
56 #define I_TITLE(i) i->title 56 #define I_TITLE(i) i->title
57 #define I_TIME(i) i->utctime 57 #define I_TIME(i) i->utctime
58 #define I_LEN(i) i->len 58 #define I_LEN(i) i->len
59 #define I_MB(i) i->mb
60 #define I_ALBUM(i) i->album 59 #define I_ALBUM(i) i->album
61 60
62 typedef struct { 61 typedef struct {
63 char *artist, 62 char *artist, *title, *album;
64 *title,
65 *mb,
66 *album;
67 int utctime, track, len; 63 int utctime, track, len;
68 int timeplayed; 64 int timeplayed;
69 int numtries; 65 int numtries;
70 void *next; 66 void *next;
71 } item_t; 67 } item_t;
72 68
73 static item_t *q_queue = NULL; 69 static item_t *q_queue = NULL;
124 { 120 {
125 if (item == NULL) 121 if (item == NULL)
126 return; 122 return;
127 curl_free(item->artist); 123 curl_free(item->artist);
128 curl_free(item->title); 124 curl_free(item->title);
129 curl_free(item->mb);
130 curl_free(item->album); 125 curl_free(item->album);
131 free(item); 126 free(item);
132 } 127 }
133 128
134 static item_t *q_put(Tuple *tuple, int t, int len) 129 static item_t *q_put(Tuple *tuple, int t, int len)
147 item->utctime = time(NULL); 142 item->utctime = time(NULL);
148 } else { /* item from queue */ 143 } else { /* item from queue */
149 item->timeplayed = len; 144 item->timeplayed = len;
150 item->utctime = t; 145 item->utctime = t;
151 } 146 }
152
153 #ifdef NOTYET
154 if(tuple->mb == NULL)
155 #endif
156 item->mb = fmt_escape("");
157 #ifdef NOTYET
158 else
159 item->mb = fmt_escape((char*)tuple->mb);
160 #endif
161 147
162 album = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL); 148 album = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL);
163 if (album) 149 if (album)
164 item->album = fmt_escape((char*) album); 150 item->album = fmt_escape((char*) album);
165 else 151 else
651 g_string_append(submission,sc_itemtag('l',i,tmp)); 637 g_string_append(submission,sc_itemtag('l',i,tmp));
652 g_free(tmp); 638 g_free(tmp);
653 tmp = g_strdup_printf("%d",I_TIME(item)); 639 tmp = g_strdup_printf("%d",I_TIME(item));
654 g_string_append(submission,sc_itemtag('i',i,tmp)); 640 g_string_append(submission,sc_itemtag('i',i,tmp));
655 g_free(tmp); 641 g_free(tmp);
656 g_string_append(submission,sc_itemtag('m',i,I_MB(item))); 642 g_string_append(submission,sc_itemtag('m',i,""));
657 g_string_append(submission,sc_itemtag('b',i,I_ALBUM(item))); 643 g_string_append(submission,sc_itemtag('b',i,I_ALBUM(item)));
658 g_string_append(submission,sc_itemtag('o',i,"P")); 644 g_string_append(submission,sc_itemtag('o',i,"P"));
659 tmp = g_strdup_printf("%d",item->track); 645 tmp = g_strdup_printf("%d",item->track);
660 g_string_append(submission,sc_itemtag('n',i,tmp)); 646 g_string_append(submission,sc_itemtag('n',i,tmp));
661 g_free(tmp); 647 g_free(tmp);
662 g_string_append(submission,sc_itemtag('r',i,"")); 648 g_string_append(submission,sc_itemtag('r',i,""));
663 649
664 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d m[%d]=%s b[%d]=%s", 650 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d b[%d]=%s",
665 i, I_ARTIST(item), 651 i, I_ARTIST(item),
666 i, I_TITLE(item), 652 i, I_TITLE(item),
667 i, I_LEN(item), 653 i, I_LEN(item),
668 i, I_TIME(item), 654 i, I_TIME(item),
669 i, I_MB(item),
670 i, I_ALBUM(item)), DEBUG); 655 i, I_ALBUM(item)), DEBUG);
671 #ifdef ALLOW_MULTIPLE 656 #ifdef ALLOW_MULTIPLE
672 i++; 657 i++;
673 } 658 }
674 #endif 659 #endif
901 g_free(string_value); 886 g_free(string_value);
902 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, track); 887 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, track);
903 item = q_put(tuple, t, len); 888 item = q_put(tuple, t, len);
904 889
905 aud_tuple_free(tuple); 890 aud_tuple_free(tuple);
891
892 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d b[%d]=%s",
893 i, I_ARTIST(item),
894 i, I_TITLE(item),
895 i, I_LEN(item),
896 i, I_TIME(item),
897 i, I_ALBUM(item)), DEBUG);
906 } 898 }
907 899
908 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%d i[%d]=%d m[%d]=%s b[%d]=%s",
909 i, I_ARTIST(item),
910 i, I_TITLE(item),
911 i, I_LEN(item),
912 i, I_TIME(item),
913 i, I_MB(item),
914 i, I_ALBUM(item)), DEBUG);
915 free(artist); 900 free(artist);
916 free(title); 901 free(title);
917 free(album); 902 free(album);
918 g_free(entry); 903 g_free(entry);
919 i++; 904 i++;