Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/tle-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
You should have received a copy of the GNU General Public License
along with this program; if not, visit http://www.fsf.org/
*/
#include <curl/curl.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
Expand All @@ -32,6 +31,11 @@
#ifdef HAVE_CONFIG_H
#include <build-config.h>
#endif
#ifdef WIN32
#include "win32-fetch.h"
#else
#include <curl/curl.h>
#endif

#include "compat.h"
#include "gpredict-utils.h"
Expand All @@ -42,8 +46,10 @@


/* private function prototypes */
#ifndef WIN32
static size_t my_write_func(void *ptr, size_t size, size_t nmemb,
FILE * stream);
#endif
static gint read_fresh_tle(const gchar * dir, const gchar * fnam,
GHashTable * data);
static gboolean is_tle_file(const gchar * dir, const gchar * fnam);
Expand Down Expand Up @@ -473,8 +479,12 @@ void tle_update_from_network(gboolean silent,
gchar *curfile;
gchar *locfile;
gchar *userconfdir;
#ifdef WIN32
int res;
#else
CURL *curl;
CURLcode res;
#endif
gdouble fraction, start = 0;
FILE *outfile;
GDir *dir;
Expand Down Expand Up @@ -518,20 +528,24 @@ void tle_update_from_network(gboolean silent,
if (!silent && (progress != NULL))
start = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress));

#ifndef WIN32
/* initialise curl */
curl = curl_easy_init();
if (proxy != NULL)
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);

curl_easy_setopt(curl, CURLOPT_USERAGENT, "gpredict/curl");
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
#endif

/* get files */
for (i = 0; i < numfiles; i++)
{
/* set URL */
curfile = g_strdup(files[i]);
#ifndef WIN32
curl_easy_setopt(curl, CURLOPT_URL, curfile);
#endif

/* set activity message */
if (!silent && (label1 != NULL))
Expand All @@ -556,6 +570,22 @@ void tle_update_from_network(gboolean silent,
outfile = g_fopen(locfile, "wb");
if (outfile != NULL)
{
#ifdef WIN32
res = win32_fetch(curfile, outfile, proxy, "gpredict/win32");
if (res != 0)
{
sat_log_log(SAT_LOG_LEVEL_ERROR,
_("%s: Error fetching %s (%x)"),
__func__, curfile, res);
}
else
{
sat_log_log(SAT_LOG_LEVEL_INFO,
_("%s: Successfully fetched %s"),
__func__, curfile);
success++;
}
#else
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);

Expand All @@ -575,6 +605,7 @@ void tle_update_from_network(gboolean silent,
__func__, curfile);
success++;
}
#endif
fclose(outfile);
}
else
Expand Down Expand Up @@ -604,7 +635,9 @@ void tle_update_from_network(gboolean silent,
g_free(locfile);
}

#ifndef WIN32
curl_easy_cleanup(curl);
#endif

/* continue update if we have fetched at least one file */
if (success > 0)
Expand Down Expand Up @@ -665,6 +698,7 @@ void tle_update_from_network(gboolean silent,
g_mutex_unlock(&tle_in_progress);
}

#ifndef WIN32
/**
* Write TLE data block to file.
*
Expand All @@ -683,6 +717,7 @@ static size_t my_write_func(void *ptr, size_t size, size_t nmemb,
/*** FIXME: TBC whether this works in wintendo */
return fwrite(ptr, size, nmemb, stream);
}
#endif

/**
* Check whether file is TLE file.
Expand Down
63 changes: 61 additions & 2 deletions src/trsp-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* Downloads Frequency list from SATNOGS db and exports json transponder
* information into satellite files identified by catalog id
*/
#include <curl/curl.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
Expand All @@ -39,14 +38,20 @@
#include "compat.h"
#include "trsp-update.h"
#include "gpredict-utils.h"
#include "nxjson/nxjson.h"
#include "sat-cfg.h"
#include "sat-log.h"
#include "nxjson/nxjson.h"

#ifdef HAVE_CONFIG_H
#include <build-config.h>
#endif

#ifdef WIN32
#include "win32-fetch.h"
#else
#include <curl/curl.h>
#endif

/* TRSP auto update frequency. */
typedef enum {
TRSP_AUTO_UPDATE_NEVER = 0, /* No auto-update, just warn after one week. */
Expand Down Expand Up @@ -89,9 +94,11 @@ typedef struct {
guint numtrsp; /* Number of transponders. */
} new_trsp_t;

#ifndef WIN32
/* private function prototypes */
static size_t my_write_func(void *ptr, size_t size, size_t nmemb,
FILE * stream);
#endif

//int getMODElist_intoHashMap();

Expand Down Expand Up @@ -387,30 +394,38 @@ void modes_update_from_network()
gchar *file_url;
gchar *locfile;
gchar *userconfdir;
#ifdef WIN32
int res;
#else
CURL *curl;
CURLcode res;
#endif
FILE *outfile;
guint success = 0; /* no. of successfull downloads */

server = sat_cfg_get_str(SAT_CFG_STR_TRSP_SERVER);
proxy = sat_cfg_get_str(SAT_CFG_STR_TRSP_PROXY);
modes_file = sat_cfg_get_str(SAT_CFG_STR_TRSP_MODE_FILE);

#ifndef WIN32
/* initialise curl */
curl = curl_easy_init();
if (proxy != NULL)
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);

