📜 ⬆️ ⬇️

Working with ICQ in Java

Prehistory


Once we decided to create our own microblogging with blackjack and whores c chess and poetess. At first they made the site, but it quickly became clear that it was not enough to implement the idea. It was necessary to work with messages through Jabber and ICQ.
We started with a simple one - with jabber. There were no problems here - we wrote in Java, so we screwed the Smack API and it all worked. But, as it is not sad, but the most popular IM protocol is still ICQ ...

Task


So, the task: log in to ICQ, receive and send messages, understand X-statuses, work with Cyrillic.

Consider solutions.
')

Solutions


* icq java library - find and use a certain analogue of the Smack API for ICQ
* PyICQt - use personal ICQ transport and work with it through the same Smack API
* score on ICQ and continue to use the Orthodox Jabber - no comment)))

icq java library

The method of deep googling on the above query " icq java library " was able to find the following:

Library - Last Updated
exeQ - 2539 days ago
OpenMIM - 240 days ago
joscar - <30 days ago

The parameter “Last update” describes the abandonment of the library. When choosing the ICQ library, it is absolutely necessary to take into account its abandonment. The fact is that the owner of ICQ is AOL Corporation. Very kind and cheerful people work there who change the ICQ protocol for the sake of lulz about a couple of times a year, which is why third-party clients and libraries SUDDENLY stop working until the authors fix them.

For obvious reasons, only joscar deserves close attention from the listed libraries, but at the time of this writing, he had serious problems with Cyrillic, but there is hope that they will be eliminated in the near future.

In the meantime, we move on to the next method.

PyICQt

Argued that ICQ-transport - is evil. And this is true, but there is one nuance: a public ICQ-transport is evil.
Problems in the work of public ICQ-transports are related to the fact that ICQ servers severely limit the number of connections from a single client IP, so the transport can normally serve only a very small number of clients.
Public transport does not suit us, then you have to raise your own.

The procedure for installing / configuring PyICQt + EJabberd is quite simple and described, for example, here . We are more interested in the client part.

So, we raised a jabber server located at jabber.joyreactor.ru and icq-transport on it with the address icq.jabber.joyreactor.ru.

Now you need to create a user, on behalf of which we will connect:

ejabberdctl register username jabber.joyreactor.ru password

Next, log in on his behalf to our server with any jabber-client and add our user icq-transport using Service Discovery. All is ready! You can go to Java.

We need the Smack API :

import org.jivesoftware.smack. * ;


and the following information:

Roster. setDefaultSubscriptionMode ( SubscriptionMode. accept_all ) ;
XMPPConnection icqConnection = new XMPPConnection ( ICQ_HOST ) ;
icqConnection. connect ( ) ;
SASLAuthentication. supportSASLMechanism ( "PLAIN" , 0 ) ; // To connect to EJabberd
icqConnection. login ( ICQ_LOGIN, ICQ_PASS ) ;


Connect:

Roster. setDefaultSubscriptionMode ( SubscriptionMode. accept_all ) ;
XMPPConnection icqConnection = new XMPPConnection ( ICQ_HOST ) ;
icqConnection. connect ( ) ;
SASLAuthentication. supportSASLMechanism ( "PLAIN" , 0 ) ; // To connect to EJabberd
icqConnection. login ( ICQ_LOGIN, ICQ_PASS ) ;

set handlers:

RosterListener rosterListener = new RosterListener ( ) {
public void entriesAdded ( Collection < String > arg0 ) {
Roster roster = connection. getRoster ( ) ;
RosterGroup gr = roster. getGroup ( "Users" ) ;
if ( gr == null )
gr = roster createGroup ( "Users" ) ;
for ( String entry : arg0 ) {
try {
String [ ] groups = { "Users" } ;
if ( roster. getEntry ( entry ) == null )
roster. createEntry ( entry, null , groups ) ;
} catch ( XMPPException ex ) {
// TODO: Handle exception.
}
}
}
public void entriesUpdated ( Collection < String > arg0 ) {
Roster roster = connection. getRoster ( ) ;
RosterGroup gr = roster. getGroup ( "Users" ) ;
if ( gr == null )
gr = roster createGroup ( "Users" ) ;
for ( String entry : arg0 ) {
try {
String [ ] groups = { "Users" } ;
if ( roster. getEntry ( entry ) == null )
roster. createEntry ( entry, null , groups ) ;
} catch ( XMPPException ex ) {
// TODO: Handle exception.
}
}
}
public void entriesDeleted ( Collection < String > arg0 ) { }
public void presenceChanged ( Presence packet ) {
try {
org. jivesoftware . smack packet . Presence prs = ( org. Jivesoftware . Smack . Packet . Presence ) packet ;
if ( ! prs. getFrom ( ) . split ( "@" ) [ 1 ] . equalsIgnoreCase ( ICQ_TRANSPORT ) )
// TODO: Process presence.
} catch ( Exception ex ) {
// TODO: Handle exception.
}
}
} ;
PacketListener icqListener = new PacketListener ( ) {
public void processPacket ( Packet packet ) {
try {
org. jivesoftware . smack packet . Message msg = ( org. Jivesoftware . Smack . Packet . Message ) packet ;
if ( msg. getType ( ) ! = org. jivesoftware . smack . packet . Message . Type . error &&
msg. getFrom ( ) . split ( "@" ) [ 1 ] . equalsIgnoreCase ( ICQ_TRANSPORT ) )
// TODO: Process message.
} catch ( Exception ex ) {
// TODO: Handle exception.
}
}
} ;
icqConnection. getRoster ( ) . addRosterListener ( icqRosterListener ) ;
icqConnection. addPacketListener ( icqListener, new PacketTypeFilter ( org. jivesoftware . smack . packet . Message . class ) ) ;
send message:

org. jivesoftware . smack packet . Message message = new org. jivesoftware . smack packet . Message ( "587641264" + "@" + ICQ_TRANSPORT ) ;
message. setBody ( "Hello world !!!" ) ;
icqConnection. sendPacket ( message ) ;


Morality


During the solution of the problem, we encountered many problems, the main of which is the rapid obsolescence of the ICQ protocol. We were able to bypass only with the help of personal ICQ-transport, which, as it turned out, is relatively easy to configure.
Sources here .

It would be interesting to hear about a similar experience with you.

Source: https://habr.com/ru/post/79911/


All Articles