Subversion Repositories mdb

Rev

Rev 13 | Rev 18 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13 Rev 14
Line 45... Line 45...
45
int globalLine;
45
int globalLine;
46
int globalPos;
46
int globalPos;
47
 
47
 
48
static int listCallback(int s1, char *type, int line, sqlite3_stmt *res);
48
static int listCallback(int s1, char *type, int line, sqlite3_stmt *res);
49
static int folderCallback(void *hint, int argc, char **argv, char **azColName);
49
static int folderCallback(void *hint, int argc, char **argv, char **azColName);
-
 
50
int countPlaylists();
50
 
51
 
51
int listSongs(int s1, char *p_type, int start, int length)
52
int listSongs(int s1, char *p_type, int start, int length)
52
{
53
{
53
	char query[1024], hv0[128];
54
	char query[1024], hv0[128];
54
	char fname[256];
55
	char fname[256];
55
	sqlite3 *db;
56
	sqlite3 *db;
56
	sqlite3_stmt *res;
57
	sqlite3_stmt *res;
57
	char *zErrMsg = 0;
-
 
58
	int rc, pos, line;
58
	int rc, pos, line;
59
	struct callPars cp;
-
 
60
 
59
 
61
	strcpy(fname, configs.home);
60
	strcpy(fname, configs.home);
62
	strcat(fname, MUSICDB);
61
	strcat(fname, MUSICDB);
63
	
62
	
64
	rc = sqlite3_open(fname, &db);
63
	rc = sqlite3_open(fname, &db);
Line 70... Line 69...
70
		write (s1, query, strlen(query));
69
		write (s1, query, strlen(query));
71
		return FALSE;
70
		return FALSE;
72
	}
71
	}
73
	
72
	
74
	/* First count the future result set */
73
	/* First count the future result set */
75
	strcpy (query, "select count(*) as cnt from musicdb");
-
 
76
 
-
 
77
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
74
	if (strcmp(p_type, "QUEUE") && strcmp(p_type, "PLAYLIST"))
78
	{
75
	{
79
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
-
 
80
		strcpy(query, "ERROR:USER:Error preparing a SQL statement;");
76
		strcpy (query, "select count(*) as cnt from musicdb");
81
		write(s1, query, strlen(query));
-
 
82
		return FALSE;
-
 
83
	}
-
 
84
 
77
 
-
 
78
		if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
-
 
79
		{
-
 
80
			syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
-
 
81
			strcpy(query, "ERROR:USER:Error preparing a SQL statement;");
-
 
82
			write(s1, query, strlen(query));
-
 
83
			return FALSE;
-
 
84
		}
-
 
85
 
85
	if (sqlite3_step(res) == SQLITE_ROW)
86
		if (sqlite3_step(res) == SQLITE_ROW)
86
		pos = sqlite3_column_int(res, 0);
87
			pos = sqlite3_column_int(res, 0);
-
 
88
		else
-
 
89
			pos = 0;
-
 
90
 
-
 
91
		sqlite3_finalize(res);
-
 
92
	}
-
 
93
	else if (!strcmp(p_type, "QUEUE"))
-
 
94
		pos = queueTotal;
87
	else
95
	else
88
		pos = 0;
96
		pos = countPlaylists();
89
 
97
 
90
	sprintf(hv0, "TOTAL:%d;", pos);
98
	sprintf(hv0, "TOTAL:%d;", pos);
91
	write(s1, hv0, strlen(hv0));
99
	write(s1, hv0, strlen(hv0));
92
	sqlite3_finalize(res);
-
 
93
 
100
 
94
	strcpy (query, "select id, title, interpret, album, genre, cover from \"main\".\"musicdb\" ");
101
	strcpy (query, "select id, title, interpret, album, genre, cover from \"main\".\"musicdb\" ");
95
	strcat (query, "order by ");
102
	strcat (query, "order by ");
96
	
103
	
97
	if (strcmp(p_type, "TITLE") == 0)
104
	if (strcmp(p_type, "TITLE") == 0)
Line 321... Line 328...
321
	return TRUE;
328
	return TRUE;
322
}
329
}
323
 
330
 
