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

📄 plugin_if.c

📁 GNOME下的短信息发送中心
💻 C
字号:
/* * plugin interface: this functions can be used by plugin writers to *                   make their work easier - protypes for the functions *                   are included in gsms-plugin.h * * Authors:     Michael Jochum <e9725005@stud3.tuwien.ac.at> *              Gerhard Khueny <e9625442@student.tuwien.ac.at> * * TODO:         * * Fixes: * * For license terms, see the file COPYING in the project directory. */#include <config.h>#include <string.h>#include <stdio.h>#include <gnome.h>#include <pref.h>#include <sock.h>#include <mail.h>#include <smtp.h>#include <httpr.h>#include <http.h>#define GSMS_PLUGIN#include <gsms-plugin.h>#undef GSMS_PLUGIN#define LINE            128voidgsms_plugin_config_save(PluginData *pd, const gchar *str){	gnome_config_push_prefix ("/gsms/Pluigin_Config/");	gnome_config_set_string(pd->name, str);	gnome_config_pop_prefix();	gnome_config_sync ();}gchar *gsms_plugin_config_load(PluginData *pd){	gchar *tmp;	gnome_config_push_prefix ("/gsms/Pluigin_Config/");	tmp = gnome_config_get_string(pd->name);	gnome_config_pop_prefix();	return g_strdup(tmp);}GsmsHttpConnection *gsms_plugin_http_connect(gchar *host, guint16 port) {	gchar *proxy = NULL;	if(configuration.http_proxy_enabled)		proxy = configuration.http_proxy;		return gsms_http_connect(host, port, proxy, 				 configuration.http_proxy_port,				 configuration.net_timeout);}GsmsHttpResponse * gsms_plugin_http_request(GsmsHttpConnection *c, GSmsHttp *ht) {	return gsms_http_request(c,ht);}void gsms_plugin_http_close(GsmsHttpConnection *c) {	gsms_http_close(c);}voidgsms_plugin_http_response_free(GsmsHttpResponse *response){	gsms_http_response_free(response);}gchar *gsms_plugin_http_request_simple(GsmsHttpConnection *c, gchar *url,	gchar *referer, gchar *method, gchar *ctype, gchar *body){	GSmsHttp *ht;	GsmsHttpResponse *r;	gchar *tmp;	ht = g_new0(GSmsHttp,1);	if(body)		ht->body = g_strdup(body);	if(method)		ht->method = g_strdup(method);	else		ht->method = g_strdup("GET");	if(ctype)		ht->ctype = g_strdup(ctype);	if(referer)		ht->referer = g_strdup(referer);	ht->url = g_strdup(url);	ht->host = g_strdup(c->host);	ht->protokoll = g_strdup("HTTP/1.0");	ht->accept = g_strdup("image/gif, image/jpeg, image/png, */*");	ht->acceptlang = g_strdup("en");	ht->acceptchar = g_strdup("iso-8859-1,*,utf-8");	ht->useragent = g_strdup("Mozilla/4.73 [en] (X11; U; Linux)");	if( (r = gsms_http_request(c, ht)) == 0) {		return NULL;	}	g_free(ht);	tmp = g_strdup(r->document);	gsms_http_response_free(r);	return tmp;}gint gsms_send_http_request(gchar * host, gint port, GSmsHttp * ht,			    gchar * buffer, gint len) {	gint i;	GsmsHttpConnection *c;        GsmsHttpResponse *response;	if( (c = gsms_plugin_http_connect(host, port)) == NULL) {                g_log(MODULE_LOG_DOMAIN, G_LOG_LEVEL_WARNING,                      "Could not open connection");                return -1;        }	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;        }		/* Copy response in buffer */	for(i=0;i<len || i<=strlen(response->document);i++)		buffer[i]=response->document[i];	buffer[i]=0;			gsms_plugin_http_response_free(response);        gsms_plugin_http_close(c);        return 0;}gintgsms_send_mail(gchar *to, gchar *subject, gchar *body){	GSmsSocket *s;	GSmsMail *mail;	gchar  hostname[128];	if(strcmp(configuration.mail_send_method, "smtp") != 0) {		g_log(NULL,G_LOG_LEVEL_WARNING, _("SMTP no enabled! plugin requested to send mail (subject=%s to=%s) - please enable smtp in the preferences"), 		      subject, to);		return -1;	}	g_log(NULL,G_LOG_LEVEL_INFO, _("sending mail (subject=%s to=%s)"), 	      subject, to);	if(strlen(configuration.smtp_host) == 0) {		if( gethostname(hostname, 128) < 0) {			g_log(GSMS_HTTP_LOG_DOMAIN, G_LOG_LEVEL_WARNING,			      _("error sending mail: could not determine hostname - enter the hostname in Preferences/Sending Mail/SMTP/Hostname"));			return -1;		}	} else {		strncpy(hostname, configuration.smtp_host, 128);	}	s = gsms_socket_create(configuration.net_timeout);	if( gsms_socket_open_connection(s, configuration.smtp_server,					configuration.smtp_port)	    != GSMS_SOCKET_SUCCESS) {		gsms_socket_close(s);		return -1;	}	if( gsms_smtp_start(s, hostname) < 0 ) {		gsms_socket_close(s);		return -1;	}	mail = mail_constructor(configuration.smtp_email, to, subject, body);	if( gsms_smtp_send(s, mail) < 0 ) {		 gsms_socket_close(s);		 return -1;	}	g_log(NULL,G_LOG_LEVEL_INFO, _("mail sent (subject=%s to=%s)"), 	      mail->subject, mail->to);	g_free(mail);	gsms_socket_close(s);	return 0;}

⌨️ 快捷键说明

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