Wednesday, April 15, 2009

File post in OCS using ucma api:

The following registry entry changes are required.

 

Go to command prompt, type “regedit”.

 

Go to the following path:

 

HKEY_CURRENT_USER\Software\Policies\Microsoft\Communicator

 

Create a new DWORD value with value name “AllowUnencryptedFileTransfer” and value as “1”.


 

 

File Post

Bot posts a file to person “x”.

Preconditions:

1)      Both person “x” and bot must be logged in.

2)      An IM session must be created between Bot and person “x”.

Steps:

1)      Bot sends a file transfer invite message to person “x” which has the following format:

 

Content-Type: text/x-msmsgsinvite; charset=UTF-8

 

Application-Name: File Transfer\r\n

Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}\r\n

Invitation-Command: INVITE\r\n

Invitation-Cookie: <invitation cookie – random number>\r\n

Application-File: <file name to be transfered>\r\n

Application-FileSize: <file size>\r\n

Connectivity: N\r\n \r\n

 

 

2)      Person “x” gets the request, and can do 2 things – accept/reject;

 

If person “x” accepts the following details are received by the bot.

 

Content-Type: text/x-msmsgsinvite; charset=UTF-8

 

Invitation-Command: ACCEPT\r\n

Invitation-Cookie: <invitation cookie – same as previous number>\r\n

IP-Address: <IP address – where to connect>\r\n

Port: <port number – which port to connect>\r\n

PortX: <alternative port - can be ignored>\r\n

AuthCookie: cookie – to be used for authentication during FTP>\r\n

Request-Data: IP-Address:\r\n

 

       If person “x” cancels the request then,

 

Content-Type: text/x-msmsgsinvite; charset=UTF-8

 

Invitation-Command: ACCEPT\r\n

Invitation-Cookie: <invitation cookie – same as previous number>\r\n

Cancel-Code: <reason for cancellation>

 

On cancel command, the Bot should just ignore the message and not transfer the file. The below steps will not be followed.

 

3)      The above 2 messages are the sent using SIP messages. After this the file transfer happens using the MSNFTP protocol.

 

 

Person “x” client creates a TCP server and starts listening at the port (the one sent in the 2nd message).

The Bot creates a TCP client and connects to IP address : Port (the one sent in the 2nd message).

        As soon as the Bot connects, it receives a version command from Person “x’s” client:

 

VER MSNFTP

 

On receiving the version command, the Bot sends a version command:

 

VER MSNFTP

 

 

4)      The person “x’s” client sends an authentication message in the following format:

 

USR <username> <auth cookie>

 

Here the username is the username which wants to receive the file and the auth cookie is the one which was sent in the 2nd message.

 

The Bot verifies if it is the same username and auth cookie, if same it sends a FIL command in the following format:

 

FIL <File-size>

 

5)      The person “x’s” client on receiving the FIL command, sends a Transfer command in the following format:

 

TFR

 

6)      On receiving the TFR command, the Bot starts transferring the file bytes as packets in the following way:

 

The packet size is 2048 bytes:

Bytes header + 2045 bytes body

§  Headers: 3 bytes

·         1st byte

¨       ‘0’ indicate file not yet transferred

¨       ‘1’ indicate file is transferred

·         2nd and 3rd bytes indicates the size of the body:

                                                   Body size = 2nd byte + (3rd byte x 256)

 

At the end, the Bot transfers 3 bytes  header 1,0,0

·         1st byte

¨       ‘0’ indicate file not yet transferred

·         2nd and 3rd bytes indicates the size of the body:

                                                   Body size = 2nd byte + (3rd byte x 256)

                                                                    = 0 + 0 = 0

7)      The person “x’s” client sends a BYE command in the following format:

 

BYE <code>

 

The code could be as follows:

 

      2147942405               Failure: receiver is out of disk space

2164261682               Failure: receiver cancelled the transfer

      2164261683               Failure: sender has cancelled the transfer

      2164261694               Failure: connection is blocked

      16777987                   Success

      16777989                   Success

 

 

8)      At any time, the a CCL command can be sent by the person “x’s” client indicating that the person “x’s” client has cancelled the file transfer, in which case the file transfer should be stopped immediately and the TCP client connection should be closed.

 

CCL

 

If a BYE command is sent by person “x’s” client then the TCP client connection should be closed.

 

 

 

 

 

File Post

Person “x” posts a file to Bot.

Preconditions:

3)      Both person “x” and bot must be logged in.

4)      An IM session must be created between Bot and person “x”.

Steps:

1)      Person “x”  sends a file transfer invite message to Bot which has the following format:

 

Content-Type: text/x-msmsgsinvite; charset=UTF-8

 

Application-Name: File Transfer\r\n

Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}\r\n

Invitation-Command: INVITE\r\n

Invitation-Cookie: <invitation cookie – random number>\r\n

Application-File: <file name to be transfered>\r\n

Application-FileSize: <file size>\r\n

Connectivity: N\r\n

Encryption: S

 

 

2)      Bot gets the request

 

Bot accepts the file transfer request by sending the following message:

 

Content-Type: text/x-msmsgsinvite; charset=UTF-8

 

Invitation-Command: ACCEPT\r\n

Invitation-Cookie: <invitation cookie – same as previous number>\r\n

IP-Address: <IP address – where to connect>\r\n

Port: <port number – which port to connect>\r\n

AuthCookie: cookie – to be used for authentication during FTP>\r\n

Request-Data: IP-Address:\r\n

Sender-Connect: TRUE\r\n \r\n

 

3)      The above 2 messages are the sent using SIP messages. After this the file transfer happens using the MSNFTP protocol.

 

 

Bot client creates a TCP server and starts listening at the port (the one sent in the 2nd message).

The person client “x” creates a TCP client and connects to IP address: Port (the one sent in the 2nd message).

        As soon as the person “x” client connects, the bot sends a version command as follows:

VER MSNFTP

 

On receiving the version command, the Person “x’s” client sends a version command:

VER MSNFTP

 

 

4)      The Bot sends an authentication message in the following format:

 

USR <username> <auth cookie>

 

Here the username is the username which wants to receive the file and the auth cookie is the one which was sent in the 2nd message.

 

The Person “x’s” verifies if it is the same username and auth cookie, if same it sends a FIL command in the following format:

 

FIL <File-size>

 

5)      The Bot on receiving the FIL command, sends a Transfer command in the following format:

 

TFR

 

6)      On receiving the TFR command, the Person “x’s” client starts transferring the file bytes as packets in the following way:

 

The packet size is 2048 bytes:

Bytes header + 2045 bytes body

§  Headers: 3 bytes

·         1st byte

¨       ‘0’ indicate file not yet transferred

¨       ‘1’ indicate file is transferred

·         2nd and 3rd bytes indicates the size of the body:

                                                   Body size = 2nd byte + (3rd byte x 256)

 

The bot understand this format and captures the byte body accordingly.

 

7)      The person Bot sends a BYE command in the following format:

 

BYE 16777989

 

Indicating that the file transfer was successful.

 

If any exception occurred in between, then the Bot should send a cancelation command as follows:

 

CCL

 

Then the Bot should disconnect the server and close the connection to free the port.

The file is constructed using the bytes.