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

📄 sms.c

📁 这个项目里有两个关于收、发GSM 手机短信的C语言程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sms.c --- code for management of script files: parts stolen from smssend  *//* Copyright (c) E. Lassauge, 2000-2001. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. * * This file is provided AS IS with no warranties of any kind.  The author * shall have no liability with respect to the infringement of copyrights, * trade secrets or any patents by this file or any part thereof.  In no * event will the author be liable for any lost revenue or profits or * other special, indirect and consequential damages. * * mailto:lassauge@mail.dotcom.fr * http://lassauge.free.fr/ * * REVISION HISTORY: * * 2001-01-30 Eric Lassauge <lassauge@mail.dotcom.fr> * added stdout/stderr callbacks to get smssend messages * * 2001-01-04 Eric Lassauge <lassauge@mail.dotcom.fr> * get rid of THREAD_SMSSEND: I do not want to maintain this part of the code. * */#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/wait.h>#include <pthread.h>#include <signal.h>#include <gnome.h>#include "sms.h"#include "interface.h"#include "support.h"/* global preferences values */gboolean	UseProxy 		= FALSE;gchar		ProxyHost[P_LENGTH];gint		ProxyPort 		= 8080;gchar		ProxyUser[P_LENGTH];gchar		ProxyPass[P_LENGTH];gchar		*HeaderFile 		= (gchar *)NULL;gint		DebugLevel 		= 0;gint		TimeOut    		= 0;gboolean	AutoCheck 		= FALSE;gboolean	KeepPass  		= FALSE;gboolean	DelaySend   		= FALSE;gint		Retries     		= 1;/* args variables */gchar		*ScriptPath 		= (gchar *)NULL;gchar		*ScriptFilename 	= (gchar *)NULL;gint		MyScripts		= 0;/* global variables */GHashTable	*AliasHash	 	= (GHashTable *)NULL;GSList		*DelayList	 	= (GSList*)NULL;gint 		NumProvider	 	= 0;GHashTable	*ShownProviderHash	= (GHashTable *)NULL; /* visible in GUI */GHashTable	*SavedProviderHash	= (GHashTable *)NULL; /* saved in user prefs */GHashTable	*ProviderHash		= (GHashTable *)NULL; /* all providers *//* executable name for smssend */#define SMSEXECNAME	"smssend"/* outputs from smssend */#define MESSAGE1	"You already have the latest version of SmsSend"#define MESSAGE2	"SmsSend Error "#define MESSAGE3	"Result :"/* parameters for DoSms() thread */#define MAXLINE 1024#define HALF_SECOND 500000#define DEF_TIMEOUT 60#define NOT_DONE    0xdeadbeefstatic void *DoSms(void *arg);const char arg_help[]   = "-help";const char arg_update[] = "-update";const char arg_minus[]  = "--";/* -----------------------------------------------------------------------------------*/void DeleteProvider(PProvider_t Pv){    /* Free a provider struct: based on smssend code */    int i;    if (Pv->Params != NULL)    {	for (i = 0; i < Pv->NbParams; i++)	{	    if (Pv->Params[i].Name != NULL)		g_free(Pv->Params[i].Name);	    if (Pv->Params[i].Value != NULL)		g_free(Pv->Params[i].Value);	}	free(Pv->Params);    }    if (Pv->Label != NULL)	g_free(Pv->Label);    if (Pv->Filename != NULL)	g_free(Pv->Filename);    g_free(Pv);}/* -----------------------------------------------------------------------------------*/PProvider_t CreateProviderFromFile(const char FileName[]){    /* Load a provider struct from script file: based on smssend code */    FILE *fp;    char Name[MAXLINE], Value[MAXLINE], Saf[MAXLINE], *Str;    PProvider_t Pv;    int NbParams;    fp = fopen(FileName, "r");    if (fp == NULL)    {	g_error(_("Error in provider loader : can't open file !\n"));	return NULL;    }    Pv = g_new0(Provider_t, 1);    NbParams = 0;    while (SU_ParseConfig(fp, Name, sizeof(Name), Value, sizeof(Value)))      {	  if (g_strncasecmp(Name, "NbParams",9) == 0)	    {		Pv->NbParams = atoi(Value);		Pv->Params = g_new0(Param_t, Pv->NbParams);	    }	  else if (Name[0] == '%')	    {		if (NbParams >= Pv->NbParams)		  {		      g_error(_("Error in provider loader : More than NbParams has been found\n"));		      DeleteProvider(Pv);		      return NULL;		  }		Pv->Params[NbParams].Name = g_strdup(Name + 1);		if (Value[0] != 0)		  {		      if (Value[0] == ':')			{			    Pv->Params[NbParams].Help = g_strdup(SU_TrimLeft(Value + 1));			}		      strcpy(Saf, Value);		      Str = strtok(Value, " ");		      while (Str != NULL)			{			    if (g_strcasecmp(Str, "Hidden") == 0)				Pv->Params[NbParams].Hidden = 1;			    else if (g_strcasecmp(Str, "Convert") == 0)				Pv->Params[NbParams].Convert = 1;			    else if (g_strncasecmp(Str, "Size", 4) == 0)				Pv->Params[NbParams].Size = atoi(Str + 5);			    else if (Str[0] == ':')			      {				  Str = strchr(Saf, ':');				  Pv->Params[NbParams].Help = g_strdup(SU_TrimLeft(Str + 1));				  break;			      }			    else				g_printerr(_("Unknown option in Param values for %s: %s\n"), FileName, Str);			    Str = strtok(NULL, " ");			}		  }		NbParams++;	    }      }    fclose(fp);    return Pv;}/* -----------------------------------------------------------------------------------*//* * Read a line from a descriptor.  Read the line one byte at a time, * looking for the newline. Works fine in nonblocking mode..here * we return when no more data can be read.  * We overwrite the newline with a null. * We return the number of characters up to, but not including, * the null (the same as strlen(3)). */gint read_line(gint fd, gchar *ptr, gint maxlen) {    gint n, rc;    gchar c;    gchar *str;	str = ptr;         for (n = 1; n < maxlen; n++) {                if ( (rc = read(fd, &c, 1)) == 1) {                        *ptr++ = c;                        if (c == '\n') {                                break;                        }                } else if (rc == 0) {			/* EOF */                        if (n == 1)                                return(0);      /* EOF, no data read */                        else                                break;          /* EOF, some data was read */                } else if (rc == -2) {			/* timeout while reading string */			return(-2);		} else {			/* nonblocking mode an nothing to read? */			if (rc == -1 && errno == EAGAIN) {				if (n == 1) 					return(-1);				else					break;			}	                        return(-1);     /* error */		}        }	/* terminate the string */	*ptr = 0;         /* strip of some trailing chars - yes..we need both levels */        ptr--;        if ((*ptr == '\n') || (*ptr == '\r') ) {                *ptr = 0;        }        ptr--;        if ((*ptr == '\n') || (*ptr == '\r') ) {                *ptr = 0;        } 	if (strlen(str) == 0) {		/* if we read an empty string, but are NOT on EOF return 1 */		return 1;	} else {        	return(strlen(str));	}}/* -----------------------------------------------------------------------------------*//* get output of smssend (stderr) */void smssend_stderr(gpointer data, gint source, GdkInputCondition cond){    gint n;    gint ret=0;    gchar line[MAXLINE];    PcmdParam_t sms_param = (PcmdParam_t) data;    n = read_line(source, line, MAXLINE);    /* finished? */    if (n <= 0)     {#ifdef DEBUGfprintf(stderr,"smssend_stderr: end\n");#endif	gtk_input_remove(sms_param->Callback);	gtk_input_remove(sms_param->Callback2);	/* pick up return status of child */	waitpid(sms_param->SmsId, &ret, WNOHANG|WUNTRACED);    	/* attach a 'ignore' signal handler again to SIGCHLD to avoid zombies */    	signal(SIGCHLD,SIG_IGN);	sms_param->Done = WEXITSTATUS(ret);#ifdef DEBUGfprintf(stderr,"smssend_stderr: finished (%d)\n",sms_param->Done);#endif        gnome_appbar_set_progress(GNOME_APPBAR(Appbar), 0.0);	return;     }     gnome_appbar_set_status(GNOME_APPBAR(Appbar), line);}/* -----------------------------------------------------------------------------------*//* get output of smssend (stdout) */void smssend_stdout(gpointer data, gint source, GdkInputCondition cond){    gint n;    gint ret=0;    gchar line[MAXLINE];    PcmdParam_t sms_param = (PcmdParam_t) data;    static gint progress = 0;    static gint dir = +1;    n = read_line(source, line, MAXLINE);    /* finished ? */    if ((n <= 0) ||	!(g_strncasecmp(line,MESSAGE1,strlen(MESSAGE1))) ||	!(g_strncasecmp(line,MESSAGE2,strlen(MESSAGE2))) ||	!(g_strncasecmp(line,MESSAGE3,strlen(MESSAGE3))) )    {#ifdef DEBUGfprintf(stderr,"smssend_stdout: end\n");#endif	gtk_input_remove(sms_param->Callback);	gtk_input_remove(sms_param->Callback2);	/* pick up return status of child */	waitpid(sms_param->SmsId, &ret, WNOHANG|WUNTRACED);    	/* attach a 'ignore' signal handler again to SIGCHLD to avoid zombies */    	signal(SIGCHLD,SIG_IGN);	sms_param->Done = WEXITSTATUS(ret);#ifdef DEBUGfprintf(stderr,"smssend_stdout: finished (%d)\n",sms_param->Done);#endif	if (n > 0)     	   gnome_appbar_set_status(GNOME_APPBAR(Appbar), line);        gnome_appbar_set_progress(GNOME_APPBAR(Appbar), 1.0);	return;     }          if (progress + 5 > 100)     {	dir = -1;        progress = 100;     }     if (progress <= 0)     {	dir = +1;        progress = 0;     }     progress = progress + (5 * dir);     gnome_appbar_set_status(GNOME_APPBAR(Appbar), line);     gnome_appbar_set_progress(GNOME_APPBAR(Appbar), ((gfloat)progress)/100.0);}/* -----------------------------------------------------------------------------------*/void CreateArgv( PcmdParam_t sms_param ){    int argc, i;

⌨️ 快捷键说明

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