annotate src/capi.c @ 2102:e1973d1962c5

rm comment warning about (left|right)-tab
author corvid <corvid@lavabit.com>
date Tue, 21 Jun 2011 00:15:55 +0000
parents 4779a3d891a1
children 350af350b840
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: capi.c
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 19
diff changeset
4 * Copyright 2002-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 * Cache API
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 * This is the module that manages the cache and starts the CCC chains
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 * to get the requests served. Kind of a broker.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include <string.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include "capi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #include "IO/IO.h" /* for IORead &friends */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #include "IO/Url.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include "chain.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "nav.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "dpiapi.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 #include "uicmd.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #include "../dpip/dpip.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 /* for testing dpi chat */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 #include "bookmark.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 DilloUrl *url; /* local copy of web->url */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 void *bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 char *server;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 char *datastr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 int SockFD;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 int Flags;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 ChainLink *InfoSend;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 ChainLink *InfoRecv;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 int Ref;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 } capi_conn_t;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 /* Flags for conn */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 enum {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 PENDING = 1,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 TIMEOUT = 2, /* unused */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 ABORTED = 4
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 * Local data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 /* Data list for active dpi connections */
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
58 static Dlist *CapiConns; /* Data list for active connections; it holds
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
59 * pointers to capi_conn_t structures. */
1600
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
60 /* Last URL asked for view source */
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
61 static DilloUrl *CapiVsUrl = NULL;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 * Forward declarations
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 void a_Capi_ccc(int Op, int Branch, int Dir, ChainLink *Info,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 void *Data1, void *Data2);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 /* ------------------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 * Initialize capi&cache data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 void a_Capi_init(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 {
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
77 /* create an empty list */
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
78 CapiConns = dList_new(32);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
79 /* init cache */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 a_Cache_init();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 /* ------------------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 * Create a new connection data structure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 static capi_conn_t *
1570
f275bd2cdeed Implement the view source functionality as a dpi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1569
diff changeset
89 Capi_conn_new(const DilloUrl *url, void *bw, char *server, char *datastr)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 capi_conn_t *conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 conn = dNew(capi_conn_t, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 conn->url = url ? a_Url_dup(url) : NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 conn->bw = bw;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 conn->server = dStrdup(server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 conn->datastr = dStrdup(datastr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 conn->SockFD = -1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 conn->Flags = (strcmp(server, "http") != 0) ? PENDING : 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 conn->InfoSend = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 conn->InfoRecv = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 conn->Ref = 0; /* Reference count */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 return conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 /*
1277
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
107 * Validate a capi_conn_t pointer.
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
108 * Return value: NULL if not valid, conn otherwise.
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
109 */
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
110 static capi_conn_t *Capi_conn_valid(capi_conn_t *conn)
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
111 {
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
112 return dList_find(CapiConns, conn);
1277
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
113 }
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
114
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
115 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 * Increment the reference count and add to the list if not present
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118 static void Capi_conn_ref(capi_conn_t *conn)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 if (++conn->Ref == 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 /* add the connection data to list */
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
122 dList_append(CapiConns, (void *)conn);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 _MSG(" Capi_conn_ref #%d %p\n", conn->Ref, conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 * Decrement the reference count (and remove from list when zero)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 static void Capi_conn_unref(capi_conn_t *conn)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 _MSG(" Capi_conn_unref #%d %p\n", conn->Ref - 1, conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
134 /* We may validate conn here, but it doesn't *seem* necessary */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 if (--conn->Ref == 0) {
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
136 /* remove conn preserving the list order */
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
137 dList_remove(CapiConns, (void *)conn);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
138 /* free dynamic memory */
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
139 a_Url_free(conn->url);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
140 dFree(conn->server);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
141 dFree(conn->datastr);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
142 dFree(conn);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 }
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
144 _MSG(" Capi_conn_unref CapiConns=%d\n", dList_length(CapiConns));
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
145 }
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
146
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
147 /*
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
148 * Compare function for searching a conn by server string
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
149 */
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
150 static int Capi_conn_by_server_cmp(const void *v1, const void *v2)
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
151 {
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
152 const capi_conn_t *node = v1;
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
153 const char *server = v2;
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
154 dReturn_val_if_fail(node && node->server && server, 1);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
155 return strcmp(node->server, server);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 * Find connection data by server
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 static capi_conn_t *Capi_conn_find(char *server)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 {
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
163 return dList_find_custom(CapiConns, (void*)server, Capi_conn_by_server_cmp);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167 * Resume connections that were waiting for dpid to start.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169 static void Capi_conn_resume(void)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 DataBuf *dbuf;
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
173 capi_conn_t *conn;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
175 for (i = 0; i < dList_length(CapiConns); ++i) {
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
176 conn = dList_nth_data (CapiConns, i);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
177 if (conn->Flags & PENDING) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178 dbuf = a_Chain_dbuf_new(conn->datastr,(int)strlen(conn->datastr), 0);
1287
50ef0236a45e Bugfix for a race condition SEGFAULT in capi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1284
diff changeset
179 if (conn->InfoSend) {
50ef0236a45e Bugfix for a race condition SEGFAULT in capi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1284
diff changeset
180 a_Capi_ccc(OpSend, 1, BCK, conn->InfoSend, dbuf, NULL);
50ef0236a45e Bugfix for a race condition SEGFAULT in capi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1284
diff changeset
181 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 dFree(dbuf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 conn->Flags &= ~PENDING;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 * Abort the connection for a given url, using its CCC.
1284
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
190 * (OpAbort 2,BCK removes the cache entry)
1401
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
191 * TODO: when conn is already done, the cache entry isn't removed.
1591
cf7f2d3312fb trim some spaces
corvid <corvid@lavabit.com>
parents: 1588
diff changeset
192 * This may be wrong and needs a revision.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 void a_Capi_conn_abort_by_url(const DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
195 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
196 int i;
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
197 capi_conn_t *conn;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
198
1279
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
199 for (i = 0; i < dList_length(CapiConns); ++i) {
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
200 conn = dList_nth_data (CapiConns, i);
761fc65a49f5 Switched capi to use dlib's Dlist instead of a_List_* methods
Jorge Arellano Cid <jcid@dillo.org>
parents: 1277
diff changeset
201 if (a_Url_cmp(conn->url, url) == 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202 if (conn->InfoSend) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 a_Capi_ccc(OpAbort, 1, BCK, conn->InfoSend, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205 if (conn->InfoRecv) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 a_Capi_ccc(OpAbort, 2, BCK, conn->InfoRecv, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213 /* ------------------------------------------------------------------------- */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 /*
1600
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
216 * Store the last URL requested by "view source"
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
217 */
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
218 void a_Capi_set_vsource_url(const DilloUrl *url)
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
219 {
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
220 a_Url_free(CapiVsUrl);
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
221 CapiVsUrl = a_Url_dup(url);
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
222 }
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
223
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
224 /*
1233
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
225 * Safety test: only allow GET|POST dpi-urls from dpi-generated pages.
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 */
1233
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
227 int a_Capi_dpi_verify_request(BrowserWindow *bw, DilloUrl *url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228 {
1668
8dd6d2330705 const qualifier
corvid <corvid@lavabit.com>
parents: 1667
diff changeset
229 const DilloUrl *referer;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
230 int allow = FALSE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
231
1588
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
232 if (dStrcasecmp(URL_SCHEME(url), "dpi") == 0) {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
233 if (!(URL_FLAGS(url) & (URL_Post + URL_Get))) {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
234 allow = TRUE;
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
235 } else if (!(URL_FLAGS(url) & URL_Post) &&
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
236 strncmp(URL_STR(url), "dpi:/vsource/", 13) == 0) {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
237 allow = TRUE;
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
238 } else {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
239 /* only allow GET&POST dpi-requests from dpi-generated urls */
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
240 if (a_Nav_stack_size(bw)) {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
241 referer = a_History_get_url(NAV_TOP_UIDX(bw));
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
242 if (dStrcasecmp(URL_SCHEME(referer), "dpi") == 0) {
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
243 allow = TRUE;
a6ccdf5807e8 Allow view source for GET URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1577
diff changeset
244 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248 allow = TRUE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
250
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 if (!allow) {
1233
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
252 MSG("a_Capi_dpi_verify_request: Permission Denied!\n");
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
253 MSG(" URL_STR : %s\n", URL_STR(url));
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
254 if (URL_FLAGS(url) & URL_Post) {
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
255 MSG(" URL_DATA: %s\n", dStr_printable(URL_DATA(url), 1024));
157
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 156
diff changeset
256 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258 return allow;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 * If the url belongs to a dpi server, return its name.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263 */
51
6ff7b6758e0c Added the "static" qualifier where missing.
jcid
parents: 35
diff changeset
264 static int Capi_url_uses_dpi(DilloUrl *url, char **server_ptr)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 char *p, *server = NULL, *url_str = URL_STR(url);
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
267 Dstr *tmp;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
269 if ((dStrncasecmp(url_str, "http:", 5) == 0) ||
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
270 (dStrncasecmp(url_str, "about:", 6) == 0)) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
271 /* URL doesn't use dpi (server = NULL) */
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
272 } else if (dStrncasecmp(url_str, "dpi:/", 5) == 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 /* dpi prefix, get this server's name */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 if ((p = strchr(url_str + 5, '/')) != NULL) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 server = dStrndup(url_str + 5, (uint_t)(p - url_str - 5));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
276 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 server = dStrdup("?");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 if (strcmp(server, "bm") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
280 dFree(server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
281 server = dStrdup("bookmarks");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
282 }
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
283 } else if ((p = strchr(url_str, ':')) != NULL) {
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
284 tmp = dStr_new("proto.");
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
285 dStr_append_l(tmp, url_str, p - url_str);
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
286 server = tmp->str;
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 51
diff changeset
287 dStr_free(tmp, 0);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
290 return ((*server_ptr = server) ? 1 : 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
291 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
292
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 * Build the dpip command tag, according to URL and server.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
295 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 static char *Capi_dpi_build_cmd(DilloWeb *web, char *server)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297 {
157
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 156
diff changeset
298 char *cmd;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
299
145
bd486ec2a522 - Enabled https. capi.c: s/https/proto.https/
jcid
parents: 122
diff changeset
300 if (strcmp(server, "proto.https") == 0) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
301 /* Let's be kind and make the HTTP query string for the dpi */
1153
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
302 char *proxy_connect = a_Http_make_connect_str(web->url);
157
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 156
diff changeset
303 Dstr *http_query = a_Http_make_query_str(web->url, FALSE);
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 156
diff changeset
304 /* BUG: embedded NULLs in query data will truncate message */
1153
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
305 if (proxy_connect) {
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
306 const char *proxy_urlstr = a_Http_get_proxy_urlstr();
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
307 cmd = a_Dpip_build_cmd("cmd=%s proxy_url=%s proxy_connect=%s "
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
308 "url=%s query=%s", "open_url", proxy_urlstr,
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
309 proxy_connect, URL_STR(web->url),
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
310 http_query->str);
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
311 } else {
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
312 cmd = a_Dpip_build_cmd("cmd=%s url=%s query=%s",
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
313 "open_url", URL_STR(web->url),http_query->str);
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
314 }
efb854e7b418 proxy support for HTTPS
corvid <corvid@lavabit.com>
parents: 1077
diff changeset
315 dFree(proxy_connect);
157
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 156
diff changeset
316 dStr_free(http_query, 1);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
317
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
318 } else if (strcmp(server, "downloads") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
319 /* let the downloads server get it */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
320 cmd = a_Dpip_build_cmd("cmd=%s url=%s destination=%s",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
321 "download", URL_STR(web->url), web->filename);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
322
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
323 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
324 /* For everyone else, the url string is enough... */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
325 cmd = a_Dpip_build_cmd("cmd=%s url=%s", "open_url", URL_STR(web->url));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
326 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
327 return cmd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
329
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 /*
1600
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
331 * Send the requested URL's source to the "view source" dpi
1577
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
332 */
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
333 static void Capi_dpi_send_source(BrowserWindow *bw, DilloUrl *url)
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
334 {
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
335 char *p, *buf, *cmd, size_str[32], *server="vsource";
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
336 int buf_size;
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
337
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
338 if (!(p = strchr(URL_STR(url), ':')) || !(p = strchr(p + 1, ':')))
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
339 return;
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
340
1600
f50835ca545e Fix "view source" for POST URLs
Jorge Arellano Cid <jcid@dillo.org>
parents: 1597
diff changeset
341 if (a_Capi_get_buf(CapiVsUrl, &buf, &buf_size)) {
1577
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
342 /* send the page's source to this dpi connection */
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
343 snprintf(size_str, 32, "%d", buf_size);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
344 cmd = a_Dpip_build_cmd("cmd=%s url=%s data_size=%s",
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
345 "start_send_page", URL_STR(url), size_str);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
346 a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
347 a_Capi_dpi_send_data(url, bw, buf, buf_size, server, 0);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
348 } else {
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
349 cmd = a_Dpip_build_cmd("cmd=%s msg=%s",
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
350 "DpiError", "Page is NOT cached");
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
351 a_Capi_dpi_send_cmd(NULL, bw, cmd, server, 0);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
352 }
1597
ed63f7b3a242 free send_source cmd
corvid <corvid@lavabit.com>
parents: 1591
diff changeset
353 dFree(cmd);
1577
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
354 }
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
355
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
356 /*
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
357 * When dillo wants to open an URL, this can be either due to user action
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
358 * (e.g., typing in an URL, clicking a link), or automatic (HTTP header
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
359 * indicates redirection, META HTML tag with refresh attribute and 0 delay,
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
360 * and images and stylesheets on an HTML page when autoloading is enabled).
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
361 *
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
362 * For a user request, the action will be permitted.
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
363 * For an automatic request, permission to load depends on the filter set
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
364 * by the user.
1770
4779a3d891a1 trim some spaces
corvid <corvid@lavabit.com>
parents: 1769
diff changeset
365 */
1695
f582fe8c2043 filter msg (grows increasingly similar to Jeremy's proposal)
corvid <corvid@lavabit.com>
parents: 1694
diff changeset
366 static bool_t Capi_filters_test(const DilloUrl *wanted,
f582fe8c2043 filter msg (grows increasingly similar to Jeremy's proposal)
corvid <corvid@lavabit.com>
parents: 1694
diff changeset
367 const DilloUrl *requester)
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
368 {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
369 bool_t ret;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
370
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
371 if (requester == NULL) {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
372 /* request made by user */
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
373 ret = TRUE;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
374 } else {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
375 switch (prefs.filter_auto_requests) {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
376 case PREFS_FILTER_SAME_DOMAIN:
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
377 {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
378 const char *req_host = URL_HOST(requester),
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
379 *want_host = URL_HOST(wanted),
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
380 *req_suffix,
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
381 *want_suffix;
1654
d82939c7c4e8 no-host is "", not NULL
corvid <corvid@lavabit.com>
parents: 1652
diff changeset
382 if (want_host[0] == '\0') {
1667
7ee5774a0601 filter allow if nohost -> nohost
corvid <corvid@lavabit.com>
parents: 1654
diff changeset
383 ret = (req_host[0] == '\0' ||
7ee5774a0601 filter allow if nohost -> nohost
corvid <corvid@lavabit.com>
parents: 1654
diff changeset
384 !dStrcasecmp(URL_SCHEME(wanted), "data")) ? TRUE : FALSE;
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
385 } else {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
386 /* This will regard "www.dillo.org" and "www.dillo.org." as
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
387 * different, but it doesn't seem worth caring about.
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
388 */
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
389 req_suffix = a_Url_host_find_public_suffix(req_host);
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
390 want_suffix = a_Url_host_find_public_suffix(want_host);
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
391
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
392 ret = dStrcasecmp(req_suffix, want_suffix) == 0;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
393 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
394
1695
f582fe8c2043 filter msg (grows increasingly similar to Jeremy's proposal)
corvid <corvid@lavabit.com>
parents: 1694
diff changeset
395 MSG("Capi_filters_test: %s from '%s' to '%s'\n",
f582fe8c2043 filter msg (grows increasingly similar to Jeremy's proposal)
corvid <corvid@lavabit.com>
parents: 1694
diff changeset
396 ret ? "ALLOW" : "DENY", req_host, want_host);
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
397 break;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
398 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
399 case PREFS_FILTER_ALLOW_ALL:
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
400 default:
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
401 ret = TRUE;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
402 break;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
403 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
404 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
405 return ret;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
406 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
407
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
408 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
409 * Most used function for requesting a URL.
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 360
diff changeset
410 * TODO: clean up the ad-hoc bindings with an API that allows dynamic
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
411 * addition of new plugins.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
412 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
413 * Return value: A primary key for identifying the client,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
414 * 0 if the client is aborted in the process.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
415 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
416 int a_Capi_open_url(DilloWeb *web, CA_Callback_t Call, void *CbData)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
417 {
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
418 int reload;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
419 char *cmd, *server;
1277
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
420 capi_conn_t *conn = NULL;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
421 const char *scheme = URL_SCHEME(web->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
422 int safe = 0, ret = 0, use_cache = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
423
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
424 dReturn_val_if_fail((a_Capi_get_flags(web->url) & CAPI_IsCached) ||
1695
f582fe8c2043 filter msg (grows increasingly similar to Jeremy's proposal)
corvid <corvid@lavabit.com>
parents: 1694
diff changeset
425 Capi_filters_test(web->url, web->requester), 0);
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1600
diff changeset
426
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
427 /* reload test */
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
428 reload = (!(a_Capi_get_flags(web->url) & CAPI_IsCached) ||
210
2f05ce84df01 + Fixed a bug in the code that remembers the scrolling position.
jcid
parents: 167
diff changeset
429 (URL_FLAGS(web->url) & URL_E2EQuery));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
430
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 if (web->flags & WEB_Download) {
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
432 /* download request: if cached save from cache, else
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
433 * for http, ftp or https, use the downloads dpi */
1077
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
434 if (a_Capi_get_flags_with_redirection(web->url) & CAPI_IsCached) {
833
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
435 if (web->filename) {
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
436 if ((web->stream = fopen(web->filename, "w"))) {
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
437 use_cache = 1;
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
438 } else {
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
439 MSG_WARN("Cannot open \"%s\" for writing.\n", web->filename);
c50f3c64b023 Added a warning message when a file can't be opened for saving
corvid <corvid@lavabit.com>
parents: 814
diff changeset
440 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 }
1401
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
442 } else if (a_Cache_download_enabled(web->url)) {
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
443 server = "downloads";
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
444 cmd = Capi_dpi_build_cmd(web, server);
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
445 a_Capi_dpi_send_cmd(web->url, web->bw, cmd, server, 1);
3f1501ae35c4 ftp dpi: fixed download offer, streamed transfer, added HTML feedback.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1287
diff changeset
446 dFree(cmd);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
449 } else if (Capi_url_uses_dpi(web->url, &server)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450 /* dpi request */
1233
4741a93c3473 Verify dpi URLs for instant redirects.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1197
diff changeset
451 if ((safe = a_Capi_dpi_verify_request(web->bw, web->url))) {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
452 if (dStrcasecmp(scheme, "dpi") == 0) {
1574
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
453 if (strcmp(server, "vsource") == 0) {
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
454 /* don't reload the "view source" page */
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
455 } else {
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
456 /* make the other "dpi:/" prefixed urls always reload. */
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
457 a_Url_set_flags(web->url, URL_FLAGS(web->url) | URL_E2EQuery);
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
458 reload = 1;
da4dac7f14b1 Interim patch for view source
Jorge Arellano Cid <jcid@dillo.org>
parents: 1570
diff changeset
459 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
460 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
461 if (reload) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
462 a_Capi_conn_abort_by_url(web->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
463 /* Send dpip command */
1577
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
464 _MSG("a_Capi_open_url, reload url='%s'\n", URL_STR(web->url));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
465 cmd = Capi_dpi_build_cmd(web, server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
466 a_Capi_dpi_send_cmd(web->url, web->bw, cmd, server, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
467 dFree(cmd);
1577
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
468 if (strcmp(server, "vsource") == 0) {
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
469 Capi_dpi_send_source(web->bw, web->url);
404899a37226 Handle vsource dpi inside a_Capi_open_url(); more orthogonality.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1574
diff changeset
470 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
471 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
472 use_cache = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
473 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
474 dFree(server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
475
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
476 } else if (!dStrcasecmp(scheme, "http")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
477 /* http request */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
478 if (reload) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
479 a_Capi_conn_abort_by_url(web->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
480 /* create a new connection and start the CCC operations */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
481 conn = Capi_conn_new(web->url, web->bw, "http", "none");
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
482 /* start the reception branch before the query one because the DNS
1769
c43a79252d10 spelling
corvid <corvid@lavabit.com>
parents: 1695
diff changeset
483 * may callback immediately. This may avoid a race condition. */
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
484 a_Capi_ccc(OpStart, 2, BCK, a_Chain_new(), conn, "http");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
485 a_Capi_ccc(OpStart, 1, BCK, a_Chain_new(), conn, web);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
486 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
487 use_cache = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
488
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
489 } else if (!dStrcasecmp(scheme, "about")) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
490 /* internal request */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
491 use_cache = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
492 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
493
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
494 if (use_cache) {
1277
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
495 if (!conn || (conn && Capi_conn_valid(conn))) {
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
496 /* not aborted, let's continue... */
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
497 ret = a_Cache_open_url(web, Call, CbData);
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
498 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
499 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
500 a_Web_free(web);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
501 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
502 return ret;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
503 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
504
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
505 /*
1077
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
506 * Convert cache-defined flags to Capi ones.
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
507 */
1077
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
508 static int Capi_map_cache_flags(uint_t flags)
156
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
509 {
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
510 int status = 0;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
511
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
512 if (flags) {
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
513 status |= CAPI_IsCached;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
514 if (flags & CA_IsEmpty)
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
515 status |= CAPI_IsEmpty;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
516 if (flags & CA_GotData)
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
517 status |= CAPI_Completed;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
518 else
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
519 status |= CAPI_InProgress;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
520
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
521 /* CAPI_Aborted is not yet used/defined */
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
522 }
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
523 return status;
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
524 }
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
525
14f50d7607ed - Added a_Capi_get_flags(). It requests a cache entry's status as flags.
jcid
parents: 145
diff changeset
526 /*
1077
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
527 * Return status information of an URL's content-transfer process.
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
528 */
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
529 int a_Capi_get_flags(const DilloUrl *Url)
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
530 {
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
531 uint_t flags = a_Cache_get_flags(Url);
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
532 int status = flags ? Capi_map_cache_flags(flags) : 0;
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
533 return status;
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
534 }
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
535
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
536 /*
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
537 * Same as a_Capi_get_flags() but following redirections.
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
538 */
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
539 int a_Capi_get_flags_with_redirection(const DilloUrl *Url)
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
540 {
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
541 uint_t flags = a_Cache_get_flags_with_redirection(Url);
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
542 int status = flags ? Capi_map_cache_flags(flags) : 0;
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
543 return status;
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
544 }
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
545
17688e07a8b7 separate a_Capi_get_flags and a_Capi_get_flags_with_redirection
corvid, Jorge Arellano Cid
parents: 930
diff changeset
546 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
547 * Get the cache's buffer for the URL, and its size.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
548 * Return: 1 cached, 0 not cached.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
549 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
550 int a_Capi_get_buf(const DilloUrl *Url, char **PBuf, int *BufSize)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
551 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
552 return a_Cache_get_buf(Url, PBuf, BufSize);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
553 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
554
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
555 /*
260
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
556 * Unref the cache's buffer when no longer using it.
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
557 */
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
558 void a_Capi_unref_buf(const DilloUrl *Url)
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
559 {
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
560 a_Cache_unref_buf(Url);
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
561 }
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
562
81fc5011ea56 - Moved charset decoding into cache.
jcid
parents: 250
diff changeset
563 /*
250
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
564 * Get the Content-Type associated with the URL
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
565 */
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
566 const char *a_Capi_get_content_type(const DilloUrl *url)
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
567 {
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
568 return a_Cache_get_content_type(url);
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
569 }
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
570
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
571 /*
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 833
diff changeset
572 * Set the Content-Type for the URL.
250
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
573 */
814
3e06388a0bc3 Cleanup and logic change in a_Cache_set_content_type().
Jorge Arellano Cid <jcid@dillo.org>
parents: 740
diff changeset
574 const char *a_Capi_set_content_type(const DilloUrl *url, const char *ctype,
3e06388a0bc3 Cleanup and logic change in a_Cache_set_content_type().
Jorge Arellano Cid <jcid@dillo.org>
parents: 740
diff changeset
575 const char *from)
250
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
576 {
814
3e06388a0bc3 Cleanup and logic change in a_Cache_set_content_type().
Jorge Arellano Cid <jcid@dillo.org>
parents: 740
diff changeset
577 return a_Cache_set_content_type(url, ctype, from);
250
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
578 }
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
579
fce9380ee68a - Switched from charset to content-type for handling data.
jcid
parents: 215
diff changeset
580 /*
1569
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
581 * Send data to a dpi (e.g. add_bookmark, open_url, send_preferences, ...)
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
582 * Most of the time we send dpi commands, but it also serves for raw data
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
583 * as with "view source".
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
584 */
1591
cf7f2d3312fb trim some spaces
corvid <corvid@lavabit.com>
parents: 1588
diff changeset
585 int a_Capi_dpi_send_data(const DilloUrl *url, void *bw,
1570
f275bd2cdeed Implement the view source functionality as a dpi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1569
diff changeset
586 char *data, int data_sz, char *server, int flags)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
587 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
588 capi_conn_t *conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
589 DataBuf *dbuf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
590
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
591 if (flags & 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
592 /* open a new connection to server */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
593
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
594 /* Create a new connection data struct and add it to the list */
1569
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
595 conn = Capi_conn_new(url, bw, server, data);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
596 /* start the CCC operations */
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
597 a_Capi_ccc(OpStart, 2, BCK, a_Chain_new(), conn, server);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
598 a_Capi_ccc(OpStart, 1, BCK, a_Chain_new(), conn, server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
599
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
600 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
601 /* Re-use an open connection */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
602 conn = Capi_conn_find(server);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
603 if (conn) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
604 /* found */
1569
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
605 dbuf = a_Chain_dbuf_new(data, data_sz, 0);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
606 a_Capi_ccc(OpSend, 1, BCK, conn->InfoSend, dbuf, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
607 dFree(dbuf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
608 } else {
1570
f275bd2cdeed Implement the view source functionality as a dpi
Jorge Arellano Cid <jcid@dillo.org>
parents: 1569
diff changeset
609 MSG(" ERROR: [a_Capi_dpi_send_data] No open connection found\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
610 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
611 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
612
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
613 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
614 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
615
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
616 /*
1569
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
617 * Send a dpi cmd.
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
618 * (For instance: add_bookmark, open_url, send_preferences, ...)
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
619 */
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
620 int a_Capi_dpi_send_cmd(DilloUrl *url, void *bw, char *cmd, char *server,
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
621 int flags)
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
622 {
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
623 return a_Capi_dpi_send_data(url, bw, cmd, strlen(cmd), server, flags);
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
624 }
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
625
24a5d37b09e1 Add the a_Capi_dpi_send_data() function
Jorge Arellano Cid <jcid@dillo.org>
parents: 1401
diff changeset
626 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
627 * Remove a client from the cache client queue.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
628 * force = also abort the CCC if this is the last client.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
629 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
630 void a_Capi_stop_client(int Key, int force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
631 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
632 CacheClient_t *Client;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
633
1284
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
634 _MSG("a_Capi_stop_client: force=%d\n", force);
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
635
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
636 Client = a_Cache_client_get_if_unique(Key);
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
637 if (Client && (force || Client->BufSize == 0)) {
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
638 /* remove empty entries too */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
639 a_Capi_conn_abort_by_url(Client->Url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
640 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
641 a_Cache_stop_client(Key);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
642 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
643
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
644 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
645 * CCC function for the CAPI module
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
646 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
647 void a_Capi_ccc(int Op, int Branch, int Dir, ChainLink *Info,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
648 void *Data1, void *Data2)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
649 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
650 capi_conn_t *conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
651
215
726937936aa0 - CCC: added reentrancy control to the OpEnd and OpAbort operations.
jcid
parents: 210
diff changeset
652 dReturn_if_fail( a_Chain_check("a_Capi_ccc", Op, Branch, Dir, Info) );
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
653
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
654 if (Branch == 1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
655 if (Dir == BCK) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
656 /* Command sending branch */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
657 switch (Op) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
658 case OpStart:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
659 /* Data1 = conn; Data2 = {Web | server} */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
660 conn = Data1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
661 Capi_conn_ref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
662 Info->LocalKey = conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
663 conn->InfoSend = Info;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
664 if (strcmp(conn->server, "http") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
665 a_Chain_link_new(Info, a_Capi_ccc, BCK, a_Http_ccc, 1, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
666 a_Chain_bcb(OpStart, Info, Data2, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
667 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
668 a_Chain_link_new(Info, a_Capi_ccc, BCK, a_Dpi_ccc, 1, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
669 a_Chain_bcb(OpStart, Info, Data2, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
670 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
671 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
672 case OpSend:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
673 /* Data1 = dbuf */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
674 a_Chain_bcb(OpSend, Info, Data1, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
675 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
676 case OpEnd:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
677 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
678 conn->InfoSend = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
679 a_Chain_bcb(OpEnd, Info, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
680 Capi_conn_unref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
681 dFree(Info);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
682 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
683 case OpAbort:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
684 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
685 conn->InfoSend = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
686 a_Chain_bcb(OpAbort, Info, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
687 Capi_conn_unref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
688 dFree(Info);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
689 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
690 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
691 MSG_WARN("Unused CCC\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
692 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
693 }
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
694 } else { /* 1 FWD */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
695 /* Command sending branch (status) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
696 switch (Op) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
697 case OpSend:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
698 if (!Data2) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
699 MSG_WARN("Capi.c: Opsend [1F] Data2 = NULL\n");
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
700 } else if (strcmp(Data2, "FD") == 0) {
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
701 conn = Info->LocalKey;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
702 conn->SockFD = *(int*)Data1;
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
703 /* communicate the FD through the answer branch */
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
704 a_Capi_ccc(OpSend, 2, BCK, conn->InfoRecv, &conn->SockFD, "FD");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
705 } else if (strcmp(Data2, "DpidOK") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
706 /* resume pending dpi requests */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
707 Capi_conn_resume();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
708 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
709 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
710 case OpAbort:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
711 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
712 conn->InfoSend = NULL;
1270
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
713 if (Data2) {
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
714 if (!strcmp(Data2, "DpidERROR")) {
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
715 a_UIcmd_set_msg(conn->bw,
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
716 "ERROR: can't start dpid daemon "
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
717 "(URL scheme = '%s')!",
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
718 conn->url ? URL_SCHEME(conn->url) : "");
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
719 } else if (!strcmp(Data2, "Both") && conn->InfoRecv) {
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
720 /* abort the other branch too */
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
721 a_Capi_ccc(OpAbort, 2, BCK, conn->InfoRecv, NULL, NULL);
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
722 }
aee7a2cccb71 Interim bugfix patch for the new CCC OpAbort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1267
diff changeset
723 }
1277
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
724 /* if URL == expect-url */
8a9fb20be467 Bugfix: remove the empty cache entry lingering after connection abort
Jorge Arellano Cid <jcid@dillo.org>
parents: 1270
diff changeset
725 a_Nav_cancel_expect_if_eq(conn->bw, conn->url);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
726 /* finish conn */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
727 Capi_conn_unref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
728 dFree(Info);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
729 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
730 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
731 MSG_WARN("Unused CCC\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
732 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
733 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
734 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
735
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
736 } else if (Branch == 2) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
737 if (Dir == BCK) {
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
738 /* Answer branch */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
739 switch (Op) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
740 case OpStart:
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
741 /* Data1 = conn; Data2 = {"http" | "<dpi server name>"} */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
742 conn = Data1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
743 Capi_conn_ref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
744 Info->LocalKey = conn;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
745 conn->InfoRecv = Info;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
746 a_Chain_link_new(Info, a_Capi_ccc, BCK, a_Dpi_ccc, 2, 2);
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
747 a_Chain_bcb(OpStart, Info, NULL, Data2);
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
748 break;
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
749 case OpSend:
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
750 /* Data1 = FD */
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
751 if (Data2 && strcmp(Data2, "FD") == 0) {
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
752 a_Chain_bcb(OpSend, Info, Data1, Data2);
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
753 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
754 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
755 case OpAbort:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
756 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
757 conn->InfoRecv = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
758 a_Chain_bcb(OpAbort, Info, NULL, NULL);
1284
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
759 /* remove the cache entry for this URL */
61e42f8567ef Remove empty cache entries on Stop-button press and new link request!
Jorge Arellano Cid <jcid@dillo.org>
parents: 1279
diff changeset
760 a_Cache_entry_remove_by_url(conn->url);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
761 Capi_conn_unref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
762 dFree(Info);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
763 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
764 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
765 MSG_WARN("Unused CCC\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
766 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
767 }
1267
2590fc2b3e39 Changed the CCCs to build in one step (for both HTTP and DPI)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1233
diff changeset
768 } else { /* 2 FWD */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
769 /* Server listening branch */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
770 switch (Op) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
771 case OpSend:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
772 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
773 if (strcmp(Data2, "send_page_2eof") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
774 /* Data1 = dbuf */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
775 DataBuf *dbuf = Data1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
776 a_Cache_process_dbuf(IORead, dbuf->Buf, dbuf->Size, conn->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
777 } else if (strcmp(Data2, "send_status_message") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
778 a_UIcmd_set_msg(conn->bw, "%s", Data1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
779 } else if (strcmp(Data2, "chat") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
780 a_UIcmd_set_msg(conn->bw, "%s", Data1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
781 a_Bookmarks_chat_add(NULL, NULL, Data1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
782 } else if (strcmp(Data2, "dialog") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
783 a_Dpiapi_dialog(conn->bw, conn->server, Data1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
784 } else if (strcmp(Data2, "reload_request") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
785 a_Nav_reload(conn->bw);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
786 } else if (strcmp(Data2, "start_send_page") == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
787 /* prepare the cache to receive the data stream for this URL
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
788 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
789 * a_Capi_open_url() already added a new cache entry,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
790 * and a client for it.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
791 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
792 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
793 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
794 case OpEnd:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
795 conn = Info->LocalKey;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
796 conn->InfoRecv = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
797
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
798 a_Cache_process_dbuf(IOClose, NULL, 0, conn->url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
799
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
800 if (conn->InfoSend) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
801 /* Propagate OpEnd to the sending branch too */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
802 a_Capi_ccc(OpEnd, 1, BCK, conn->InfoSend, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
803 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
804 Capi_conn_unref(conn);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
805 dFree(Info);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
806 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
807 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
808 MSG_WARN("Unused CCC\n");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
809 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
810 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
811 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
812 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
813 }