Guest User

Untitled

a guest
Feb 11th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. static inline void
  2. oim_send_request (PnNode *conn,
  3. OimRequest *oim_request)
  4. {
  5. gchar *body;
  6. gchar *header;
  7. gsize body_len;
  8.  
  9. pn_log ("begin");
  10.  
  11. body = g_strdup_printf ("<?xml version=\"1.0\" encoding=\"utf-8\"?>",
  12. "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">",
  13. "<soap:Header>",
  14. "<From memberName=\"%s\" friendlyName=\"%s%s%s\" xml:lang=\"nl-nl\" proxy=\"MSNMSGR\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\" msnpVer=\"MSNP13\" buildVer=\"8.0.0328\"/>",
  15. "<To memberName=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>",
  16. "<Ticket passport=\"%s\" appid=\"%s\" lockkey=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>",
  17. "<Sequence xmlns=\"http://schemas.xmlsoap.org/ws/2003/03/rm\">",
  18. "<Identifier xmlns=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">http://messenger.msn.com</Identifier>",
  19. "<MessageNumber>%i</MessageNumber>",
  20. "</Sequence>",
  21. "</soap:Header>",
  22. "<soap:Body>",
  23. "<MessageType xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\">%s</MessageType>",
  24. "<Content xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\">MIME-Version: 1.0",
  25. "Content-Type: text/plain; charset=UTF-8",
  26. "Content-Transfer-Encoding: base64",
  27. "X-OIM-Message-Type: OfflineMessage",
  28. "X-OIM-Run-Id: %s",
  29. "X-OIM-Sequence-Num: %i",
  30. "\r\n",
  31. "%s",
  32. "</Content>",
  33. "</soap:Body>",
  34. "</soap:Envelope>",
  35. memberName,
  36. "=?utf-8?B?", pecan_base64_encode (friendly_name), "?=",
  37. memberName,
  38. passport,
  39. appid,
  40. lockkey, /** @todo session->lockkey ? */
  41. MessageNumber = X-OIM-Sequence-Num, /** @todo ++contact->sent_oims ? */
  42. "text",
  43. X-OIM-Run-Id,
  44. MessageNumber = X-OIM-Sequence-Num, /** @todo ++contact->sent_oims ? */
  45. purple_base64_encode (str));
  46.  
  47. body_len = strlen (body);
  48.  
  49. header = g_strdup_printf ("POST /OimWS/oim.asmx HTTP/1.1\r\n"
  50. "Accept: */*\r\n"
  51. "SOAPAction: \"http://messenger.msn.com/ws/2004/09/oim/Store\"\r\n"
  52. "Content-Type: text/xml; charset=utf-8\r\n"
  53. "Content-Length: %" G_GSIZE_FORMAT "\r\n"
  54. "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
  55. "Host: %s\r\n"
  56. "Connection: Keep-Alive\r\n"
  57. "Cache-Control: no-cache\r\n"
  58. /* "Cookie: MSPAuth=%s\r\n" */
  59. "\r\n%s",
  60. body_len,
  61. "ows.messenger.msn.com",
  62. /* session->passport_info.mspauth, */
  63. body);
  64.  
  65. g_free (body);
  66.  
  67. pn_debug ("header=[%s]", header);
  68. /* pn_debug ("body=[%s]", body); */
  69.  
  70. {
  71. gsize len;
  72. pn_node_write (conn, header, strlen (header), &len, NULL);
  73. pn_debug ("write_len=%d", len);
  74. }
  75.  
  76. g_free (header);
  77.  
  78. pn_log ("end");
  79. }
  80.  
  81. static void
  82. read_cb (PnNode *conn,
  83. gpointer data)
  84. {
  85. OimRequest *oim_request;
  86. GIOStatus status = G_IO_STATUS_NORMAL;
  87. gchar *str = NULL;
  88.  
  89. oim_request = data;
  90.  
  91. gsize terminator_pos;
  92.  
  93. status = pn_parser_read_line (oim_request->parser, &str, NULL, &terminator_pos, NULL);
  94.  
  95. if (status == G_IO_STATUS_AGAIN)
  96. return;
  97.  
  98. if (status != G_IO_STATUS_NORMAL)
  99. goto leave;
  100.  
  101. if (str)
  102. {
  103. if (strcmp (str, "HTTP/1.1 200 OK") == 0)
  104. goto leave; /** is this correct? */
  105.  
  106. g_free (str);
  107. }
  108.  
  109. while (oim_request->parser_state < 1)
  110. {
  111. gsize terminator_pos;
  112.  
  113. status = pn_parser_read_line (oim_request->parser, &str, NULL, &terminator_pos, NULL);
  114.  
  115. if (status == G_IO_STATUS_AGAIN)
  116. return;
  117.  
  118. if (status != G_IO_STATUS_NORMAL)
  119. goto leave;
  120.  
  121. if (str)
  122. {
  123. str[terminator_pos] = '\0';
  124.  
  125. /* now comes the content */
  126. if (str[0] == '\0')
  127. oim_request->parser_state++;
  128.  
  129. g_free (str);
  130. }
  131. }
  132.  
  133. while (oim_request->parser_state == 1)
  134. {
  135. gsize terminator_pos;
  136.  
  137. status = pn_parser_read_line (oim_request->parser, &str, NULL, &terminator_pos, NULL);
  138.  
  139. if (status == G_IO_STATUS_AGAIN)
  140. return;
  141.  
  142. if (status != G_IO_STATUS_NORMAL)
  143. goto leave;
  144.  
  145. if (str)
  146. {
  147. str[terminator_pos] = '\0';
  148.  
  149. if (strncmp (str, "<LockKeyChallenge xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\">", 67) == 0)
  150. {
  151. /** @todo: save the lockkey in session->lockkey */
  152. /** @todo: resend the message */
  153. goto leave; /** is this correct? */
  154. }
  155.  
  156. /* now comes the content */
  157. if (str[0] == '\0')
  158. oim_request->parser_state++;
  159.  
  160. g_free (str);
  161. }
  162. }
  163.  
  164. leave:
  165. pn_node_close (conn);
  166. next_request (oim_request->oim_session);
  167. }
Advertisement
Add Comment
Please, Sign In to add comment