File: update.c

package info (click to toggle)
apt-spy 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 344 kB
  • sloc: ansic: 1,067; makefile: 54; sh: 11
file content (59 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * apt-spy (c) Steven Holmes, 2003.
 * This software is licensed as detailed in the COPYRIGHT file
 */

#include <stdio.h>
#include <curl/curl.h>

#include "include/update.h"

int update(FILE *mirror_p, char *update_url, char *proxy)
{
	CURL *curl;
	char errorbuff[CURL_ERROR_SIZE];
	int error;

	curl = curl_easy_init();

	if (curl == NULL)
		return 1;

	if (proxy != NULL)
		if (curl_easy_setopt(curl, CURLOPT_PROXY, proxy) != 0)
			return 1;

	/* Turn off libcurl's progress indicator */
	if (curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1) != 0)
		return 1;

	/* Fail on error */
	if (curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1) != 0)
		return 1;

	/* And give us nice, human-readable error messages */
	if (curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuff) != 0)
		return 1;

	/* set URL to use */
	if (curl_easy_setopt(curl, CURLOPT_URL, update_url) != 0)
		return 1;

	/* set file to output stuff to */
	if (curl_easy_setopt(curl, CURLOPT_FILE, mirror_p) != 0)
		return 1;

	printf("Updating...\n");
	printf("Grabbing file %s...\n", update_url);

	/* Do the transfer */
	if ((error = curl_easy_perform(curl)) != 0) {
		fprintf(stderr, "Error: %i: %s\n", error, errorbuff);
		return 1;
	}

	/* And cleanup */
	curl_easy_cleanup(curl);

	return 0;
}