diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-02 11:35:53 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-02 11:36:53 +0200 |
commit | 51d823832538d495f382299ec668e7afa1cc12f8 (patch) | |
tree | 48884754c0d2d5f37f41425726d28ffa1101733e | |
parent | 2254b31a65c784888215169efc9a067f7dd3a430 (diff) |
Add support for Finger protocol
A patch courtesy of John Cowan.
IssueID #106
-rw-r--r-- | src/gmdocument.c | 22 | ||||
-rw-r--r-- | src/gmdocument.h | 2 | ||||
-rw-r--r-- | src/gmrequest.c | 9 | ||||
-rw-r--r-- | src/gopher.c | 17 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 1 |
5 files changed, 30 insertions, 21 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 1f8ecb75..8d2e3f1f 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -177,8 +177,9 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li | |||
177 | else if (startsWithCase_Rangecc(parts.scheme, "http")) { | 177 | else if (startsWithCase_Rangecc(parts.scheme, "http")) { |
178 | link->flags |= http_GmLinkFlag; | 178 | link->flags |= http_GmLinkFlag; |
179 | } | 179 | } |
180 | else if (equalCase_Rangecc(parts.scheme, "gopher")) { | 180 | else if (equalCase_Rangecc(parts.scheme, "gopher") || |
181 | link->flags |= gopher_GmLinkFlag; | 181 | equalCase_Rangecc(parts.scheme, "finger")) { |
182 | link->flags |= gopher_finger_GmLinkFlag; | ||
182 | if (startsWith_Rangecc(parts.path, "/7")) { | 183 | if (startsWith_Rangecc(parts.path, "/7")) { |
183 | link->flags |= query_GmLinkFlag; | 184 | link->flags |= query_GmLinkFlag; |
184 | } | 185 | } |
@@ -187,7 +188,6 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li | |||
187 | link->flags |= file_GmLinkFlag; | 188 | link->flags |= file_GmLinkFlag; |
188 | } | 189 | } |
189 | else if (equalCase_Rangecc(parts.scheme, "data")) { | 190 | else if (equalCase_Rangecc(parts.scheme, "data")) { |
190 | link->flags |= data_GmLinkFlag; | ||
191 | } | 191 | } |
192 | else if (equalCase_Rangecc(parts.scheme, "about")) { | 192 | else if (equalCase_Rangecc(parts.scheme, "about")) { |
193 | link->flags |= about_GmLinkFlag; | 193 | link->flags |= about_GmLinkFlag; |
@@ -245,7 +245,8 @@ static iBool isForcedMonospace_GmDocument_(const iGmDocument *d) { | |||
245 | if (equalCase_Rangecc(scheme, "gemini")) { | 245 | if (equalCase_Rangecc(scheme, "gemini")) { |
246 | return prefs_App()->monospaceGemini; | 246 | return prefs_App()->monospaceGemini; |
247 | } | 247 | } |
248 | if (equalCase_Rangecc(scheme, "gopher")) { | 248 | if (equalCase_Rangecc(scheme, "gopher") || |
249 | equalCase_Rangecc(scheme, "finger")) { | ||
249 | return prefs_App()->monospaceGopher; | 250 | return prefs_App()->monospaceGopher; |
250 | } | 251 | } |
251 | return iFalse; | 252 | return iFalse; |
@@ -1373,24 +1374,24 @@ enum iColorId linkColor_GmDocument(const iGmDocument *d, iGmLinkId linkId, enum | |||
1373 | if (link->flags & visited_GmLinkFlag) { | 1374 | if (link->flags & visited_GmLinkFlag) { |
1374 | return link->flags & www_GmLinkFlag | 1375 | return link->flags & www_GmLinkFlag |
1375 | ? tmHypertextLinkIconVisited_ColorId | 1376 | ? tmHypertextLinkIconVisited_ColorId |
1376 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkIconVisited_ColorId | 1377 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkIconVisited_ColorId |
1377 | : tmLinkIconVisited_ColorId; | 1378 | : tmLinkIconVisited_ColorId; |
1378 | } | 1379 | } |
1379 | return link->flags & www_GmLinkFlag | 1380 | return link->flags & www_GmLinkFlag |
1380 | ? tmHypertextLinkIcon_ColorId | 1381 | ? tmHypertextLinkIcon_ColorId |
1381 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkIcon_ColorId | 1382 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkIcon_ColorId |
1382 | : tmLinkIcon_ColorId; | 1383 | : tmLinkIcon_ColorId; |
1383 | } | 1384 | } |
1384 | if (part == text_GmLinkPart) { | 1385 | if (part == text_GmLinkPart) { |
1385 | return link->flags & www_GmLinkFlag | 1386 | return link->flags & www_GmLinkFlag |
1386 | ? tmHypertextLinkText_ColorId | 1387 | ? tmHypertextLinkText_ColorId |
1387 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkText_ColorId | 1388 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkText_ColorId |
1388 | : tmLinkText_ColorId; | 1389 | : tmLinkText_ColorId; |
1389 | } | 1390 | } |
1390 | if (part == textHover_GmLinkPart) { | 1391 | if (part == textHover_GmLinkPart) { |
1391 | return link->flags & www_GmLinkFlag | 1392 | return link->flags & www_GmLinkFlag |
1392 | ? tmHypertextLinkTextHover_ColorId | 1393 | ? tmHypertextLinkTextHover_ColorId |
1393 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkTextHover_ColorId | 1394 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkTextHover_ColorId |
1394 | : tmLinkTextHover_ColorId; | 1395 | : tmLinkTextHover_ColorId; |
1395 | } | 1396 | } |
1396 | if (part == domain_GmLinkPart) { | 1397 | if (part == domain_GmLinkPart) { |
@@ -1399,13 +1400,13 @@ enum iColorId linkColor_GmDocument(const iGmDocument *d, iGmLinkId linkId, enum | |||
1399 | } | 1400 | } |
1400 | return link->flags & www_GmLinkFlag | 1401 | return link->flags & www_GmLinkFlag |
1401 | ? tmHypertextLinkDomain_ColorId | 1402 | ? tmHypertextLinkDomain_ColorId |
1402 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkDomain_ColorId | 1403 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkDomain_ColorId |
1403 | : tmLinkDomain_ColorId; | 1404 | : tmLinkDomain_ColorId; |
1404 | } | 1405 | } |
1405 | if (part == visited_GmLinkPart) { | 1406 | if (part == visited_GmLinkPart) { |
1406 | return link->flags & www_GmLinkFlag | 1407 | return link->flags & www_GmLinkFlag |
1407 | ? tmHypertextLinkLastVisitDate_ColorId | 1408 | ? tmHypertextLinkLastVisitDate_ColorId |
1408 | : link->flags & gopher_GmLinkFlag ? tmGopherLinkLastVisitDate_ColorId | 1409 | : link->flags & gopher_finger_GmLinkFlag ? tmGopherLinkLastVisitDate_ColorId |
1409 | : tmLinkLastVisitDate_ColorId; | 1410 | : tmLinkLastVisitDate_ColorId; |
1410 | } | 1411 | } |
1411 | } | 1412 | } |
@@ -1416,6 +1417,7 @@ iBool isMediaLink_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | |||
1416 | const iString *dstUrl = absoluteUrl_String(&d->url, linkUrl_GmDocument(d, linkId)); | 1417 | const iString *dstUrl = absoluteUrl_String(&d->url, linkUrl_GmDocument(d, linkId)); |
1417 | const iRangecc scheme = urlScheme_String(dstUrl); | 1418 | const iRangecc scheme = urlScheme_String(dstUrl); |
1418 | if (equalCase_Rangecc(scheme, "gemini") || equalCase_Rangecc(scheme, "gopher") || | 1419 | if (equalCase_Rangecc(scheme, "gemini") || equalCase_Rangecc(scheme, "gopher") || |
1420 | equalCase_Rangecc(scheme, "finger") || | ||
1419 | equalCase_Rangecc(scheme, "file") || willUseProxy_App(scheme)) { | 1421 | equalCase_Rangecc(scheme, "file") || willUseProxy_App(scheme)) { |
1420 | return (linkFlags_GmDocument(d, linkId) & | 1422 | return (linkFlags_GmDocument(d, linkId) & |
1421 | (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag)) != 0; | 1423 | (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag)) != 0; |
diff --git a/src/gmdocument.h b/src/gmdocument.h index b1121d85..7d962511 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h | |||
@@ -53,7 +53,7 @@ typedef uint16_t iGmLinkId; | |||
53 | 53 | ||
54 | enum iGmLinkFlags { | 54 | enum iGmLinkFlags { |
55 | gemini_GmLinkFlag = iBit(1), | 55 | gemini_GmLinkFlag = iBit(1), |
56 | gopher_GmLinkFlag = iBit(2), | 56 | gopher_finger_GmLinkFlag = iBit(2), |
57 | http_GmLinkFlag = iBit(3), | 57 | http_GmLinkFlag = iBit(3), |
58 | file_GmLinkFlag = iBit(4), | 58 | file_GmLinkFlag = iBit(4), |
59 | data_GmLinkFlag = iBit(5), | 59 | data_GmLinkFlag = iBit(5), |
diff --git a/src/gmrequest.c b/src/gmrequest.c index 5b005fbb..a1cf1a8e 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -434,9 +434,6 @@ static void gopherError_GmRequest_(iGmRequest *d, iSocket *socket, int error, co | |||
434 | } | 434 | } |
435 | 435 | ||
436 | static void beginGopherConnection_GmRequest_(iGmRequest *d, const iString *host, uint16_t port) { | 436 | static void beginGopherConnection_GmRequest_(iGmRequest *d, const iString *host, uint16_t port) { |
437 | if (port == 0) { | ||
438 | port = 70; /* default port */ | ||
439 | } | ||
440 | clear_Block(&d->gopher.source); | 437 | clear_Block(&d->gopher.source); |
441 | iGmResponse *resp = d->resp; | 438 | iGmResponse *resp = d->resp; |
442 | d->gopher.meta = &resp->meta; | 439 | d->gopher.meta = &resp->meta; |
@@ -642,7 +639,11 @@ void submit_GmRequest(iGmRequest *d) { | |||
642 | } | 639 | } |
643 | } | 640 | } |
644 | else if (equalCase_Rangecc(url.scheme, "gopher")) { | 641 | else if (equalCase_Rangecc(url.scheme, "gopher")) { |
645 | beginGopherConnection_GmRequest_(d, host, port); | 642 | beginGopherConnection_GmRequest_(d, host, port ? port : 70); |
643 | return; | ||
644 | } | ||
645 | else if (equalCase_Rangecc(url.scheme, "finger")) { | ||
646 | beginGopherConnection_GmRequest_(d, host, port ? port : 79); | ||
646 | return; | 647 | return; |
647 | } | 648 | } |
648 | else if (!equalCase_Rangecc(url.scheme, "gemini")) { | 649 | else if (!equalCase_Rangecc(url.scheme, "gemini")) { |
diff --git a/src/gopher.c b/src/gopher.c index dfdcf672..229ff9f4 100644 --- a/src/gopher.c +++ b/src/gopher.c | |||
@@ -149,16 +149,21 @@ void deinit_Gopher(iGopher *d) { | |||
149 | void open_Gopher(iGopher *d, const iString *url) { | 149 | void open_Gopher(iGopher *d, const iString *url) { |
150 | iUrl parts; | 150 | iUrl parts; |
151 | init_Url(&parts, url); | 151 | init_Url(&parts, url); |
152 | /* Determine Gopher item type. */ | ||
153 | d->type = '1'; | ||
154 | if (!isEmpty_Range(&parts.path)) { | 152 | if (!isEmpty_Range(&parts.path)) { |
155 | if (*parts.path.start == '/') { | 153 | if (*parts.path.start == '/') { |
156 | parts.path.start++; | 154 | parts.path.start++; |
157 | } | 155 | } |
158 | if (parts.path.start < parts.path.end) { | 156 | } |
159 | d->type = *parts.path.start; | 157 | /* Determine Gopher item type (finger is type 0). */ |
160 | parts.path.start++; | 158 | if (equalCase_Rangecc(parts.scheme, "finger")) { |
161 | } | 159 | d->type = '0'; |
160 | } | ||
161 | else if (parts.path.start < parts.path.end) { | ||
162 | d->type = *parts.path.start; | ||
163 | parts.path.start++; | ||
164 | } | ||
165 | else { | ||
166 | d->type = '1'; | ||
162 | } | 167 | } |
163 | if (d->type == '7' && isEmpty_Range(&parts.query)) { | 168 | if (d->type == '7' && isEmpty_Range(&parts.query)) { |
164 | /* Ask for the query parameters first. */ | 169 | /* Ask for the query parameters first. */ |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index bc9dbc8d..da66c65d 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -2292,6 +2292,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2292 | const iRangecc scheme = urlScheme_String(linkUrl); | 2292 | const iRangecc scheme = urlScheme_String(linkUrl); |
2293 | const iBool isGemini = equalCase_Rangecc(scheme, "gemini"); | 2293 | const iBool isGemini = equalCase_Rangecc(scheme, "gemini"); |
2294 | if (willUseProxy_App(scheme) || isGemini || | 2294 | if (willUseProxy_App(scheme) || isGemini || |
2295 | equalCase_Rangecc(scheme, "finger") || | ||
2295 | equalCase_Rangecc(scheme, "gopher")) { | 2296 | equalCase_Rangecc(scheme, "gopher")) { |
2296 | /* Regular links that we can open. */ | 2297 | /* Regular links that we can open. */ |
2297 | pushBackN_Array( | 2298 | pushBackN_Array( |