Skip to content
Browse files

added wordpress cookie and moved something to cookieutils

  • Loading branch information...
1 parent fa27d80 commit f26aa2822fba649908a4c2f52673f8fa194fa2e4 naturegirl committed Jan 10, 2014
View
15 src/com/BiscuitSpy/cookies/CookieUtils.java
@@ -1,6 +1,9 @@
package com.BiscuitSpy.cookies;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.StringTokenizer;
public class CookieUtils {
@@ -38,4 +41,16 @@ public static void main(String[] args) {
return result;
}
+ /**
+ * converts a unix timestamp to a readable date time string
+ * @param unixTimestamp: unix timestamp (in seconds, not milliseconds)
+ * @return returns a time string of format: "01/16/1970 08:55 PM"
+ */
+ public static String convertTimestamp(String unixTimestamp) {
+ DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
+ long timestamp = Long.parseLong(unixTimestamp) * 1000; // miliseconds
+ Date date = new Date(timestamp);
+ return df.format(date);
+ }
+
}
View
23 src/com/BiscuitSpy/cookies/definitions/Utma.java
@@ -1,12 +1,11 @@
package com.BiscuitSpy.cookies.definitions;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.StringTokenizer;
+import com.BiscuitSpy.cookies.CookieUtils;
public class Utma {
+ // cookie name: __utma
// utma cookie structure:
// 'domain hash'.'visitor id'.'initial visit'.'previous visit'.'current visit'.'session number'
String domainhash, visitorid, sessionCount;
@@ -29,24 +28,12 @@ public Utma(String utmastring) {
}
domainhash = st.nextToken();
visitorid = st.nextToken();
- firstVisit = convertTimestamp(st.nextToken());
- previousVisit = convertTimestamp(st.nextToken());
- currentVisit = convertTimestamp(st.nextToken());
+ firstVisit = CookieUtils.convertTimestamp(st.nextToken());
+ previousVisit = CookieUtils.convertTimestamp(st.nextToken());
+ currentVisit = CookieUtils.convertTimestamp(st.nextToken());
sessionCount = st.nextToken();
}
- /**
- *
- * @param unixTimestamp: unix timestamp (in seconds, not milliseconds)
- * @return returns a time string of format: "01/16/1970 08:55 PM"
- */
- private String convertTimestamp(String unixTimestamp) {
- DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
- long timestamp = Long.parseLong(unixTimestamp) * 1000; // miliseconds
- Date date = new Date(timestamp);
- return df.format(date);
- }
-
public String getVisitorId() {
return visitorid;
}
View
57 src/com/BiscuitSpy/cookies/definitions/Wordpress.java
@@ -0,0 +1,57 @@
+package com.BiscuitSpy.cookies.definitions;
+
+import java.util.StringTokenizer;
+
+public class Wordpress {
+
+ // cookie name: wpc_wpc
+ // wordpress wpc cookie structure:
+ // has multiple fields divided by & where each field has structure: key=value
+ // account=xxx&avatar=xxx&email=xxx&link=xxx&name=xxx&uid=xxx&access_token=xxx
+ // see main() for example
+
+ String email, accountname, username;
+
+
+ public Wordpress(String wpc_string) {
+ if (wpc_string == null || wpc_string == "") {
+ System.out.println("Error in Wordpress(): wpc_string is empty");
+ return;
+ }
+ String delim = "&";
+ StringTokenizer st = new StringTokenizer(wpc_string, delim);
+ if (st.countTokens() != 7) {
+ System.out.println("Error in Wordpress(): wordpress cookie tokens count incorrect");
+ return;
+ }
+ accountname = st.nextToken();
+ st.nextToken(); // skip avatar
+ email = st.nextToken();
+ st.nextToken(); // skip link
+ username = st.nextToken();
+ }
+
+
+ public String getAccountName() {
+ return accountname;
+ }
+
+ // username might be different from accountname
+ public String getUsername() {
+ return username;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ String wpc_string = "account=xuezhongwen&avatar=https%3A%2F%2F1.gravatar.com%2Favatar%2F420824352fe495c1b3b1dd0bc157def4%3Fs%3D25%26amp%3Bd%3Dhttps%253A%252F%252Fs2.wp.com%252Fwp-content%252Fmu-plugins%252Fhighlander-comments%252Fimages%252Fwplogo.png&email=nature_girl473%40yahoo.de&link=http%3A%2F%2Fgravatar.com%2Fxuezhongwen&name=naturegirl&uid=1757819&access_token=1d31013fd9a4613cfb7975c98553c4f762f32750";
+ Wordpress wp = new Wordpress(wpc_string);
+ }
+
+}

0 comments on commit f26aa28

Please sign in to comment.
Something went wrong with that request. Please try again.