////////////////////////////////////////////////////////// send_message() ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //int send_message(char*, char*, char*, char* ) 是短信发送接口函数,只要将手机号,密码,对方手机号和短信内容作为参数传过来,就可以发送短信了。 // void send_message(char* fromPhone, char* password, char* toPhone, char* dataSend) { static char *systemconfig_xml = NULL, *URL= NULL, *sipc_proxy = NULL, *SSIAppSignIn_xml = NULL, *domain, *fetion_num, *fetion_sip, *ssiapp_signin , *nonce, *cnonce; static char data[400], *login_xml_1=NULL, *login_xml_2=NULL, *login_request_1=NULL, *login_request_2=NULL, *login_1=NULL, *login_2=NULL, *server_response=NULL; char* response; //static char myname[200]; char *re_back; static char *data_send; char *ip="221.176.31.33"; char *port="8080"; domain = "fetion.com.cn"; //判断是否为空 if (fromPhone == NULL || password == NULL) return; /////////////// initalize /////////////////////////////////////////////// SSIAppSignIn_xml = SSIAppSignIn(fromPhone, password); //通过curl发送https请求,验证身份,并从网页获取相关信息 fetion_num = get_value(SSIAppSignIn_xml , "sip:", "@"); //从返回的xml中获取飞信号 fetion_num="64738765" fetion_sip = get_value(SSIAppSignIn_xml, "uri=\"", "\""); //从返回的xml中获取sip fetion_sip="sip:[email protected];p=xxxx" uri="sip:[email protected];p=6176" type="3" ////////////////// login ////////////////////////////////////// ///////////////////////////////////////// //登陆服务器,这是个标准的Digest Authentication验证过程 // login_xml_1 = "<args><device type=\"PC\" version=\"36\" client-version=\"3.3.0370\" /><caps value=\"simple-im;im-session;temp-group;personal-group\" /><events value=\"contact;permission;system-message;personal-group\" /><user-info attributes=\"all\" /><presence><basic value=\"400\" desc=\"\" /></presence></args>"; sprintf(data,"R %s SIP-C/2.0\r\nF: %s\r\nI: 1\r\nQ: 1 R\r\nL: %d\r\n\r\n", domain, fetion_num, strlen(login_xml_1)); data_send = strcating(data, login_xml_1); socket_init(ip,port); server_response = request(data_send); //通过sipc的request()函数和服务器进行sip交互过程 // ////nonce: // nonce = get_value(server_response, "nonce=\"", "\""); login_xml_2 = "<args><device type=\"PC\" version=\"36\" client-version=\"3.3.0370\" /><caps value=\"simple-im;im-session;temp-group;personal-group\" /><events value=\"contact;permission;system-message;personal-group\" /><user-info attributes=\"all\" /><presence><basic value=\"400\" desc=\"\" /></presence></args>"; // ////cnonce: // cnonce = get_cnonce(); // ////response: // response = make_response(fetion_num, password, domain, nonce, cnonce ); //getchar(); sprintf(data,"R %s SIP-C/2.0\r\nF: %s\r\nI: 1\r\nQ: 2 R\r\nA: Digest response=\"%s\",cnonce=\"%s\"\r\nL: %d\r\n\r\n", domain, fetion_num, response, cnonce, strlen(login_xml_2)); data_send = strcating(data, login_xml_2); server_response = request(data_send);//通过sipc的request()函数和服务器进行sip交互过程 re_back = get_value(server_response, "SIP-C/2.0 ","F"); ////////////////////////////////////////////////////////////// //sendSMS_toMyself( )发送短信 // sendSMS_toMyself( domain, fetion_num, fetion_sip, dataSend ); //sendSMS_toOther( domain, fetion_num, toPhone, dataSend ); sip_logout(domain, fetion_num); }
/* Examine a digest challenge: return 0 if it is a valid Digest challenge, * else non-zero. */ static int digest_challenge(auth_session *sess, struct auth_challenge *parms) { struct ne_md5_ctx tmp; unsigned char tmp_md5[16]; char password[NE_ABUFSIZ]; /* Verify they've given us the right bits. */ if (parms->alg == auth_alg_unknown || (parms->alg == auth_alg_md5_sess && !parms->qop_auth) || parms->realm == NULL || parms->nonce == NULL) { NE_DEBUG(NE_DBG_HTTPAUTH, "Invalid challenge."); return -1; } if (parms->stale) { /* Just a stale response, don't need to get a new username/password */ NE_DEBUG(NE_DBG_HTTPAUTH, "Stale digest challenge.\n"); } else { /* Forget the old session details */ NE_DEBUG(NE_DBG_HTTPAUTH, "In digest challenge.\n"); clean_session(sess); sess->realm = ne_strdup(parms->realm); /* Not a stale response: really need user authentication */ if (get_credentials(sess, password)) { /* Failed to get credentials */ return -1; } } sess->alg = parms->alg; sess->scheme = auth_scheme_digest; sess->nonce = ne_strdup(parms->nonce); sess->cnonce = get_cnonce(); /* TODO: add domain handling. */ if (parms->opaque != NULL) { sess->opaque = ne_strdup(parms->opaque); /* don't strip the quotes */ } if (parms->got_qop) { /* What type of qop are we to apply to the message? */ NE_DEBUG(NE_DBG_HTTPAUTH, "Got qop directive.\n"); sess->nonce_count = 0; sess->qop = auth_qop_auth; } else { /* No qop at all/ */ sess->qop = auth_qop_none; } if (!parms->stale) { /* Calculate H(A1). * tmp = H(unq(username-value) ":" unq(realm-value) ":" passwd) */ NE_DEBUG(NE_DBG_HTTPAUTH, "Calculating H(A1).\n"); ne_md5_init_ctx(&tmp); ne_md5_process_bytes(sess->username, strlen(sess->username), &tmp); ne_md5_process_bytes(":", 1, &tmp); ne_md5_process_bytes(sess->realm, strlen(sess->realm), &tmp); ne_md5_process_bytes(":", 1, &tmp); ne_md5_process_bytes(password, strlen(password), &tmp); memset(password, 0, sizeof password); /* done with that. */ ne_md5_finish_ctx(&tmp, tmp_md5); if (sess->alg == auth_alg_md5_sess) { unsigned char a1_md5[16]; struct ne_md5_ctx a1; char tmp_md5_ascii[33]; /* Now we calculate the SESSION H(A1) * A1 = H(...above...) ":" unq(nonce-value) ":" unq(cnonce-value) */ ne_md5_to_ascii(tmp_md5, tmp_md5_ascii); ne_md5_init_ctx(&a1); ne_md5_process_bytes(tmp_md5_ascii, 32, &a1); ne_md5_process_bytes(":", 1, &a1); ne_md5_process_bytes(sess->nonce, strlen(sess->nonce), &a1); ne_md5_process_bytes(":", 1, &a1); ne_md5_process_bytes(sess->cnonce, strlen(sess->cnonce), &a1); ne_md5_finish_ctx(&a1, a1_md5); ne_md5_to_ascii(a1_md5, sess->h_a1); NE_DEBUG(NE_DBG_HTTPAUTH, "Session H(A1) is [%s]\n", sess->h_a1); } else { ne_md5_to_ascii(tmp_md5, sess->h_a1); NE_DEBUG(NE_DBG_HTTPAUTH, "H(A1) is [%s]\n", sess->h_a1); } } NE_DEBUG(NE_DBG_HTTPAUTH, "I like this Digest challenge.\n"); return 0; }
/* Examine a digest challenge: return 0 if it is a valid Digest challenge, * else non-zero. */ static int digest_challenge(http_auth_session *sess, struct http_auth_chall *parms) { struct md5_ctx tmp; unsigned char tmp_md5[16]; char *password; /* Do we understand this challenge? */ if (parms->alg == http_auth_alg_unknown) { DEBUG(DEBUG_HTTPAUTH, "Unknown algorithm.\n"); return -1; } if ((parms->alg == http_auth_alg_md5_sess) && !(parms->qop_auth || parms->qop_auth_int)) { DEBUG(DEBUG_HTTPAUTH, "Server did not give qop with MD5-session alg.\n"); return -1; } if ((parms->realm==NULL) || (parms->nonce==NULL)) { DEBUG(DEBUG_HTTPAUTH, "Challenge missing nonce or realm.\n"); return -1; } if (parms->stale) { /* Just a stale response, don't need to get a new username/password */ DEBUG(DEBUG_HTTPAUTH, "Stale digest challenge.\n"); } else { /* Forget the old session details */ DEBUG(DEBUG_HTTPAUTH, "In digest challenge.\n"); clean_session(sess); sess->unq_realm = shave_string(parms->realm, '"'); /* Not a stale response: really need user authentication */ if (get_credentials(sess, &password)) { /* Failed to get credentials */ HTTP_FREE(sess->unq_realm); return -1; } } sess->alg = parms->alg; sess->scheme = http_auth_scheme_digest; sess->unq_nonce = shave_string(parms->nonce, '"'); sess->unq_cnonce = get_cnonce(); if (parms->domain) { if (parse_domain(sess, parms->domain)) { /* TODO: Handle the error? */ } } else { sess->domain = NULL; sess->domain_count = 0; } if (parms->opaque != NULL) { sess->opaque = ne_strdup(parms->opaque); /* don't strip the quotes */ } if (parms->got_qop) { /* What type of qop are we to apply to the message? */ DEBUG(DEBUG_HTTPAUTH, "Got qop directive.\n"); sess->nonce_count = 0; if (parms->qop_auth_int) { sess->qop = http_auth_qop_auth_int; } else { sess->qop = http_auth_qop_auth; } } else { /* No qop at all/ */ sess->qop = http_auth_qop_none; } if (!parms->stale) { /* Calculate H(A1). * tmp = H(unq(username-value) ":" unq(realm-value) ":" passwd) */ DEBUG(DEBUG_HTTPAUTH, "Calculating H(A1).\n"); md5_init_ctx(&tmp); md5_process_bytes(sess->username, strlen(sess->username), &tmp); md5_process_bytes(":", 1, &tmp); md5_process_bytes(sess->unq_realm, strlen(sess->unq_realm), &tmp); md5_process_bytes(":", 1, &tmp); if (password != NULL) md5_process_bytes(password, strlen(password), &tmp); md5_finish_ctx(&tmp, tmp_md5); if (sess->alg == http_auth_alg_md5_sess) { unsigned char a1_md5[16]; struct md5_ctx a1; char tmp_md5_ascii[33]; /* Now we calculate the SESSION H(A1) * A1 = H(...above...) ":" unq(nonce-value) ":" unq(cnonce-value) */ md5_to_ascii(tmp_md5, tmp_md5_ascii); md5_init_ctx(&a1); md5_process_bytes(tmp_md5_ascii, 32, &a1); md5_process_bytes(":", 1, &a1); md5_process_bytes(sess->unq_nonce, strlen(sess->unq_nonce), &a1); md5_process_bytes(":", 1, &a1); md5_process_bytes(sess->unq_cnonce, strlen(sess->unq_cnonce), &a1); md5_finish_ctx(&a1, a1_md5); md5_to_ascii(a1_md5, sess->h_a1); DEBUG(DEBUG_HTTPAUTH, "Session H(A1) is [%s]\n", sess->h_a1); } else { md5_to_ascii(tmp_md5, sess->h_a1); DEBUG(DEBUG_HTTPAUTH, "H(A1) is [%s]\n", sess->h_a1); } HTTP_FREE(password); } DEBUG(DEBUG_HTTPAUTH, "I like this Digest challenge.\n"); return 0; }