comparison lib/protocols.c @ 125:b875de05c22d

2003-4-8 Brian Masney <masneyb@gftp.org> * src/text/gftp-text.c lib/misc.c - moved r_gethostbyname() and r_getservbyname() to lib/misc.c. Now uses GMutex functions * lib/config_file.c lib/gftp.h lib/options.h - added config variable type textcombo. default_protocol uses this * lib/config_file.c (gftp_read_config_file) - when reading in the list of supported protocols, add the protocol names to the list associated with default_protocol. Also, don't try to have default_protocol fall back to FTP. The code that uses this will fall back properly * lib/gftp.h (struct gftp_transfer) - renamed node to user_data * lib/misc.c lib/gftp.h - moved parse_attribs() from src/gtk/transfer.c to misc.c. Renamed to gftp_parse_attribs() * lib/protocols.c lib/gftp.h - moved get_status() from src/gtk/transfer.c to protocols.c. Renamed to gftp_get_transfer_status(). Uses GMutex functions
author masneyb
date Tue, 08 Apr 2003 22:28:17 +0000
parents 65048c959029
children 84b3e69807a2
comparison
equal deleted inserted replaced
124:65048c959029 125:b875de05c22d
431 if (gftp_protocols[i].name == NULL) 431 if (gftp_protocols[i].name == NULL)
432 { 432 {
433 gftp_lookup_request_option (request, "default_protocol", 433 gftp_lookup_request_option (request, "default_protocol",
434 &default_protocol); 434 &default_protocol);
435 435
436 if (*default_protocol != '\0') 436 if (default_protocol != NULL && *default_protocol != '\0')
437 { 437 {
438 for (i = 0; gftp_protocols[i].url_prefix; i++) 438 for (i = 0; gftp_protocols[i].url_prefix; i++)
439 { 439 {
440 if (strcmp (gftp_protocols[i].name, default_protocol) == 0) 440 if (strcmp (gftp_protocols[i].name, default_protocol) == 0)
441 break; 441 break;
487 else 487 else
488 { 488 {
489 gftp_lookup_request_option (request, "default_protocol", 489 gftp_lookup_request_option (request, "default_protocol",
490 &default_protocol); 490 &default_protocol);
491 491
492 if (*default_protocol != '\0') 492 if (default_protocol != NULL && *default_protocol != '\0')
493 { 493 {
494 for (i = 0; gftp_protocols[i].url_prefix; i++) 494 for (i = 0; gftp_protocols[i].url_prefix; i++)
495 { 495 {
496 if (strcmp (gftp_protocols[i].name, default_protocol) == 0) 496 if (strcmp (gftp_protocols[i].name, default_protocol) == 0)
497 break; 497 break;
2177 2177
2178 if (g_thread_supported ()) 2178 if (g_thread_supported ())
2179 g_static_mutex_unlock (&tdata->statmutex); 2179 g_static_mutex_unlock (&tdata->statmutex);
2180 } 2180 }
2181 2181
2182
2183 int
2184 gftp_get_transfer_status (gftp_transfer * tdata, ssize_t num_read)
2185 {
2186 int ret1, ret2, retries, sleep_time;
2187 gftp_file * tempfle;
2188 struct timeval tv;
2189
2190 ret1 = ret2 = 0;
2191 gftp_lookup_request_option (tdata->fromreq, "retries", &retries);
2192 gftp_lookup_request_option (tdata->fromreq, "sleep_time", &sleep_time);
2193
2194 if (g_thread_supported ())
2195 g_static_mutex_lock (&tdata->structmutex);
2196
2197 if (tdata->curfle == NULL)
2198 {
2199 if (g_thread_supported ())
2200 g_static_mutex_unlock (&tdata->structmutex);
2201
2202 return (GFTP_EFATAL);
2203 }
2204
2205 tempfle = tdata->curfle->data;
2206
2207 if (g_thread_supported ())
2208 g_static_mutex_unlock (&tdata->structmutex);
2209
2210 gftp_disconnect (tdata->fromreq);
2211 gftp_disconnect (tdata->toreq);
2212
2213 if (num_read < 0 || tdata->skip_file)
2214 {
2215 if (num_read == GFTP_EFATAL)
2216 return (GFTP_EFATAL);
2217 else if (retries != 0 &&
2218 tdata->current_file_retries >= retries)
2219 {
2220 tdata->fromreq->logging_function (gftp_logging_error,
2221 tdata->fromreq->user_data,
2222 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"),
2223 tdata->fromreq->hostname != NULL ?
2224 tdata->fromreq->hostname : tdata->toreq->hostname);
2225 return (GFTP_EFATAL);
2226 }
2227 else
2228 {
2229 tdata->fromreq->logging_function (gftp_logging_error,
2230 tdata->fromreq->user_data,
2231 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"),
2232 tdata->fromreq->hostname != NULL ?
2233 tdata->fromreq->hostname : tdata->toreq->hostname,
2234 sleep_time);
2235 }
2236
2237 while (retries == 0 ||
2238 tdata->current_file_retries <= retries)
2239 {
2240 if (!tdata->skip_file)
2241 {
2242 tv.tv_sec = sleep_time;
2243 tv.tv_usec = 0;
2244 select (0, NULL, NULL, NULL, &tv);
2245 }
2246
2247 if ((ret1 = gftp_connect (tdata->fromreq)) == 0 &&
2248 (ret2 = gftp_connect (tdata->toreq)) == 0)
2249 {
2250 if (g_thread_supported ())
2251 g_static_mutex_lock (&tdata->structmutex);
2252
2253 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans;
2254 tdata->trans_bytes = 0;
2255 if (tdata->skip_file)
2256 {
2257 tdata->total_bytes -= tempfle->size;
2258 tdata->curtrans = 0;
2259
2260 tdata->curfle = tdata->curfle->next;
2261 tdata->next_file = 1;
2262 tdata->skip_file = 0;
2263 tdata->cancel = 0;
2264 tdata->fromreq->cancel = 0;
2265 tdata->toreq->cancel = 0;
2266 }
2267 else
2268 {
2269 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME;
2270 tempfle->startsize = tdata->curtrans + tdata->curresumed;
2271 /* We decrement this here because it will be incremented in
2272 the loop again */
2273 tdata->curresumed = 0;
2274 tdata->current_file_number--; /* Decrement this because it
2275 will be incremented when we
2276 continue in the loop */
2277 }
2278
2279 gettimeofday (&tdata->starttime, NULL);
2280
2281 if (g_thread_supported ())
2282 g_static_mutex_unlock (&tdata->structmutex);
2283
2284 return (GFTP_ERETRYABLE);
2285 }
2286 else if (ret1 == GFTP_EFATAL || ret2 == GFTP_EFATAL)
2287 {
2288 gftp_disconnect (tdata->fromreq);
2289 gftp_disconnect (tdata->toreq);
2290 return (GFTP_EFATAL);
2291 }
2292 else
2293 tdata->current_file_retries++;
2294 }
2295 }
2296 else if (tdata->cancel)
2297 return (GFTP_EFATAL);
2298
2299 return (0);
2300 }
2301