📄 httpposter.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
import java.io.*;
import java.util.Date;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class HttpPoster
implements Runnable
{//HTTP通信类;
private volatile boolean aborting;
private Vector requestQueue;
private Vector listenerQueue;
private Vector vDeleteItems;
private final int C_SendInterval = 6;
private String strUin;//用户号码;
private int iSeqNo;
private int iDBTimer;
private int iDBLeftTimer;
private Vector DBCommandQueue;
private boolean bExit;
private int iTimerCnt;
private int iNetErrorCnt;
Thread thread;
private final int C_NetError_TimeCnt = 600;
private boolean timerOn;
public HttpPoster()
{
aborting = false;
requestQueue = new Vector();
listenerQueue = new Vector();
vDeleteItems = new Vector();
iDBTimer = 0;
iDBLeftTimer = 0;
DBCommandQueue = new Vector();
bExit = false;
iTimerCnt = 0;
iNetErrorCnt = 0;
thread = null;
timerOn = false;
iSeqNo = getInitSeqNo();
thread = new Thread(this);
thread.start();
}
public String getUINbySeq(String s)
{
String s1 = null;
for(int i = 0; i < vDeleteItems.size(); i += 2)
{
if(!s.equals((String)vDeleteItems.elementAt(i)))
continue;
s1 = (String)vDeleteItems.elementAt(i + 1);
vDeleteItems.removeElementAt(i + 1);
vDeleteItems.removeElementAt(i);
break;
}
return s1;
}
public void startTimer()
{
timerOn = true;
}
public void stopTimer()
{
timerOn = false;
DBCommandQueue.removeAllElements();
}
public void OnTimer()
{
if(!timerOn)
return;
iTimerCnt++;
if(iDBTimer != 0)
{
iDBTimer--;
if(iDBTimer % 10 == 0)
getDBCommand();
}
if(iDBLeftTimer != 0)
iDBLeftTimer--;
if(++iNetErrorCnt > 600)
{
iNetErrorCnt = 0;
KQQMIDlet.instance.onNetError(true);
}
}
private void addDBCommand(String s, HttpPosterListener httpposterlistener)
{
if(iDBLeftTimer != 0)
{
DBCommandQueue.addElement(s);
DBCommandQueue.addElement(httpposterlistener);
iDBTimer += 10;
} else
{
sendRequest(s, httpposterlistener);
}
iDBLeftTimer += 10;
}
private void getDBCommand()
{
if(DBCommandQueue.size() < 2)
{
return;
} else
{
String s = (String)DBCommandQueue.elementAt(0);
HttpPosterListener httpposterlistener = (HttpPosterListener)DBCommandQueue.elementAt(1);
sendRequest(s, httpposterlistener);
DBCommandQueue.removeElementAt(1);
DBCommandQueue.removeElementAt(0);
return;
}
}
public String GetSelfUIN()
{//取得uin;
return strUin;
}
private int getInitSeqNo()
{//初始序列号的获得;取得系统时间,将时间转换成整数,循环右移一位
//然后再取其模除256的值为初始序列号;
Date date = new Date();
int i = (int)date.getTime() >>> 1;
return i % 256;
}
public void login(String s, String s1, HttpPosterListener httpposterlistener)
{//登录函数;第一个参数为用户号码,第二个参数为密码的MD5值,第三个参数为监听句柄;
String s2 = null;
strUin = s;
String s3 = MD5.toMD5(s1);
s2 = "VER=1.0&CMD=Login&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&PS=" + s3 + "&M5=1" + ("&LG=" + KQQMIDlet.sysString.language) + "&LC=9326B87B234E7235";
addDBCommand(s2, httpposterlistener);
}
public void getMsg(HttpPosterListener httpposterlistener)
{//取得消息;
Object obj = null;
for(int i = 0; i < listenerQueue.size(); i++)
{
String s = ((HttpPosterListener)listenerQueue.elementAt(i)).toString();
if(s.equals(httpposterlistener.toString()))
return;
}
String s1 = null;
s1 = "VER=1.0&CMD=GetMsgEx&SEQ=" + iSeqNo++ + "&UIN=" + strUin;
sendRequest(s1, httpposterlistener);//发送请求串;
}
public void sendMsg(String s, String s1, HttpPosterListener httpposterlistener)
{//发送消息,第一个参数为,第二个参数为消息内容,第三个消息为监听窗口;
String s2 = null;
s2 = "VER=1.0&CMD=CLTMSG&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&UN=" + s + "&MG=" + s1;
sendRequest(s2, httpposterlistener);
}
public void sendList(HttpPosterListener httpposterlistener)
{
String s = null;
s = "VER=1.0&CMD=List&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&TN=160&UN=0";
sendRequest(s, httpposterlistener);
}
public void getFriend(HttpPosterListener httpposterlistener)
{
String s = null;
s = "VER=1.0&CMD=Query_Stat&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&TN=50&UN=0";
sendRequest(s, httpposterlistener);
}
public void getInfor(String s, HttpPosterListener httpposterlistener)
{
String s1 = null;
s1 = "VER=1.0&CMD=GetInfo&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&LV=2" + "&UN=" + s;
addDBCommand(s1, httpposterlistener);
}
public void addFriend(String s, HttpPosterListener httpposterlistener)
{//加一个好友;第一个参数为,第二个参数为监听句柄;
String s1 = null;
s1 = "VER=1.0&CMD=AddToList&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&UN=" + s;
addDBCommand(s1, httpposterlistener);
}
public void ackAddFriend(String s, String s1, String s2, HttpPosterListener httpposterlistener)
{//应答加入朋友;第一个参数为,第二个参数为,第三个参数为,第四个参数为;
String s3 = null;
s3 = "VER=1.0&CMD=Ack_AddToList&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&UN=" + s + "&CD=" + s1 + "&RS=" + s2;
if(s1.equals("2"))
addDBCommand(s3, httpposterlistener);
else
sendRequest(s3, httpposterlistener);
}
public void delFriend(String s, HttpPosterListener httpposterlistener)
{
String s1 = null;
vDeleteItems.addElement(Integer.toString(iSeqNo));
vDeleteItems.addElement(s);
s1 = "VER=1.0&CMD=DelFromList&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&UN=" + s;
sendRequest(s1, httpposterlistener);
}
public void finger(String s, String s1, String s2, HttpPosterListener httpposterlistener)
{
String s3 = null;
s3 = "VER=1.0&CMD=Finger&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&AG=" + s + "&SX=" + s1 + "&PV=" + s2;
sendRequest(s3, httpposterlistener);
}
public void changeStat(String s, HttpPosterListener httpposterlistener)
{
String s1 = null;
s1 = "VER=1.0&CMD=Change_Stat&SEQ=" + iSeqNo++ + "&UIN=" + strUin + "&ST=" + s;
sendRequest(s1, httpposterlistener);
}
public void logout(HttpPosterListener httpposterlistener)
{
if(requestQueue.size() > 0)
{
KQQMIDlet.instance.quitApp();
return;
} else
{
bExit = true;
KQQMIDlet.mainForm.StopQQ();
String s = null;
s = "VER=1.0&CMD=Logout&SEQ=" + iSeqNo++ + "&UIN=" + strUin;
sendRequest(s, httpposterlistener);
return;
}
}
public synchronized void sendRequest(String s, HttpPosterListener httpposterlistener)
{
if(iSeqNo == 65535)
iSeqNo = 1;
requestQueue.addElement(s);
listenerQueue.addElement(httpposterlistener);
startToSend();
}
public void startToSend()
{
notify();
}
public void run()
{
Object obj = null;
Object obj1 = null;
goto _L1
_L8:
HttpPoster httpposter = this;
JVM INSTR monitorenter ;
goto _L2
_L5:
try
{
wait();
}
catch(InterruptedException interruptedexception)
{
System.out.println("error in httpposter-run");
}
if(!aborting)
{
if(requestQueue.size() == 0) goto _L5; else goto _L4
}
else
{ goto _L3
_L3:
httpposter;
JVM INSTR monitorexit ;
break; /* Loop/switch isn't completed */
}
_L4:
String s;
HttpPosterListener httpposterlistener;
s = (String)requestQueue.elementAt(0);
httpposterlistener = (HttpPosterListener)listenerQueue.elementAt(0);
httpposter;
JVM INSTR monitorexit ;
goto _L6
Exception exception;
exception;
httpposter;
JVM INSTR monitorexit ;
throw exception;
_L6:
doSend(s, httpposterlistener);
synchronized(this)
{
requestQueue.removeElementAt(0);
listenerQueue.removeElementAt(0);
}
_L1:
if(!aborting) goto _L8; else goto _L7
_L7:
}
private boolean doSend(String s, HttpPosterListener httpposterlistener)
{
HttpConnection httpconnection;
DataInputStream datainputstream;
DataOutputStream dataoutputstream;
String s1;
String s2;
boolean flag;
httpconnection = null;
datainputstream = null;
dataoutputstream = null;
s1 = null;
s2 = null;
flag = false;
boolean flag1;
httpconnection = (HttpConnection)Connector.open(KQQMIDlet.url, 3, true);
httpconnection.setRequestMethod("POST");
byte abyte0[] = PkgTools.convertUnicode2UTF8Byte(s);
httpconnection.setRequestProperty("Content-Length", "" + abyte0.length);
dataoutputstream = httpconnection.openDataOutputStream();
dataoutputstream.write(abyte0);
dataoutputstream.flush();
if(!bExit)
break MISSING_BLOCK_LABEL_165;
KQQMIDlet.instance.quitApp();
flag1 = true;
if(datainputstream != null)
try
{
datainputstream.close();
}
catch(IOException ioexception4) { }
if(dataoutputstream != null)
try
{
dataoutputstream.close();
}
catch(IOException ioexception5) { }
if(httpconnection != null)
try
{
httpconnection.close();
}
catch(IOException ioexception6) { }
return flag1;
datainputstream = httpconnection.openDataInputStream();
int i = (int)httpconnection.getLength();
byte abyte1[];
if(i != -1)
{
abyte1 = new byte[i];
datainputstream.readFully(abyte1);
} else
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
int j;
while((j = datainputstream.read()) != -1)
bytearrayoutputstream.write(j);
abyte1 = bytearrayoutputstream.toByteArray();
bytearrayoutputstream.close();
}
i = abyte1.length;
byte abyte2[] = new byte[i + 2];
abyte2[0] = (byte)(i >> 8);
abyte2[1] = (byte)i;
for(int k = 0; k < i; k++)
abyte2[k + 2] = abyte1[k];
ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte2);
DataInputStream datainputstream1 = new DataInputStream(bytearrayinputstream);
s1 = datainputstream1.readUTF();
datainputstream1.close();
bytearrayinputstream.close();
if(s1 == null)
{
flag = true;
s2 = "http respone null";
}
if(datainputstream != null)
try
{
datainputstream.close();
}
catch(IOException ioexception) { }
if(dataoutputstream != null)
try
{
dataoutputstream.close();
}
catch(IOException ioexception1) { }
if(httpconnection != null)
try
{
httpconnection.close();
}
catch(IOException ioexception2) { }
break MISSING_BLOCK_LABEL_553;
IOException ioexception3;
ioexception3;
flag = true;
s2 = "http connect error:" + ioexception3.getMessage();
if(datainputstream != null)
try
{
datainputstream.close();
}
catch(IOException ioexception7) { }
if(dataoutputstream != null)
try
{
dataoutputstream.close();
}
catch(IOException ioexception8) { }
if(httpconnection != null)
try
{
httpconnection.close();
}
catch(IOException ioexception9) { }
break MISSING_BLOCK_LABEL_553;
Exception exception;
exception;
if(datainputstream != null)
try
{
datainputstream.close();
}
catch(IOException ioexception10) { }
if(dataoutputstream != null)
try
{
dataoutputstream.close();
}
catch(IOException ioexception11) { }
if(httpconnection != null)
try
{
httpconnection.close();
}
catch(IOException ioexception12) { }
throw exception;
if(flag)
{
httpposterlistener.handleHttpError(s2);
return false;
} else
{
iNetErrorCnt = 0;
httpposterlistener.receiveHttpResponse(s1);
return true;
}
}
public void abort()
{
aborting = true;
synchronized(this)
{
notify();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -