Exemplo n.º 1
0
int main (int argc, char *argv[])
{
    int err = 0;

    int retval, c, checksent = 0;

    char *serveraddr, *port, *gsmnumber, *gsmtext, *errstr;


    serveraddr = (char *) malloc (40);
    memset (serveraddr, 0x0, 40);
    gsmnumber = (char *) malloc (40);
    memset (gsmnumber, 0x0, 40);
    gsmtext = (char *) malloc (40);
    memset (gsmtext, 0x0, 40);
    errstr = (char *) malloc (1000);
    memset (errstr, 0x0, 1000);
    if (argc < 4) {
        usage (argv[0]);
        return -1;
    }

    while ((c = getopt (argc, argv, "chs:b:t:p:")) != -1)
        switch (c) {
        case 'c':
            checksent = 1;
            break;
        case 's':
            serveraddr = optarg;
            break;
        case 'b':
            gsmnumber = optarg;
            break;
        case 't':
            gsmtext = optarg;
            break;
        case 'p':
            port = optarg;
            break;
        case '?':
            if (optopt == 's' || optopt == 'b' || optopt == 't')
                fprintf (stderr, "Option -%c requires an argument.\n",
                         optopt);
            else if (isprint (optopt))
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf (stderr, "Unknown option character `\\x%x'.\n",
                         optopt);
            return 1;
        case 'h':
            usage (argv[0]);
            return 0;
            break;
        default:
            return -1;
        }

    if (strlen (serveraddr) == 0) {
        strcat (errstr, "Server address/name must be specified\n");
        err = 1;
    }
    if (strlen (gsmnumber) == 0) {
        strcat (errstr, "Number to send must be specified\n");
        err = 1;
    }
    if (strlen (gsmtext) == 0) {
        strcat (errstr, "Text to send must be specified\n");
        err = 1;
    }

    if (err == 1) {
        printf ("Errors detected:\n%s\nType \"%s -h\" for help\n", errstr,
                argv[0]);
        return -1;
    }

    if (checksent == 1) {
        /* printf ("Checking if sent....(timeout ~ 15 sec)\n"); */
    }
#ifdef MINGW32
    WSADATA wsaData;

    int iResult = WSAStartup (MAKEWORD (2, 2), &wsaData);

    if (iResult != NO_ERROR)
        printf ("SMSSTATUS: Error at WSAStartup()\n");
#endif
    retval = sendsms (serveraddr, gsmnumber, gsmtext, checksent, port);
#ifdef MINGW32
    WSACleanup ();
#endif
    return retval;
}
Exemplo n.º 2
0
void AppManager::rescan()
{
    m_appList.clear();
    m_apps.clear();

    AppInfo settingsApp(QUuid(SETTINGS_APP_UUID), false, gettext("Settings"), gettext("System app"));
    m_appList.append(settingsApp.uuid());
    m_apps.insert(settingsApp.uuid(), settingsApp);
    AppInfo watchfaces(QUuid("18e443ce-38fd-47c8-84d5-6d0c775fbe55"), false, gettext("Watchfaces"), gettext("System app"));
    m_appList.append(watchfaces.uuid());
    m_apps.insert(watchfaces.uuid(), watchfaces);
    if (m_pebble->capabilities().testFlag(CapabilityHealth)) {
        AppInfo health(QUuid("36d8c6ed-4c83-4fa1-a9e2-8f12dc941f8c"), false, gettext("Health"), gettext("System app"), true);
        m_appList.append(health.uuid());
        m_apps.insert(health.uuid(), health);
    }
    AppInfo music(QUuid("1f03293d-47af-4f28-b960-f2b02a6dd757"), false, gettext("Music"), gettext("System app"));
    m_appList.append(music.uuid());
    m_apps.insert(music.uuid(), music);
    if(m_pebble->capabilities().testFlag(CapabilityWeather)) {
        AppInfo weather(WeatherApp::appUUID, false, gettext("Weather"), gettext("System app"), true);
        m_appList.append(weather.uuid());
        m_apps.insert(weather.uuid(), weather);
    }
    if(m_pebble->capabilities().testFlag(CapabilitySendSMS)) {
        AppInfo sendsms(SendTextApp::appUUID, false, SendTextApp::appName, gettext("System app"), true);
        m_appList.append(sendsms.uuid());
        m_apps.insert(sendsms.uuid(), sendsms);
    }
    AppInfo notifications(QUuid("b2cae818-10f8-46df-ad2b-98ad2254a3c1"), false, gettext("Notifications"), gettext("System app"));
    m_appList.append(notifications.uuid());
    m_apps.insert(notifications.uuid(), notifications);
    AppInfo alarms(QUuid("67a32d95-ef69-46d4-a0b9-854cc62f97f9"), false, gettext("Alarms"), gettext("System app"));
    m_appList.append(alarms.uuid());
    m_apps.insert(alarms.uuid(), alarms);
    AppInfo ticToc(QUuid("8f3c8686-31a1-4f5f-91f5-01600c9bdc59"), true, "Tic Toc", gettext("Default watchface"));
    m_appList.append(ticToc.uuid());
    m_apps.insert(ticToc.uuid(), ticToc);

    QDir dir(m_pebble->storagePath() + "/apps/");
    qDebug() << "Scanning Apps dir" << dir.absolutePath();
    Q_FOREACH(const QString &path, dir.entryList(QDir::Dirs | QDir::Readable)) {
        QString appPath = dir.absoluteFilePath(path);
        if (dir.exists(path + "/appinfo.json")) {
            scanApp(appPath);
        } else if (QFileInfo(appPath).isFile()) {
            scanApp(appPath);
        }
    }

    QSettings settings(m_pebble->storagePath() + "/apps.conf", QSettings::IniFormat);
    QStringList storedList = settings.value("appList").toStringList();
    if (storedList.isEmpty()) {
        // User did not manually sort the app list yet... We can stop here.
        return;
    }
    // Run some sanity checks
    if (storedList.count() != m_appList.count()) {
        qWarning() << "Installed apps not matching order config. App sort order might be wrong.";
        return;
    }
    foreach (const QUuid &uuid, m_appList) {
        if (!storedList.contains(uuid.toString())) {
            qWarning() << "Installed apps and stored config order cannot be matched. App sort order might be wrong.";
            return;
        }
    }
    // All seems fine, repopulate m_appList
    m_appList.clear();
    foreach (const QString &storedId, storedList) {
        m_appList.append(QUuid(storedId));
    }
Exemplo n.º 3
0
static int parse_options(int argc, char *argv[])
{
	int c;
	int opt_index = -1;
	gn_error rc;

	/* Every option should be in this array. */
	static struct option long_options[] = {
		/* FIXME: these comments are nice, but they would be more useful as docs for the user */
		/* Display usage. */
		{ "help",               optional_argument, NULL, OPT_HELP },

		/* Display version and build information. */
		{ "version",            no_argument,       NULL, OPT_VERSION },

		/* Monitor mode */
		{ "monitor",            optional_argument, NULL, OPT_MONITOR },

		/* Alternate config file location */
		{ "config",             required_argument, NULL, OPT_CONFIGFILE },

		/* Alternate phone section from the config */
		{ "phone",              required_argument, NULL, OPT_CONFIGMODEL },

		/* Get Security Code */
		{ "getsecuritycode",    no_argument,   	   NULL, OPT_GETSECURITYCODE },

		/* Enter Security Code mode */
		{ "entersecuritycode",  required_argument, NULL, OPT_ENTERSECURITYCODE },

		/* Get Security Code status */
		{ "getsecuritycodestatus",  no_argument,   NULL, OPT_GETSECURITYCODESTATUS },

		/* Change Security Code */
		{ "changesecuritycode", required_argument, NULL, OPT_CHANGESECURITYCODE },

		/* Set date and time */
		{ "setdatetime",        optional_argument, NULL, OPT_SETDATETIME },

		/* Get date and time mode */
		{ "getdatetime",        no_argument,       NULL, OPT_GETDATETIME },

		/* Set alarm */
		{ "setalarm",           optional_argument, NULL, OPT_SETALARM },

		/* Get alarm */
		{ "getalarm",           no_argument,       NULL, OPT_GETALARM },

		/* Voice call mode */
		{ "dialvoice",          required_argument, NULL, OPT_DIALVOICE },

		/* Answer the incoming call */
		{ "answercall",         required_argument, NULL, OPT_ANSWERCALL },

		/* Hangup call */
		{ "hangup",             required_argument, NULL, OPT_HANGUP },

		/* Get ToDo note mode */
		{ "gettodo",		required_argument, NULL, OPT_GETTODO },

		/* Write ToDo note mode */
		{ "writetodo",          required_argument, NULL, OPT_WRITETODO },

		/* Delete all ToDo notes mode */
		{ "deletealltodos",     no_argument,       NULL, OPT_DELETEALLTODOS },

		/* Get calendar note mode */
		{ "getcalendarnote",    required_argument, NULL, OPT_GETCALENDARNOTE },

		/* Write calendar note mode */
		{ "writecalendarnote",  required_argument, NULL, OPT_WRITECALENDARNOTE },

		/* Delete calendar note mode */
		{ "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE },

		/* Get display status mode */
		{ "getdisplaystatus",   no_argument,       NULL, OPT_GETDISPLAYSTATUS },

		/* Get memory mode */
		{ "getphonebook",       required_argument, NULL, OPT_GETPHONEBOOK },

		/* Write phonebook (memory) mode */
		{ "writephonebook",     optional_argument, NULL, OPT_WRITEPHONEBOOK },

		/* Delete phonebook entry from memory mode */
		{ "deletephonebook",    required_argument, NULL, OPT_DELETEPHONEBOOK },

		/* Get speed dial mode */
		{ "getspeeddial",       required_argument, NULL, OPT_GETSPEEDDIAL },

		/* Set speed dial mode */
		{ "setspeeddial",       required_argument, NULL, OPT_SETSPEEDDIAL },

		/* Create SMS folder mode */
		{ "createsmsfolder",    required_argument, NULL, OPT_CREATESMSFOLDER },

		/* Delete SMS folder mode */
		{ "deletesmsfolder",    required_argument, NULL, OPT_DELETESMSFOLDER },

		/* Show SMS folder names and its attributes */
		{ "showsmsfolderstatus",no_argument,       NULL, OPT_SHOWSMSFOLDERSTATUS },

		/* Get SMS message mode */
		{ "getsms",             required_argument, NULL, OPT_GETSMS },

		/* Delete SMS message mode */
		{ "deletesms",          required_argument, NULL, OPT_DELETESMS },

		/* Send SMS message mode */
		{ "sendsms",            required_argument, NULL, OPT_SENDSMS },

		/* Ssve SMS message mode */
		{ "savesms",            optional_argument, NULL, OPT_SAVESMS },

		/* Send logo as SMS message mode */
		{ "sendlogo",           required_argument, NULL, OPT_SENDLOGO },

		/* Send ringtone as SMS message */
		{ "sendringtone",       required_argument, NULL, OPT_SENDRINGTONE },

		/* Get ringtone */
		{ "getringtone",        required_argument, NULL, OPT_GETRINGTONE },

		/* Set ringtone */
		{ "setringtone",        required_argument, NULL, OPT_SETRINGTONE },

		/* Play ringtone */
		{ "playringtone",       required_argument, NULL, OPT_PLAYRINGTONE },

		/* Convert ringtone */
		{ "ringtoneconvert",    required_argument, NULL, OPT_RINGTONECONVERT },

		/* Get list of the ringtones */
		{ "getringtonelist",    no_argument,       NULL, OPT_GETRINGTONELIST },

		/* Delete ringtones */
		{ "deleteringtone",     required_argument, NULL, OPT_DELETERINGTONE },

		/* Get SMS center number mode */
		{ "getsmsc",            optional_argument, NULL, OPT_GETSMSC },

		/* Set SMS center number mode */
		{ "setsmsc",            no_argument,       NULL, OPT_SETSMSC },

		/* For development purposes: run in passive monitoring mode */
		{ "pmon",               no_argument,       NULL, OPT_PMON },

		/* NetMonitor mode */
		{ "netmonitor",         required_argument, NULL, OPT_NETMONITOR },

		/* Identify */
		{ "identify",           no_argument,       NULL, OPT_IDENTIFY },

		/* Send DTMF sequence */
		{ "senddtmf",           required_argument, NULL, OPT_SENDDTMF },

		/* Resets the phone */
		{ "reset",              required_argument, NULL, OPT_RESET },

		/* Set logo */
		{ "setlogo",            required_argument, NULL, OPT_SETLOGO },

		/* Get logo */
		{ "getlogo",            required_argument, NULL, OPT_GETLOGO },

		/* View logo */
		{ "viewlogo",           required_argument, NULL, OPT_VIEWLOGO },

		/* Show profile */
		{ "getprofile",         optional_argument, NULL, OPT_GETPROFILE },

		/* Set profile */
		{ "setprofile",         no_argument,       NULL, OPT_SETPROFILE },

		/* Get the active profile */
		{ "getactiveprofile",   no_argument,       NULL, OPT_GETACTIVEPROFILE },

		/* Set the active profile */
		{ "setactiveprofile",   required_argument, NULL, OPT_SETACTIVEPROFILE },

		/* Show texts from phone's display */
		{ "displayoutput",      no_argument,       NULL, OPT_DISPLAYOUTPUT },

		/* Simulate pressing the keys */
		{ "keysequence",        no_argument,       NULL, OPT_KEYPRESS },

		/* Simulate pressing the keys */
		{ "enterchar",          no_argument,       NULL, OPT_ENTERCHAR },

		/* Divert calls */
		{ "divert",		no_argument,       NULL, OPT_DIVERT },

		/* SMS reader */
		{ "smsreader",          no_argument,       NULL, OPT_SMSREADER },

		/* For development purposes: insert you function calls here */
		{ "foogle",             no_argument,       NULL, OPT_FOOGLE },

		/* Get WAP bookmark */
		{ "getwapbookmark",     required_argument, NULL, OPT_GETWAPBOOKMARK },

		/* Write WAP bookmark */
		{ "writewapbookmark",   required_argument, NULL, OPT_WRITEWAPBOOKMARK },

		/* Delete WAP bookmark */
		{ "deletewapbookmark",  required_argument, NULL, OPT_DELETEWAPBOOKMARK },

		/* Get WAP setting */
		{ "getwapsetting",      required_argument, NULL, OPT_GETWAPSETTING },

		/* Write WAP setting */
		{ "writewapsetting",    no_argument, 	   NULL, OPT_WRITEWAPSETTING },

		/* Activate WAP setting */
		{ "activatewapsetting", required_argument, NULL, OPT_ACTIVATEWAPSETTING },

		/* List GSM networks */
		{ "listnetworks",       no_argument,       NULL, OPT_LISTNETWORKS },

		/* Get network info */
		{ "getnetworkinfo",     no_argument,       NULL, OPT_GETNETWORKINFO },

		/* Get (sim)lock info */
		{ "getlocksinfo",       no_argument,       NULL, OPT_GETLOCKSINFO },

                /* Get file list */
		{ "getfilelist",        required_argument, NULL, OPT_GETFILELIST },

                /* Get file details by id */
		{ "getfiledetailsbyid", optional_argument, NULL, OPT_GETFILEDETAILSBYID },

                /* Get file id */
		{ "getfileid",          required_argument, NULL, OPT_GETFILEID },

                /* Get file */
		{ "getfile",            required_argument, NULL, OPT_GETFILE },

                /* Get file by id */
		{ "getfilebyid",        required_argument, NULL, OPT_GETFILEBYID },

		/* Get all files */
		{ "getallfiles",        required_argument, NULL, OPT_GETALLFILES },

                /* Put a file */
		{ "putfile",            required_argument, NULL, OPT_PUTFILE },

		/* Delete a file */
		{ "deletefile",         required_argument, NULL, OPT_DELETEFILE },

		/* Delete a file by id */
		{ "deletefilebyid",     required_argument, NULL, OPT_DELETEFILEBYID },

		/* Shell like interface */
		{ "shell",              no_argument, NULL, OPT_SHELL },

		/* Get MMS message mode */
		{ "getmms",             required_argument, NULL, OPT_GETMMS },

		/* Delete MMS message mode */
		{ "deletemms",          required_argument, NULL, OPT_DELETEMMS },

		/* Check if the phone responds */
		{ "ping",               no_argument, NULL, OPT_PING },

		{ 0, 0, 0, 0 },
	};

	/* Every command which requires arguments should have an appropriate entry
	   in this array. */
	static struct gnokii_arg_len gals[] = {
		{ OPT_HELP,              1, 100, 0 },
		{ OPT_CONFIGFILE,        1, 100, 0 },
		{ OPT_CONFIGMODEL,       1, 100, 0 },
		{ OPT_ENTERSECURITYCODE, 1, 100, 0 },
		{ OPT_CHANGESECURITYCODE,1, 1, 0 },
		{ OPT_SETDATETIME,       0, 5, 0 },
		{ OPT_SETALARM,          0, 2, 0 },
		{ OPT_DIALVOICE,         1, 1, 0 },
		{ OPT_ANSWERCALL,        1, 1, 0 },
		{ OPT_HANGUP,            1, 1, 0 },
		{ OPT_GETTODO,           1, 3, 0 },
		{ OPT_WRITETODO,         2, 3, 0 },
		{ OPT_GETCALENDARNOTE,   1, 3, 0 },
		{ OPT_WRITECALENDARNOTE, 2, 3, 0 },
		{ OPT_DELCALENDARNOTE,   1, 2, 0 },
		{ OPT_GETPHONEBOOK,      2, 4, 0 },
		{ OPT_WRITEPHONEBOOK,    0, 10, 0 },
		{ OPT_DELETEPHONEBOOK,   2, 3, 0 },
		{ OPT_GETSPEEDDIAL,      1, 1, 0 },
		{ OPT_SETSPEEDDIAL,      3, 3, 0 },
		{ OPT_CREATESMSFOLDER,   1, 1, 0 },
		{ OPT_DELETESMSFOLDER,   1, 1, 0 },
		{ OPT_GETSMS,            2, 6, 0 },
		{ OPT_DELETESMS,         2, 3, 0 },
		{ OPT_SENDSMS,           1, 10, 0 },
		{ OPT_SAVESMS,           0, 12, 0 },
		{ OPT_SENDLOGO,          3, 4, GAL_XOR },
		{ OPT_SENDRINGTONE,      2, 2, 0 },
		{ OPT_GETSMSC,           0, 3, 0 },
		{ OPT_GETWELCOMENOTE,    1, 1, 0 },
		{ OPT_SETWELCOMENOTE,    1, 1, 0 },
		{ OPT_NETMONITOR,        1, 1, 0 },
		{ OPT_SENDDTMF,          1, 1, 0 },
		{ OPT_SETLOGO,           1, 4, 0 },
		{ OPT_GETLOGO,           1, 4, 0 },
		{ OPT_VIEWLOGO,          1, 1, 0 },
		{ OPT_GETRINGTONE,       1, 3, 0 },
		{ OPT_SETRINGTONE,       1, 5, 0 },
		{ OPT_PLAYRINGTONE,      1, 3, 0 },
		{ OPT_RINGTONECONVERT,   2, 2, 0 },
		{ OPT_DELETERINGTONE,    1, 2, 0 },
		{ OPT_RESET,             0, 1, 0 },
		{ OPT_GETPROFILE,        0, 3, 0 },
		{ OPT_SETACTIVEPROFILE,  1, 1, 0 },
		{ OPT_DIVERT,            6, 10, 0 },
		{ OPT_GETWAPBOOKMARK,    1, 1, 0 },
		{ OPT_WRITEWAPBOOKMARK,  2, 2, 0 },
		{ OPT_DELETEWAPBOOKMARK, 1, 1, 0 },
		{ OPT_GETWAPSETTING,     1, 2, 0 },
		{ OPT_ACTIVATEWAPSETTING,1, 1, 0 },
		{ OPT_MONITOR,           0, 1, 0 },
		{ OPT_GETFILELIST,       1, 1, 0 },
		{ OPT_GETFILEDETAILSBYID,0, 1, 0 },
		{ OPT_GETFILEID,         1, 1, 0 },
		{ OPT_GETFILE,           1, 2, 0 },
		{ OPT_GETFILEBYID,       1, 2, 0 },
		{ OPT_GETALLFILES,       1, 1, 0 },
		{ OPT_PUTFILE,           2, 2, 0 },
		{ OPT_DELETEFILE,        1, 1, 0 },
		{ OPT_DELETEFILEBYID,    1, 1, 0 },
		{ OPT_SHELL,             0, 0, 0 },
		{ OPT_GETMMS,            2, 6, 0 },
		{ OPT_DELETEMMS,         2, 3, 0 },
		{ OPT_FOOGLE,            0, 0, 0 },
		{ OPT_PING,              0, 0, 0 },
		{ 0, 0, 0, 0 },
	};

	/* Handle command line arguments.
	 * -c equals to --config
	 * -p equals to --phone
	 */
	c = getopt_long(argc, argv, "c:p:", long_options, &opt_index);

	switch (c) {
	/* No argument given - we should display usage. */
	case -1:
		return usage(stderr, -1, NULL);
	/* First, error conditions */
	case '?':
	case ':':
		/* --shell command does not set argv[0] */
		if (argv[0])
			fprintf(stderr, _("Use '%s --help' for usage information.\n"), argv[0]);
		else
			fprintf(stderr, _("Use '--help' for usage information.\n"));
		return 1;
	/* Then, options with no arguments */
	case OPT_VERSION:
		version();
		return 0;
	/* That's a bit ugly... */
	case 'c':
		c = OPT_CONFIGFILE;
		opt_index = 0;
		break;
	case 'p':
		c = OPT_CONFIGMODEL;
		opt_index = 1;
		break;
	}

	/* We have to build an array of the arguments which will be passed to the
	   functions.  Please note that every text after the --command will be
	   passed as arguments.  A syntax like gnokii --cmd1 args --cmd2 args will
	   not work as expected; instead args --cmd2 args is passed as a
	   parameter. */
	if (checkargs(c, gals, argc, long_options[opt_index].has_arg)) {
		return usage(stderr, -1, NULL);
	}

	/* Other options that do not need initialization */
	switch (c) {
	case OPT_CONFIGFILE:
		if (configfile)
			return usage(stderr, -1, NULL);
		configfile = optarg;
		return parse_options(argc, argv);
	case OPT_CONFIGMODEL:
		if (configmodel)
			return usage(stderr, -1, NULL);
		configmodel = optarg;
		return parse_options(argc, argv);
	case OPT_HELP:
		return usage(stdout, argc, argv);
	case OPT_VIEWLOGO:
		return viewlogo(optarg);
	case OPT_LISTNETWORKS:
		list_gsm_networks();
		return GN_ERR_NONE;
	case OPT_RINGTONECONVERT:
		return ringtoneconvert(argc, argv);
	}

	/* Initialise the code for the GSM interface. */
	if (c != OPT_FOOGLE && state == NULL && businit())
		return -1;

	switch (c) {
	/* Monitoring options */
	case OPT_MONITOR:
		rc = monitormode(argc, argv, data, state);
		break;
	case OPT_GETDISPLAYSTATUS:
		rc = getdisplaystatus(data, state);
		break;
	case OPT_DISPLAYOUTPUT:
		rc = displayoutput(data, state);
		break;
	case OPT_NETMONITOR:
		rc = netmonitor(optarg, data, state);
		break;

	/* SMS options */
	case OPT_SENDSMS:
		rc = sendsms(argc, argv, data, state);
		break;
	case OPT_SAVESMS:
		rc = savesms(argc, argv, data, state);
		break;
	case OPT_GETSMS:
		rc = getsms(argc, argv, data, state);
		break;
	case OPT_DELETESMS:
		rc = deletesms(argc, argv, data, state);
		break;
	case OPT_GETSMSC:
		rc = getsmsc(argc, argv, data, state);
		break;
	case OPT_SETSMSC:
		rc = setsmsc(data, state);
		break;
	case OPT_CREATESMSFOLDER:
		rc = createsmsfolder(optarg, data, state);
		break;
	case OPT_DELETESMSFOLDER:
		rc = deletesmsfolder(optarg, data, state);
		break;
	case OPT_SHOWSMSFOLDERSTATUS:
		rc = showsmsfolderstatus(data, state);
		break;
	case OPT_SMSREADER:
		rc = smsreader(data, state);
		break;

	/* Phonebook options */
	case OPT_GETPHONEBOOK:
		rc = getphonebook(argc, argv, data, state);
		break;
	case OPT_WRITEPHONEBOOK:
		rc = writephonebook(argc, argv, data, state);
		break;
	case OPT_DELETEPHONEBOOK:
		rc = deletephonebook(argc, argv, data, state);
		break;

	/* Calendar options */
	case OPT_GETCALENDARNOTE:
		rc = getcalendarnote(argc, argv, data, state);
		break;
	case OPT_WRITECALENDARNOTE:
		rc = writecalendarnote(argc, argv, data, state);
		break;
	case OPT_DELCALENDARNOTE:
		rc = deletecalendarnote(argc, argv, data, state);
		break;

	/* ToDo options */
	case OPT_GETTODO:
		rc = gettodo(argc, argv, data, state);
		break;
	case OPT_WRITETODO:
		rc = writetodo(argc, argv, data, state);
		break;
	case OPT_DELETEALLTODOS:
		rc = deletealltodos(data, state);
		break;

	/* Dialling and call handling options */
	case OPT_GETSPEEDDIAL:
		rc = getspeeddial(optarg, data, state);
		break;
	case OPT_SETSPEEDDIAL:
		rc = setspeeddial(argv, data, state);
		break;
	case OPT_DIALVOICE:
		rc = dialvoice(optarg, data, state);
		break;
	case OPT_SENDDTMF:
		rc = senddtmf(optarg, data, state);
		break;
	case OPT_ANSWERCALL:
		rc = answercall(optarg, data, state);
		break;
	case OPT_HANGUP:
		rc = hangup(optarg, data, state);
		break;
	case OPT_DIVERT:
		rc = divert(argc, argv, data, state);
		break;

	/* Profile options */
	case OPT_GETPROFILE:
		rc = getprofile(argc, argv, data, state);
		break;
	case OPT_SETPROFILE:
		rc = setprofile(data, state);
		break;
	case OPT_GETACTIVEPROFILE:
		rc = getactiveprofile(data, state);
		break;
	case OPT_SETACTIVEPROFILE:
		rc = setactiveprofile(argc, argv, data, state);
		break;

	/* Phone settings options */
	case OPT_RESET:
		rc = reset(optarg, data, state);
		break;
	case OPT_GETDATETIME:
		rc = getdatetime(data, state);
		break;
	case OPT_SETDATETIME:
		rc = setdatetime(argc, argv, data, state);
		break;
	case OPT_GETALARM:
		rc = getalarm(data, state);
		break;
	case OPT_SETALARM:
		rc = setalarm(argc, argv, data, state);
		break;

	/* WAP options */
	case OPT_GETWAPBOOKMARK:
		rc = getwapbookmark(optarg, data, state);
		break;
	case OPT_WRITEWAPBOOKMARK:
		rc = writewapbookmark(argc, argv, data, state);
		break;
	case OPT_DELETEWAPBOOKMARK:
		rc = deletewapbookmark(optarg, data, state);
		break;
	case OPT_GETWAPSETTING:
		rc = getwapsetting(argc, argv, data, state);
		break;
	case OPT_WRITEWAPSETTING:
		rc = writewapsetting(data, state);
		break;
	case OPT_ACTIVATEWAPSETTING:
		rc = activatewapsetting(optarg, data, state);
		break;

	/* Logo options */
	case OPT_SENDLOGO:
		rc = sendlogo(argc, argv, data, state);
		break;
	case OPT_SETLOGO:
		rc = setlogo(argc, argv, data, state);
		break;
	case OPT_GETLOGO:
		rc = getlogo(argc, argv, data, state);
		break;

	/* Ringtone options */
	case OPT_SENDRINGTONE:
		rc = sendringtone(argc, argv, data, state);
		break;
	case OPT_GETRINGTONE:
		rc = getringtone(argc, argv, data, state);
		break;
	case OPT_SETRINGTONE:
		rc = setringtone(argc, argv, data, state);
		break;
	case OPT_PLAYRINGTONE:
		rc = playringtone(argc, argv, data, state);
		break;
	case OPT_GETRINGTONELIST:
		rc = getringtonelist(data, state);
		break;
	case OPT_DELETERINGTONE:
		rc = deleteringtone(argc, argv, data, state);
		break;

	/* Security options */
	case OPT_IDENTIFY:
		rc = identify(state);
		break;
	case OPT_GETLOCKSINFO:
		rc = getlocksinfo(data, state);
		break;
	case OPT_GETSECURITYCODE:
		rc = getsecuritycode(data, state);
		break;
	case OPT_ENTERSECURITYCODE:
		rc = entersecuritycode(optarg, data, state);
		if (rc == GN_ERR_NONE && optind < argc)
			return parse_options(argc, argv);
		break;
	case OPT_GETSECURITYCODESTATUS:
		rc = getsecuritycodestatus(data, state);
		break;
	case OPT_CHANGESECURITYCODE:
		rc = changesecuritycode(optarg, data, state);
			break;

	/* File options */
	case OPT_GETFILELIST:
		rc = getfilelist(optarg, data, state);
		break;
	case OPT_GETFILEDETAILSBYID:
		rc = getfiledetailsbyid(argc, argv, data, state);
		break;
	case OPT_GETFILEID:
		rc = getfileid(optarg, data, state);
		break;
	case OPT_GETFILE:
		rc = getfile(argc, argv, data, state);
		break;
	case OPT_GETFILEBYID:
		rc = getfilebyid(argc, argv, data, state);
		break;
	case OPT_GETALLFILES:
		rc = getallfiles(optarg, data, state);
		break;
	case OPT_PUTFILE:
		rc = putfile(argc, argv, data, state);
		break;
	case OPT_DELETEFILE:
		rc = deletefile(optarg, data, state);
		break;
	case OPT_DELETEFILEBYID:
		rc = deletefilebyid(optarg, data, state);
		break;

	/* Misc options */
	case OPT_PMON:
		rc = pmon(data, state);
		break;
	case OPT_KEYPRESS:
		rc = presskeysequence(data, state);
		break;
	case OPT_ENTERCHAR:
		rc = enterchar(data, state);
		break;
	case OPT_GETNETWORKINFO:
		rc = getnetworkinfo(data, state);
		break;
	case OPT_SHELL:
		rc = shell(data, state);
		break;
	case OPT_PING:
		rc = ping(data, state);
		break;
#ifndef WIN32
	case OPT_FOOGLE:
		rc = foogle(argc, argv);
		break;
#endif
	/* MMS options */
	case OPT_GETMMS:
		rc = getmms(argc, argv, data, state);
		break;
	case OPT_DELETEMMS:
		rc = deletemms(argc, argv, data, state);
		break;
	default:
		rc = GN_ERR_FAILED;
		fprintf(stderr, _("Unknown option: %d\n"), c);
		break;
	}
	return rc;
}
Exemplo n.º 4
0
Arquivo: sms.c Projeto: ceppa/socket
void doMessageHandler()
/*--------------------------------------------
 * gestisce la connessione/disconnessione del device SMS
 * riprova ogni 2 secondi
 * legge la coda degli SMS e invia
 * -----------------------------------------*/
{
	int out=0;
	int attempt=0;
	int vai;
	time_t start_time;
	int i;
	struct msgform msg;
	char message[160];
	char *c;

	strcpy(message,"connesso");
	msg.mtype=0;
	start_time=0;	//last connection fail

	if(NUMSMSDEVICES>0)
	{
//		printf("trying to connect to sms\n");
		start_time=time(NULL);
		sms_devices[0].sockfd=socketConnect(sms_devices[0].address,
				sms_devices[0].port);
		if(sms_devices[0].sockfd>0)
			printf("address %s, port %d, sms connected\n",sms_devices[0].address, sms_devices[0].port);
	}
/*
		for(i=0;i<NUMSMSNUMBERS;i++)
		{
			if(sendsms(sms_devices[0].sockfd,
					sms_numbers[i].number,message)<0)
			{
				close(sms_devices[0].sockfd);
				sms_devices[0].sockfd=-1;
				start_time=time(NULL);
			}
		}*/
	


	while(1)
	{
		//leggo coda dei messaggi e scrivo su log
		vai=1;
		do
		{
			if(msgrcv(msgid,&msg,MSGLENGTH,0,IPC_NOWAIT)!=-1)
			{
				write(logFileFd,msg.mtext,strlen(msg.mtext));
				if(msg.mtype>1)	//is sms
				{
					if(NUMSMSDEVICES>0)
					{
						if((sms_devices[0].sockfd<0)&&(time(NULL)-start_time>2))
						{
//							printf("trying to connect to sms\n");
							start_time=time(NULL);
							sms_devices[0].sockfd=socketConnect(sms_devices[0].address,
								sms_devices[0].port);
						}
						if(sms_devices[0].sockfd>0)
						{
							printf("address %s, port %d, sms connected\n",sms_devices[0].address, sms_devices[0].port);
							for(i=0;i<NUMSMSNUMBERS;i++)
							{
								if((c=strrchr(msg.mtext,'\t'))==0)
									c=msg.mtext;
								else 
									c++;
								if(sendsms(sms_devices[0].sockfd,
									sms_numbers[i].number,c)<0)
								{
									close(sms_devices[0].sockfd);
									sms_devices[0].sockfd=-1;
									start_time=time(NULL);
								}
							}
						}
					}
				}
			}
			else
				vai=0;
		}
		while(vai);
		usleep(10000);
	}
}