private List<HttpCookie> getValidCookies(URI uri) {
    List<HttpCookie> targetCookies = new ArrayList<HttpCookie>();
    // If the stored URI does not have a path then it must match any URI in
    // the same domain
    for (URI storedUri : allCookies.keySet()) {
      // Check ith the domains match according to RFC 6265
      if (checkDomainsMatch(storedUri.getHost(), uri.getHost())) {
        // Check if the paths match according to RFC 6265
        if (checkPathsMatch(storedUri.getPath(), uri.getPath())) {
          targetCookies.addAll(allCookies.get(storedUri));
        }
      }
    }

    // Check it there are expired cookies and remove them
    if (!targetCookies.isEmpty()) {
      List<HttpCookie> cookiesToRemoveFromPersistence = new ArrayList<HttpCookie>();
      for (Iterator<HttpCookie> it = targetCookies.iterator(); it.hasNext(); ) {
        HttpCookie currentCookie = it.next();
        if (currentCookie.hasExpired()) {
          cookiesToRemoveFromPersistence.add(currentCookie);
          it.remove();
        }
      }

      if (!cookiesToRemoveFromPersistence.isEmpty()) {
        removeFromPersistence(uri, cookiesToRemoveFromPersistence);
      }
    }
    return targetCookies;
  }
Пример #2
0
  // java.net.HttpCookie is mutable
  public void useMutableInput(HttpCookie cookie) {
    if (cookie == null) {
      throw new NullPointerException();
    }

    // Check whether cookie has expired
    if (cookie.hasExpired()) {
      // Cookie is no longer valid; handle condition by throwing an
      // exception
    }

    // Cookie may have expired since time of check
    doLogic(cookie);
  }
Пример #3
0
  public void loadState(Activity a) {
    SharedPreferences prefs = a.getSharedPreferences("cookies", 0);
    String cookie = prefs.getString("RevTK", "no value");

    Log.v(DEBUG_TAG, "loaded RevTK cookie: " + cookie);

    HttpCookie revTKCookie = new HttpCookie("RevTK", cookie);
    revTKCookie.setVersion(0);
    revTKCookie.setDomain("kanji.koohii.com");

    try {
      if (!(cookie.equals("no value") || revTKCookie.hasExpired())) {
        cm.getCookieStore().add(new URI("http://kanji.koohii.com/"), revTKCookie);
        loggedIn = true;
      }
    } catch (URISyntaxException e) { // should not happen
      e.printStackTrace();
    }
  }