Commit | Line | Data |
---|---|---|
448d3570 RK |
1 | /* |
2 | * This file is part of DisOrder. | |
3 | * Copyright (C) 2004-2008 Richard Kettlewell | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
18 | * USA | |
19 | */ | |
1e97629d RK |
20 | /** @file server/lookup.c |
21 | * @brief Server lookups | |
448d3570 | 22 | * |
1e97629d | 23 | * To improve performance many server lookups are cached. |
448d3570 | 24 | */ |
1e97629d RK |
25 | |
26 | #include "disorder-cgi.h" | |
448d3570 RK |
27 | |
28 | /** @brief Cached data */ | |
29 | static unsigned flags; | |
30 | ||
1e97629d RK |
31 | struct queue_entry *dcgi_queue; |
32 | struct queue_entry *dcgi_playing; | |
33 | struct queue_entry *dcgi_recent; | |
448d3570 | 34 | |
1e97629d RK |
35 | int dcgi_volume_left; |
36 | int dcgi_volume_right; | |
448d3570 | 37 | |
1e97629d RK |
38 | char **dcgi_new; |
39 | int dcgi_nnew; | |
448d3570 | 40 | |
1e97629d | 41 | rights_type dcgi_rights; |
448d3570 | 42 | |
1e97629d RK |
43 | int dcgi_enabled; |
44 | int dcgi_random_enabled; | |
448d3570 RK |
45 | |
46 | /** @brief Fetch cachable data */ | |
1e97629d | 47 | void dcgi_lookup(unsigned want) { |
448d3570 RK |
48 | unsigned need = want ^ (flags & want); |
49 | struct queue_entry *r, *rnext; | |
1e97629d | 50 | #if 0 |
448d3570 | 51 | const char *dir, *re; |
1e97629d RK |
52 | #endif |
53 | char *rs; | |
448d3570 | 54 | |
1e97629d | 55 | if(!dcgi_client || !need) |
448d3570 | 56 | return; |
1e97629d RK |
57 | if(need & DCGI_QUEUE) |
58 | disorder_queue(dcgi_client, &dcgi_queue); | |
59 | if(need & DCGI_PLAYING) | |
60 | disorder_playing(dcgi_client, &dcgi_playing); | |
61 | if(need & DCGI_NEW) | |
62 | disorder_new_tracks(dcgi_client, &dcgi_new, &dcgi_nnew, 0); | |
63 | if(need & DCGI_RECENT) { | |
448d3570 | 64 | /* we need to reverse the order of the list */ |
1e97629d | 65 | disorder_recent(dcgi_client, &r); |
448d3570 RK |
66 | while(r) { |
67 | rnext = r->next; | |
1e97629d RK |
68 | r->next = dcgi_recent; |
69 | dcgi_recent = r; | |
448d3570 RK |
70 | r = rnext; |
71 | } | |
72 | } | |
1e97629d RK |
73 | if(need & DCGI_VOLUME) |
74 | disorder_get_volume(dcgi_client, | |
75 | &dcgi_volume_left, &dcgi_volume_right); | |
76 | #if 0 | |
77 | /* DCGI_FILES and DCGI_DIRS are looking obsolete now */ | |
78 | if(need & (DCGI_FILES|DCGI_DIRS)) { | |
448d3570 RK |
79 | if(!(dir = cgi_get("directory"))) |
80 | dir = ""; | |
81 | re = cgi_get("regexp"); | |
1e97629d RK |
82 | if(need & DCGI_DIRS) |
83 | if(disorder_directories(dcgi_client, dir, re, | |
448d3570 RK |
84 | &dirs, &ndirs)) |
85 | ndirs = 0; | |
1e97629d RK |
86 | if(need & DCGI_FILES) |
87 | if(disorder_files(dcgi_client, dir, re, | |
448d3570 RK |
88 | &files, &nfiles)) |
89 | nfiles = 0; | |
90 | } | |
1e97629d RK |
91 | #endif |
92 | if(need & DCGI_RIGHTS) { | |
93 | dcgi_rights = RIGHT_READ; /* fail-safe */ | |
94 | if(!disorder_userinfo(dcgi_client, disorder_user(dcgi_client), | |
95 | "rights", &rs)) | |
96 | parse_rights(rs, &dcgi_rights, 1); | |
448d3570 | 97 | } |
1e97629d RK |
98 | if(need & DCGI_ENABLED) |
99 | disorder_enabled(dcgi_client, &dcgi_enabled); | |
100 | if(need & DCGI_RANDOM_ENABLED) | |
101 | disorder_random_enabled(dcgi_client, &dcgi_random_enabled); | |
448d3570 RK |
102 | flags |= need; |
103 | } | |
104 | ||
1e97629d | 105 | void dcgi_lookup_reset(void) { |
71634563 RK |
106 | /* Forget everything we knew */ |
107 | flags = 0; | |
1e97629d RK |
108 | dcgi_recent = 0; |
109 | dcgi_queue = 0; | |
110 | dcgi_playing = 0; | |
111 | dcgi_rights = 0; | |
112 | dcgi_new = 0; | |
113 | dcgi_nnew = 0; | |
114 | dcgi_enabled = 0; | |
115 | dcgi_random_enabled = 0; | |
116 | dcgi_volume_left = dcgi_volume_right = 0; | |
71634563 RK |
117 | } |
118 | ||
119 | ||
448d3570 RK |
120 | /* |
121 | Local Variables: | |
122 | c-basic-offset:2 | |
123 | comment-column:40 | |
124 | fill-column:79 | |
125 | indent-tabs-mode:nil | |
126 | End: | |
127 | */ |