* Update cache clients for a single cache-entry * Tasks: * - Set the client function (if not already set) * - Look if new data is available and pass it to client functions * - Remove clients when done * - Call redirect handler * * @return Cache entry, which may be NULL if it has been removed. * * TODO: Implement CA_Abort Op in client callback */
| 1173 | * TODO: Implement CA_Abort Op in client callback |
| 1174 | */ |
| 1175 | static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry) |
| 1176 | { |
| 1177 | uint_t i; |
| 1178 | int st; |
| 1179 | const char *Type; |
| 1180 | Dstr *data; |
| 1181 | CacheClient_t *Client; |
| 1182 | DilloWeb *ClientWeb; |
| 1183 | BrowserWindow *Client_bw = NULL; |
| 1184 | static bool_t Busy = FALSE; |
| 1185 | bool_t AbortEntry = FALSE; |
| 1186 | bool_t OfferDownload = FALSE; |
| 1187 | bool_t TypeMismatch = FALSE; |
| 1188 | |
| 1189 | if (Busy) |
| 1190 | MSG_ERR("FATAL!: >>>> Cache_process_queue Caught busy!!! <<<<\n"); |
| 1191 | if (!(entry->Flags & CA_GotHeader)) |
| 1192 | return entry; |
| 1193 | if (!(entry->Flags & CA_GotContentType)) { |
| 1194 | st = a_Misc_get_content_type_from_data( |
| 1195 | entry->Data->str, entry->Data->len, &Type); |
| 1196 | _MSG("Cache: detected Content-Type '%s'\n", Type); |
| 1197 | if (st == 0 || !(entry->Flags & CA_InProgress)) { |
| 1198 | if (a_Misc_content_type_check(entry->TypeHdr, Type) < 0) { |
| 1199 | MSG_HTTP("Content-Type '%s' doesn't match the real data.\n", |
| 1200 | entry->TypeHdr); |
| 1201 | TypeMismatch = TRUE; |
| 1202 | } |
| 1203 | entry->TypeDet = dStrdup(Type); |
| 1204 | entry->Flags |= CA_GotContentType; |
| 1205 | } else |
| 1206 | return entry; /* i.e., wait for more data */ |
| 1207 | } |
| 1208 | |
| 1209 | Busy = TRUE; |
| 1210 | for (i = 0; (Client = dList_nth_data(ClientQueue, i)); ++i) { |
| 1211 | if (Client->Url == entry->Url) { |
| 1212 | ClientWeb = Client->Web; /* It was a (void*) */ |
| 1213 | Client_bw = ClientWeb->bw; /* 'bw' in a local var */ |
| 1214 | |
| 1215 | if (ClientWeb->flags & WEB_RootUrl) { |
| 1216 | if (!(entry->Flags & CA_MsgErased)) { |
| 1217 | /* clear the "expecting for reply..." message */ |
| 1218 | a_UIcmd_set_msg(Client_bw, ""); |
| 1219 | entry->Flags |= CA_MsgErased; |
| 1220 | } |
| 1221 | if (TypeMismatch) { |
| 1222 | a_UIcmd_set_msg(Client_bw,"HTTP warning: Content-Type '%s' " |
| 1223 | "doesn't match the real data.", entry->TypeHdr); |
| 1224 | OfferDownload = TRUE; |
| 1225 | } |
| 1226 | if (entry->Flags & CA_Redirect) { |
| 1227 | if (!Client->Callback) { |
| 1228 | Client->Callback = Cache_null_client; |
| 1229 | Client_bw->redirect_level++; |
| 1230 | } |
| 1231 | } else { |
| 1232 | Client_bw->redirect_level = 0; |
no test coverage detected