Mercurial > pidgin
diff src/protocols/msn/soap.c @ 19788:8b4653986e8e
[gaim-migrate @ 16600]
change to add SOAP HTTP header retrieve
Now Can do the OIM Message XML process
submitted by Ma Yuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sun, 30 Jul 2006 13:44:34 +0000 |
parents | 852b32710df0 |
children | 4f21c73a0c48 |
line wrap: on
line diff
--- a/src/protocols/msn/soap.c Sun Jul 23 12:19:10 2006 +0000 +++ b/src/protocols/msn/soap.c Sun Jul 30 13:44:34 2006 +0000 @@ -117,7 +117,9 @@ msn_soap_free_write_buf(soapconn); /*close ssl connection*/ - gaim_ssl_close(soapconn->gsc); + if(soapconn->gsc != NULL){ + gaim_ssl_close(soapconn->gsc); + } soapconn->gsc = NULL; g_free(soapconn); @@ -199,41 +201,104 @@ return; } - body_start = (char *)g_strstr_len(soapconn->read_buf, soapconn->read_len,"\r\n\r\n"); - if(!body_start){ - return; + if (strstr(soapconn->read_buf, "HTTP/1.1 302") != NULL) + { + /* Redirect. */ + char *location, *c; + + location = strstr(soapconn->read_buf, "Location: "); + if (location == NULL) + { + msn_soap_free_read_buf(soapconn); + + return; + } + location = strchr(location, ' ') + 1; + + if ((c = strchr(location, '\r')) != NULL) + *c = '\0'; + + /* Skip the http:// */ + if ((c = strchr(location, '/')) != NULL) + location = c + 2; + + if ((c = strchr(location, '/')) != NULL) + { + g_free(soapconn->login_path); + soapconn->login_path = g_strdup(c); + + *c = '\0'; + } + + g_free(soapconn->login_host); + soapconn->login_host = g_strdup(location); + + gaim_ssl_connect(session->account, soapconn->login_host, + GAIM_SSL_DEFAULT_PORT, msn_soap_connect_cb, + msn_soap_error_cb, soapconn); } - body_start += 4; - -// gaim_debug_misc("msn", "Soap Read: {%s}\n", soapconn->read_buf); + else if (strstr(soapconn->read_buf, "HTTP/1.1 401 Unauthorized") != NULL) + { + const char *error; - /* we read the content-length*/ - length_start = strstr(soapconn->read_buf, "Content-Length: "); - length_start += strlen("Content-Length: "); - length_end = strstr(length_start, "\r\n"); - body_len = g_strndup(length_start,length_end - length_start); + if ((error = strstr(soapconn->read_buf, "WWW-Authenticate")) != NULL) + { + if ((error = strstr(error, "cbtxt=")) != NULL) + { + const char *c; + char *temp; + + error += strlen("cbtxt="); + + if ((c = strchr(error, '\n')) == NULL) + c = error + strlen(error); + + temp = g_strndup(error, c - error); + error = gaim_url_decode(temp); + g_free(temp); + } + } - /*setup the conn body */ - soapconn->body = body_start; - soapconn->body_len = atoi(body_len); -// gaim_debug_misc("MaYuan","content length :%d",soapconn->body_len); + msn_session_set_error(session, MSN_ERROR_SERV_UNAVAILABLE, error); + } + else if (strstr(soapconn->read_buf, "HTTP/1.1 200 OK")) + { + /*OK! process the SOAP body*/ + body_start = (char *)g_strstr_len(soapconn->read_buf, soapconn->read_len,"\r\n\r\n"); + if(!body_start){ + return; + } + body_start += 4; + + // gaim_debug_misc("msn", "Soap Read: {%s}\n", soapconn->read_buf); - if(soapconn->read_len < body_start - soapconn->read_buf + atoi(body_len)){ - return; - } + /* we read the content-length*/ + length_start = strstr(soapconn->read_buf, "Content-Length: "); + length_start += strlen("Content-Length: "); + length_end = strstr(length_start, "\r\n"); + body_len = g_strndup(length_start,length_end - length_start); - g_free(body_len); + /*setup the conn body */ + soapconn->body = body_start; + soapconn->body_len = atoi(body_len); + // gaim_debug_misc("MaYuan","content length :%d",soapconn->body_len); + + if(soapconn->read_len < body_start - soapconn->read_buf + atoi(body_len)){ + return; + } + + g_free(body_len); #if 1 - /*remove the read handler*/ - gaim_input_remove(soapconn->input_handler); - soapconn->input_handler = -1; + /*remove the read handler*/ + gaim_input_remove(soapconn->input_handler); + soapconn->input_handler = -1; #endif - /*call the read callback*/ - if(soapconn->read_cb != NULL){ - soapconn->read_cb(soapconn,source,0); - } + /*call the read callback*/ + if(soapconn->read_cb != NULL){ + soapconn->read_cb(soapconn,source,0); + } #if 0 /*clear the read buffer*/ msn_soap_free_read_buf(soapconn); @@ -241,9 +306,10 @@ /*remove the read handler*/ gaim_input_remove(soapconn->input_handler); soapconn->input_handler = -1; -// gaim_ssl_close(soapconn->gsc); -// soapconn->gsc = NULL; + // gaim_ssl_close(soapconn->gsc); + // soapconn->gsc = NULL; #endif + } } void @@ -360,7 +426,7 @@ /*free read buffer*/ msn_soap_free_read_buf(soapconn); -// gaim_debug_info("MaYuan","send to contact server{%s}\n",request_str); + gaim_debug_info("MaYuan","send to server{%s}\n",request_str); msn_soap_write(soapconn,request_str,written_cb); }