aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2015-03-12 21:36:25 +0100
committerrsudev <rasch@munin-soft.de>2015-03-12 21:36:25 +0100
commit13a402c9134e1c27376edccfc5bb4830c317fcfb (patch)
treeba955f64fad96a796382aeb8fdcedfff1d473a8b
parent09b8bd5147da9d0c9102df34a54fda0b2e762f35 (diff)
downloadcgeo-13a402c9134e1c27376edccfc5bb4830c317fcfb.zip
cgeo-13a402c9134e1c27376edccfc5bb4830c317fcfb.tar.gz
cgeo-13a402c9134e1c27376edccfc5bb4830c317fcfb.tar.bz2
Fixes #4730, Search function broken
- read post action url out of the page
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConstants.java1
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java24
2 files changed, 17 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
index d56bebe..6e6c8b8 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -134,6 +134,7 @@ public final class GCConstants {
final static Pattern PATTERN_SEARCH_RECAPTCHA = Pattern.compile("<script[^>]*src=\"[^\"]*/recaptcha/api/challenge\\?k=([^\"]+)\"[^>]*>");
public final static Pattern PATTERN_SEARCH_RECAPTCHACHALLENGE = Pattern.compile("challenge : '([^']+)'");
final static Pattern PATTERN_SEARCH_HIDDEN_DATE = Pattern.compile("<td style=\"width:70px\">[^<]+<span class=\"small\">([^<]+)</span>");
+ final static Pattern PATTERN_SEARCH_POST_ACTION = Pattern.compile("<form name=\"aspnetForm\" method=\"post\" action=\"(.*)\" id=\"aspnetForm\"");
/**
* Patterns for waypoints
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index f20df8d..d5ea8c4 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -325,17 +325,25 @@ public abstract class GCParser {
params.put("recaptcha_challenge_field", recaptchaReceiver.getChallenge());
params.put("recaptcha_response_field", recaptchaText);
}
- params.put("ctl00$ContentBody$uxDownloadLoc", "Download Waypoints");
+ params.put("Download", "Download Waypoints");
- final String coordinates = Network.getResponseData(Network.postRequest("http://www.geocaching.com/seek/nearest.aspx", params), false);
+ // retrieve target url
+ final String queryUrl = TextUtils.getMatch(pageContent, GCConstants.PATTERN_SEARCH_POST_ACTION, "");
- if (StringUtils.contains(coordinates, "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) {
- Log.i("User has not agreed to the license agreement. Can\'t download .loc file.");
- searchResult.setError(StatusCode.UNAPPROVED_LICENSE);
- return searchResult;
- }
+ if (StringUtils.isEmpty(queryUrl)) {
+ Log.w("Loc download url not found");
+ } else {
+
+ final String coordinates = Network.getResponseData(Network.postRequest("http://www.geocaching.com/seek/" + queryUrl, params), false);
- LocParser.parseLoc(searchResult, coordinates, storedCaches.toBlocking().single());
+ if (StringUtils.contains(coordinates, "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) {
+ Log.i("User has not agreed to the license agreement. Can\'t download .loc file.");
+ searchResult.setError(StatusCode.UNAPPROVED_LICENSE);
+ return searchResult;
+ }
+
+ LocParser.parseLoc(searchResult, coordinates, storedCaches.toBlocking().single());
+ }
} catch (final RuntimeException e) {
Log.e("GCParser.parseSearch.CIDs", e);