summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gmrequest.c38
-rw-r--r--src/gmrequest.h1
2 files changed, 16 insertions, 23 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index 6f2c2bc5..e05679bd 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -48,21 +48,24 @@ void init_GmRequest(iGmRequest *d) {
48} 48}
49 49
50void deinit_GmRequest(iGmRequest *d) { 50void deinit_GmRequest(iGmRequest *d) {
51 if (d->req) {
52 iDisconnectObject(TlsRequest, d->req, readyRead, d);
53 iDisconnectObject(TlsRequest, d->req, finished, d);
54 }
51 lock_Mutex(&d->mutex); 55 lock_Mutex(&d->mutex);
52 if (d->timeoutId) { 56 if (d->timeoutId) {
53 SDL_RemoveTimer(d->timeoutId); 57 SDL_RemoveTimer(d->timeoutId);
54 } 58 }
55 if (d->req) { 59 if (!isFinished_GmRequest(d)) {
56 if (!isFinished_GmRequest(d)) { 60 unlock_Mutex(&d->mutex);
57 iDisconnectObject(TlsRequest, d->req, readyRead, d); 61 cancel_TlsRequest(d->req);
58 iDisconnectObject(TlsRequest, d->req, finished, d); 62 d->state = finished_GmRequestState;
59 cancel_TlsRequest(d->req);
60 d->state = finished_GmRequestState;
61 }
62 iRelease(d->req);
63 d->req = NULL;
64 } 63 }
65 unlock_Mutex(&d->mutex); 64 else {
65 unlock_Mutex(&d->mutex);
66 }
67 iRelease(d->req);
68 d->req = NULL;
66 delete_Audience(d->finished); 69 delete_Audience(d->finished);
67 delete_Audience(d->updated); 70 delete_Audience(d->updated);
68 deinit_Block(&d->body); 71 deinit_Block(&d->body);
@@ -157,8 +160,8 @@ static void requestFinished_GmRequest_(iAnyObject *obj) {
157 } 160 }
158 SDL_RemoveTimer(d->timeoutId); 161 SDL_RemoveTimer(d->timeoutId);
159 d->timeoutId = 0; 162 d->timeoutId = 0;
160 iReleaseLater(d->req); 163// iReleaseLater(d->req);
161 d->req = NULL; 164// d->req = NULL;
162 d->state = finished_GmRequestState; 165 d->state = finished_GmRequestState;
163 unlock_Mutex(&d->mutex); 166 unlock_Mutex(&d->mutex);
164 iNotifyAudience(d, finished, GmRequestFinished); 167 iNotifyAudience(d, finished, GmRequestFinished);
@@ -186,6 +189,7 @@ void submit_GmRequest(iGmRequest *d) {
186 } 189 }
187 else { 190 else {
188 d->code = failedToOpenFile_GmStatusCode; 191 d->code = failedToOpenFile_GmStatusCode;
192 setCStr_String(&d->header, cstr_String(path));
189 } 193 }
190 iRelease(f); 194 iRelease(f);
191 d->state = finished_GmRequestState; 195 d->state = finished_GmRequestState;
@@ -212,16 +216,6 @@ iBool isFinished_GmRequest(const iGmRequest *d) {
212 return done; 216 return done;
213} 217}
214 218
215const char *error_GmRequest(const iGmRequest *d) {
216 if (d->code == failedToOpenFile_GmStatusCode) {
217 return "Failed to open file";
218 }
219 if (d->code == invalidHeader_GmStatusCode) {
220 return "Received invalid header (not Gemini?)";
221 }
222 return NULL; /* TDOO: detailed error string */
223}
224
225enum iGmStatusCode status_GmRequest(const iGmRequest *d) { 219enum iGmStatusCode status_GmRequest(const iGmRequest *d) {
226 return d->code; 220 return d->code;
227} 221}
diff --git a/src/gmrequest.h b/src/gmrequest.h
index b2cd339b..270f976a 100644
--- a/src/gmrequest.h
+++ b/src/gmrequest.h
@@ -17,7 +17,6 @@ void setUrl_GmRequest (iGmRequest *, const iString *url);
17void submit_GmRequest (iGmRequest *); 17void submit_GmRequest (iGmRequest *);
18 18
19iBool isFinished_GmRequest (const iGmRequest *); 19iBool isFinished_GmRequest (const iGmRequest *);
20const char * error_GmRequest (const iGmRequest *); /* NULL if successful */
21enum iGmStatusCode status_GmRequest (const iGmRequest *); 20enum iGmStatusCode status_GmRequest (const iGmRequest *);
22const iString * meta_GmRequest (const iGmRequest *); 21const iString * meta_GmRequest (const iGmRequest *);
23const iBlock * body_GmRequest (const iGmRequest *); 22const iBlock * body_GmRequest (const iGmRequest *);