コード例 #1
0
ファイル: weather-bom.c プロジェクト: Achers/libgweather
static void
bom_finish (SoupSession *session, SoupMessage *msg, gpointer data)
{
    GWeatherInfo *info = (GWeatherInfo *)data;
    char *p, *rp;

    g_return_if_fail (info != NULL);

    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
        g_warning ("Failed to get BOM forecast data: %d %s.\n",
		   msg->status_code, msg->reason_phrase);
        _gweather_info_request_done (info);
	return;
    }

    p = strstr (msg->response_body->data, "Forecast for the rest");
    if (p != NULL) {
        rp = strstr (p, "The next routine forecast will be issued");
        if (rp == NULL)
            info->priv->forecast = g_strdup (p);
        else
            info->priv->forecast = g_strndup (p, rp - p);
    }

    if (info->priv->forecast == NULL)
        info->priv->forecast = g_strdup (msg->response_body->data);

    g_print ("%s\n",  info->priv->forecast);
    _gweather_info_request_done (info);
}
コード例 #2
0
ファイル: weather-metar.c プロジェクト: Achers/libgweather
static void
metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
{
    GWeatherInfo *info = (GWeatherInfo *)data;
    GWeatherInfoPrivate *priv;
    WeatherLocation *loc;
    const gchar *p, *eoln;
    gchar *searchkey, *metar;
    gboolean success = FALSE;

    g_return_if_fail (info != NULL);

    priv = info->priv;
   
    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
	if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
	    priv->network_error = TRUE;
	else {
	    /* Translators: %d is an error code, and %s the error string */
	    g_warning (_("Failed to get METAR data: %d %s.\n"),
		       msg->status_code, msg->reason_phrase);
	}

	_gweather_info_request_done (info);
	return;
    }

    loc = &priv->location;

    searchkey = g_strdup_printf ("\n%s", loc->code);
    p = strstr (msg->response_body->data, searchkey);
    g_free (searchkey);
    if (p) {
	p += WEATHER_LOCATION_CODE_LEN + 2;
	eoln = strchr(p, '\n');
	if (eoln)
	    metar = g_strndup (p, eoln - p);
	else
	    metar = g_strdup (p);
	success = metar_parse (metar, info);
	g_free (metar);
    } else if (!strstr (msg->response_body->data, "National Weather Service")) {
	/* The response doesn't even seem to have come from NWS...
	 * most likely it is a wifi hotspot login page. Call that a
	 * network error.
	 */
	priv->network_error = TRUE;
    }

    priv->valid = success;
    _gweather_info_request_done (info);
}
コード例 #3
0
ファイル: weather-yahoo.c プロジェクト: Achers/libgweather
static void
yahoo_finish (SoupSession *session,
	      SoupMessage *msg,
	      gpointer     user_data)
{
    GWeatherInfo *info = GWEATHER_INFO (user_data);

    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
	/* forecast data is not really interesting anyway ;) */
	g_warning ("Failed to get Yahoo! Weather forecast data: %d %s\n",
		   msg->status_code, msg->reason_phrase);
	_gweather_info_request_done (info);
	return;
    }

    parse_forecast_xml (info, msg->response_body);
    _gweather_info_request_done (info);
}
コード例 #4
0
ファイル: weather-iwin.c プロジェクト: SRP2504/libgweather
static void
iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
{
    GWeatherInfo *info = (GWeatherInfo *)data;
    GWeatherInfoPrivate *priv;

    g_return_if_fail (info != NULL);

    if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
        /* forecast data is not really interesting anyway ;) */
	if (msg->status_code != SOUP_STATUS_CANCELLED)
	    g_warning ("Failed to get IWIN forecast data: %d %s\n",
		       msg->status_code, msg->reason_phrase);
        _gweather_info_request_done (info, msg);
        return;
    }

    priv = info->priv;
    priv->forecast_list = parseForecastXml (msg->response_body->data, info);

    _gweather_info_request_done (info, msg);
}