curl_easy_setopt(curl, CURLOPT_USERAGENT, "gpredict/curl");
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
#endif

/* get files */
/* set URL */
file_url = g_strconcat(server, modes_file, NULL);
#ifndef WIN32
curl_easy_setopt(curl, CURLOPT_URL, file_url);
sat_log_log(SAT_LOG_LEVEL_INFO,
_("%s: Ready to fetch modes list from %s"),
__func__, file_url);
#endif

/* create local cache file */
userconfdir = get_user_conf_dir();
Expand All @@ -422,6 +437,20 @@ void modes_update_from_network()
outfile = g_fopen(locfile, "wb");
if (outfile != NULL)
{
#ifdef WIN32
res = win32_fetch(file_url, outfile, proxy, "gpredict/win32");
if (res != 0)
{
sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error fetching %s (%x)"),
__func__, file_url, res);
}
else
{
sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Successfully fetched %s"),
__func__, file_url);
success++;
}
#else
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);

Expand All @@ -439,6 +468,7 @@ void modes_update_from_network()
__func__, file_url);
success++;
}
#endif
fclose(outfile);

}
Expand All @@ -455,7 +485,9 @@ void modes_update_from_network()
g_free(proxy);
g_free(modes_file);

#ifndef WIN32
curl_easy_cleanup(curl);
#endif

/* continue update if we have fetched at least one file */
if (success > 0)
Expand Down Expand Up @@ -495,8 +527,12 @@ void trsp_update_from_network(gboolean silent,
gchar *file_url;
gchar *locfile_trsp;
gchar *userconfdir;
#ifdef WIN32
int res;
#else
CURL *curl;
CURLcode res;
#endif
gdouble fraction;
FILE *outfile;
gchar *cache;
Expand Down Expand Up @@ -524,21 +560,25 @@ void trsp_update_from_network(gboolean silent,
proxy = sat_cfg_get_str(SAT_CFG_STR_TRSP_PROXY);
freq_file = sat_cfg_get_str(SAT_CFG_STR_TRSP_FREQ_FILE);

#ifndef WIN32
/* initialise curl */
curl = curl_easy_init();
if (proxy != NULL)
curl_easy_setopt(curl, CURLOPT_PROXY, proxy);

curl_easy_setopt(curl, CURLOPT_USERAGENT, "gpredict/curl");
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
#endif

/* get files */
/* set URL */
file_url = g_strconcat(server, freq_file, NULL);
#ifndef WIN32
curl_easy_setopt(curl, CURLOPT_URL, file_url);
sat_log_log(SAT_LOG_LEVEL_INFO,
_("%s: Ready to fetch transponder list from %s"),
__func__, file_url);
#endif

/* set activity message */
if (!silent && (label1 != NULL))
Expand Down Expand Up @@ -566,6 +606,20 @@ void trsp_update_from_network(gboolean silent,
outfile = g_fopen(locfile_trsp, "wb");
if (outfile != NULL)
{
#ifdef WIN32
res = win32_fetch(file_url, outfile, proxy, "gpredict/win32");
if (res != 0)
{
sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error fetching %s (%x)"),
__func__, file_url, res);
}
else
{
sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Successfully fetched %s"),
__func__, file_url);
success++;
}
#else
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);

Expand All @@ -583,6 +637,7 @@ void trsp_update_from_network(gboolean silent,
__func__, file_url);
success++;
}
#endif
fclose(outfile);

}
Expand Down Expand Up @@ -614,7 +669,9 @@ void trsp_update_from_network(gboolean silent,
g_free(freq_file);
g_free(proxy);

#ifndef WIN32
curl_easy_cleanup(curl);
#endif

/* continue update if we have fetched at least one file */
if (success > 0)
Expand All @@ -637,6 +694,7 @@ void trsp_update_from_network(gboolean silent,
g_mutex_unlock(&trsp_in_progress);
}

#ifndef WIN32
/**
* Write TRSP data block to file.
*
Expand All @@ -655,6 +713,7 @@ static size_t my_write_func(void *ptr, size_t size, size_t nmemb,
/*** FIXME: TBC whether this works in wintendo */
return fwrite(ptr, size, nmemb, stream);
}
#endif

const gchar *freq_to_str2[TRSP_AUTO_UPDATE_NUM] = {
N_("Never"),
Expand Down
Loading