324
static int listCallback(int s1, char *type, int line, sqlite3_stmt *res)
331
static int listCallback(int s1, char *type, int line, sqlite3_stmt *res)
325
{
332
{
326
	int i, id;
333
	int id;
327
	char id3_title[256], id3_artist[256], id3_album[256], id3_genre[256], id3_cover[256];
334
	char id3_title[256], id3_artist[256], id3_album[256], id3_genre[256], id3_cover[256];
328
	char buffer[8192];
335
	char buffer[8192];
329
	char *title, *artist, *album;
336
	char *title, *artist, *album;
330
 
337
 
331
	memset(id3_title, 0, sizeof(id3_title));
338
	memset(id3_title, 0, sizeof(id3_title));
Line 436... Line 443...
436
{
443
{
437
	char query[1024], hv0[128], field[32];
444
	char query[1024], hv0[128], field[32];
438
	char fname[256];
445
	char fname[256];
439
	sqlite3 *db;
446
	sqlite3 *db;
440
	sqlite3_stmt *res;
447
	sqlite3_stmt *res;
441
	char *zErrMsg = 0;
-
 
442
	int rc, pos, line;
448
	int rc, pos, line;
443
	struct callPars cp;
-
 
444
	
449
	
445
	strcpy(fname, configs.home);
450
	strcpy(fname, configs.home);
446
	strcat(fname, MUSICDB);
451
	strcat(fname, MUSICDB);
447
	
452
	
448
	if (!strcasecmp(p_type, "TITLE"))
453
	if (!strcasecmp(p_type, "TITLE"))
Line 522... Line 527...
522
	sqlite3_close(db);
527
	sqlite3_close(db);
523
	return TRUE;
528
	return TRUE;
524
}
529
}
525
 
530
 
526
/*
531
/*
-
 
532
 * Count the playlists of the users and return the result.
-
 
533
 */
-
 
534
int countPlaylists()
-
 
535
{
-
 
536
	USERS *act;
-
 
537
	int count;
-
 
538
	
-
 
539
	count = 0;
-
 
540
	act = userchain;
-
 
541
	
-
 
542
	while (act)
-
 
543
	{
-
 
544
		count++;
-
 
545
		act = act->next;
-
 
546
	}
-
 
547
	
-
 
548
	return count;
-
 
549
}
-
 
550
 
-
 
551
/*
527
 * List the playlists of the current user.
552
 * List the playlists of the current user.
528
 */
553
 */
529
int listPlaylists(int s1, int start, int length)
554
int listPlaylists(int s1, int start, int length)
530
{
555
{
531
	USERS *act;
556
	USERS *act;
Line 573... Line 598...
573
int listUserPlaylist(int s1, const char *user, const char *playlist, int start, int length)
598
int listUserPlaylist(int s1, const char *user, const char *playlist, int start, int length)
574
{
599
{
575
	char query[1024], hv0[128], buffer[8192];
600
	char query[1024], hv0[128], buffer[8192];
576
	char fname[256];
601
	char fname[256];
577
	sqlite3 *db;
602
	sqlite3 *db;
578
	char *zErrMsg = 0;
-
 
579
	int rc, id, total, pos, line;
603
	int rc, id, total, pos, line;
580
	sqlite3_stmt *res;
604
	sqlite3_stmt *res;
581
	char id3_title[256], id3_artist[256], id3_album[256], id3_genre[256], id3_cover[512];
605
	char id3_title[256], id3_artist[256], id3_album[256], id3_genre[256], id3_cover[512];
582
	char *title, *artist, *album, *cover, *t;
606
	char *title, *artist, *album, *cover;
583
	USERS *act;
607
	USERS *act;
584
 
608
 
585
	if (playlist == NULL)
609
	if (playlist == NULL)
586
	{
610
	{
587
		strcpy(hv0, "ERROR:LIST:Missing name of playlist;");
611
		strcpy(hv0, "ERROR:LIST:Missing name of playlist;");
Line 627... Line 651...
627
		syslog(LOG_WARNING, "Error opening database %s: %s", fname, sqlite3_errmsg(db));
651
		syslog(LOG_WARNING, "Error opening database %s: %s", fname, sqlite3_errmsg(db));
628
		strcpy(query, "ERROR:USER:Error opening database;");
652
		strcpy(query, "ERROR:USER:Error opening database;");
629
		write (s1, query, strlen(query));
653
		write (s1, query, strlen(query));
630
		return FALSE;
654
		return FALSE;
631
	}
655
	}
-
 
656
 
-
 
657
	sprintf(query, "select count(*) from musicdb as a where (select musicid from playlist as b where a.id = b.musicid and b.userid = %d)", act->id);
-
 
658
	
-
 
659
	if (sqlite3_prepare(db, query, -1, &res, NULL) != SQLITE_OK)
-
 
660
	{
-
 
661
		syslog(LOG_DAEMON, "Error preparing SQL statement [%s]: %s", query, sqlite3_errmsg(db));
-
 
662
		strcpy(hv0, "ERROR:USER:Error preparing a SQL statement;");
-
 
663
		write(s1, hv0, strlen(hv0));
-
 
664
		return FALSE;
-
 
665
	}
632
	
666
	
-
 
667
	if ((rc = sqlite3_step(res)) == SQLITE_ROW)
-
 
668
	{
-
 
669
		total = sqlite3_column_int(res, 0);
-
 
670
		sprintf(hv0, "TOTAL:%d;", total);
-
 
671
		write (s1, hv0, strlen(hv0));
-
 
672
	}
-
 
673
 
-
 
674
	sqlite3_finalize(res);
633
	strcpy (query, "select id, title, interpret, album, genre, cover from musicdb as a where ");
675
	strcpy (query, "select id, title, interpret, album, genre, cover from musicdb as a where ");
634
	strcat (query, "(select musicid from playlists as b where a.id = b.musicid and b.userid = ");
676
	strcat (query, "(select musicid from playlists as b where a.id = b.musicid and b.userid = ");
635
	sprintf(hv0, "%d", act->id);
677
	sprintf(hv0, "%d", act->id);
636
	strcat (query, hv0);
678
	strcat (query, hv0);
637
	strcat (query, ")");
679
	strcat (query, ")");
Line 642... Line 684...
642
		strcpy(hv0, "ERROR:USER:Error preparing a SQL statement;");
684
		strcpy(hv0, "ERROR:USER:Error preparing a SQL statement;");
643
		write(s1, hv0, strlen(hv0));
685
		write(s1, hv0, strlen(hv0));
644
		return FALSE;
686
		return FALSE;
645
	}
687
	}
646
 
688
 
647
	total = sqlite3_column_count(res);
-
 
648
	sprintf(hv0, "TOTAL:%d;", total);
-
 
649
	write (s1, hv0, strlen(hv0));
-
 
650
	pos = 1;
689
	pos = 1;
651
	line = 0;
690
	line = 0;
652
	
691
	
653
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
692
	while ((rc = sqlite3_step(res)) == SQLITE_ROW)
654
	{
693
	{