⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsde.c

📁 这个项目里有两个关于收、发GSM 手机短信的C语言程序
💻 C
字号:
/* * send sms through www.sms-kostenlos.de  * * Authors:     Gerhard Kh黱y <e9625442@student.tuwien.ac.at> *  * TODO:         * * Fixes: * * For license terms, see the file COPYING in the project directory. */#include <stdio.h>#include <string.h>#include <glib.h>#include <gsms-plugin.h>#include "networks.h"#define SERVERHOST      "www.sms.de"#define PORT            80#define MAXMSGLEN       146#define LINE            128gint init_plugin (PluginData *pd);static void destroy_plugin (PluginData *pd);static gint send_sms(PluginData *pd, gchar * text, gchar * tel); static gchar * get_networkkey (gchar *number);static gchar *get_networkkey(gchar *number) {	gint i=0;	     	while(networks[i] != NULL) {		if(strstr(number, networks[i]) != NULL)			return (networks[i+1]);		else			i+=2;	}				return NULL;}static gint send_sms(PluginData *pd, gchar * text, gchar * tel){	gchar *text_ue, *number_ue, *network_ue; //I should free them 	gchar *networkkey, *cookie, *tmp;	GSmsHttp ht;	GsmsHttpConnection *c;	GsmsHttpResponse *response;       	/*Cut message */	/*Since you can enter as many chars as you want at the website, it's not my problem */	//tel[MAXMSGLEN]=0;		if((networkkey=get_networkkey(tel)) == NULL) {		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not find networkkey");		return -1;	}		text_ue= gsms_http_url_encode(text);	number_ue = gsms_http_url_encode(tel);	network_ue = gsms_http_url_encode(networkkey);	if( (c = gsms_plugin_http_connect(SERVERHOST, PORT)) == NULL) {		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not open connection");		return -1;	}				/* GET start site */	ht.protokoll = g_strdup("HTTP/1.0");	ht.accept = g_strdup("image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, "			     "image/png, */*");	ht.acceptlang = g_strdup("en");	ht.acceptchar = g_strdup("iso-8859-1,*,utf-8");	ht.connection = g_strdup("Keep-Alive");	ht.cookie = NULL;	ht.useragent = g_strdup("Mozilla/4.73 [en] (X11; U; Linux)");	ht.method = g_strdup_printf("GET");	ht.url = g_strdup_printf("/send.php3");	ht.host = g_strdup_printf("www.sms.de");	ht.referer = g_strdup_printf("http://www.sms.de/");	ht.cookie = NULL;	ht.body = NULL;	ht.message = NULL;		if((response = gsms_plugin_http_request(c,&ht)) == NULL) {		gsms_plugin_http_response_free(response);                                  		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not send http request");		return -1;	}	/* Accept the AGB */	ht.protokoll = g_strdup("HTTP/1.0");	ht.accept = g_strdup("image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, "			     "image/png, */*");	ht.acceptlang = g_strdup("en");	ht.acceptchar = g_strdup("iso-8859-1,*,utf-8");	ht.connection = g_strdup("Keep-Alive");	ht.cookie = NULL;	ht.useragent = g_strdup("Mozilla/4.73 [en] (X11; U; Linux)");	ht.method = g_strdup_printf("GET");	ht.url = g_strdup_printf("/send.php3?action=accept");	ht.host = g_strdup_printf("www.sms.de");	ht.referer = g_strdup_printf("http://www.sms.de/send.php3");	ht.cookie = NULL;	ht.body = NULL;	ht.message = NULL;	if((response = gsms_plugin_http_request(c,&ht)) == NULL) {		gsms_plugin_http_response_free(response);                                  		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not send http request");		return -1;	}	/* Get cookie from header */	if ((tmp = strstr(response->header, "Set-Cookie:")) == NULL) {		gsms_plugin_http_response_free(response);                                  		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not find cookie");		return -1;	}	        cookie = tmp + strlen("Set-Cookie: ");	tmp = index(cookie,';');	*tmp = 0;	/* Send the request */	ht.protokoll = g_strdup("HTTP/1.0");	ht.accept = g_strdup("image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,"			     "image/png, */*");	ht.acceptlang = g_strdup("en");	ht.acceptchar = g_strdup("iso-8859-1,*,utf-8");	ht.connection = g_strdup("Keep-Alive");	ht.useragent = g_strdup("Mozilla/4.73 [en] (X11; U; Linux)");	ht.method = g_strdup_printf("POST");	ht.url = g_strdup_printf("/send.php3");	ht.host = g_strdup_printf("www.sms.de");	ht.referer = g_strdup_printf("http://www.sms.de/send.php3?action=form2&networkkey="				     "%s&x=54&y=11",networkkey);	ht.ctype = g_strdup_printf("application/x-www-form-urlencoded");	ht.cookie = g_strdup_printf("%s",cookie);	ht.body = g_strdup_printf("action=send&networkkey=%s&number=%s&message=%s"				  "&redir=51&x=58&y=39",network_ue, number_ue, text_ue);	ht.message = NULL;	if((response = gsms_plugin_http_request(c,&ht)) == NULL) {		gsms_plugin_http_response_free(response);                                  		g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,		      "Could not send http request");		return -1;	}    		gsms_plugin_http_response_free(response);	gsms_plugin_http_close(c);	return 0;}voiddestroy_plugin (PluginData *pd){/* TODO FREE	g_free(pd->networks->data); */}gintinit_plugin (PluginData *pd){	GSMNetwork *network;	gint i;	/* initialize */	pd->destroy_plugin = destroy_plugin;	pd->send_sms = send_sms;	pd->name = "www.sms.de";	pd->authors = "Gerhard Khueny <e9625442@student.tuwien.ac.at>";	pd->info = "There is no inforamtion about the supported providers";        pd->default_priority = 250;	for(i=0; networks[i] != NULL;) {			network = g_new(GSMNetwork, 1);			network->prefix = networks[i++];			network->name = networks[i++];		pd->networks = g_slist_append(pd->networks, network);	}	return PLUGIN_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -