/* FUNCTION: Calculate a grid of Voigt profiles. */ int calcprofiles(struct transit *tr){ struct transithint *th = tr->ds.th; /* transithint struct */ struct opacity *op=tr->ds.op; /* Opacity struct */ int i, j; /* for-loop indices */ int nDop, nLor; /* Number of Doppler and Lorentz-widths */ double Lmin, Lmax, Dmin, Dmax; /* Minimum and maximum widths */ PREC_VOIGT ***profile; /* Grid of Voigt profiles */ float timesalpha=tr->timesalpha; /* Voigt wings width */ struct timeval tv; /* Time-keeping variables */ double t0=0.0; /* Make logscale grid for the profile widths: */ /* FINDME: Add check that these numbers make sense */ nDop = op->nDop = th->nDop; nLor = op->nLor = th->nLor; Dmin = th->dmin; Dmax = th->dmax; Lmin = th->lmin; Lmax = th->lmax; op->aDop = logspace(Dmin, Dmax, nDop); op->aLor = logspace(Lmin, Lmax, nLor); /* Allocate array for the profile half-size: */ op->profsize = (PREC_NREC **)calloc(nDop, sizeof(PREC_NREC *)); op->profsize[0] = (PREC_NREC *)calloc(nDop*nLor, sizeof(PREC_NREC)); for (i=1; i<nDop; i++) op->profsize[i] = op->profsize[0] + i*nLor; /* Allocate grid of Voigt profiles: */ op->profile = (PREC_VOIGT ***)calloc(nDop, sizeof(PREC_VOIGT **)); op->profile[0] = (PREC_VOIGT **)calloc(nDop*nLor, sizeof(PREC_VOIGT *)); for (i=1; i<nDop; i++){ op->profile[i] = op->profile[0] + i*nLor; } profile = op->profile; tr_output(TOUT_RESULT, "Number of Voigt profiles: %d.\n", nDop*nLor); t0 = timestart(tv, "Begin Voigt profiles calculation."); /* Evaluate the profiles for the array of widths: */ for (i=0; i<nDop; i++){ for (j=0; j<nLor; j++){ /* Skip calculation if Doppler width << Lorentz width: */ /* Set size and pointer to previous profile: */ if (op->aDop[i]*10.0 < op->aLor[j] && i != 0){ op->profsize[i][j] = op->profsize[i-1][j]; profile[i][j] = profile[i-1][j]; } else{ /* Calculate a new profile for given widths: */ op->profsize[i][j] = getprofile(&profile[i][j], tr->wns.d/tr->owns.o, op->aDop[i], op->aLor[j], timesalpha, tr->owns.n); } tr_output(TOUT_DEBUG, "Profile[%2d][%2d] size = %4li (D=%.3g, " "L=%.3g).\n", i, j, 2*op->profsize[i][j]+1, op->aDop[i], op->aLor[j]); } } t0 = timecheck(verblevel, 0, 0, "End Voigt-profile calculation.", tv, t0); return 0; }
PROTO int cmdauthinfo(char *args) { char subcmd[17], subcmdargs[65]; USER *newuser; PROFILE *oldprf; PROFILE *newprf; int change_profile; AUTHRESULT *authres; sscanf (args, "%16[^\r\n\t ] %64[^\r\n]", subcmd, subcmdargs); if ( client->authenticated ) return swriteclient(client, MSG_AUTH_TWICE); if (!strcasecmp(subcmd,"user")) { if (client->authenticated && strncmp(client->username, subcmdargs, 64)) return swriteclient (client, MSG_AUTH_TWICE); if ( client->vhost->AddSuffix[0] != '\0' ) { snprintf(client->username, MAX_USERPASS-1, "%s@%s", subcmdargs, client->vhost->AddSuffix); } else { strncpy(client->username, subcmdargs, MAX_USERPASS-1); } } else if ( !strcasecmp(subcmd, "pass") ) { strncpy(client->password, subcmdargs, MAX_USERPASS-1); } else { return swriteclient(client, MSG_AUTH_UNKNOWN); } if ( client->username[0] == 0 || client->password[0] == 0 ) return swriteclient(client, MSG_MOREAUTHREQ); client->auth = getauth(client->username); if ( (authres=new_authresult(client)) == NULL ) return swriteclient(client, MSG_AUTH_NOMEM); void (*authmod)() = find_auth_mod(client->auth->auth->lib); if (!authmod) { CLEARPASS syslog(LOG_ERR, "Can't find authmap: %s", client->auth->auth->lib); swriteclient(client, MSG_AUTH_ERR); return 0; } client->authenticated = 0; (*authmod)(authres, &cfg, client->auth->auth->args); CLEARPASS if ( authres->authenticated == true ) { semlock_lock(master->semid); client->authenticated++; if ( authres->logname != NULL ) strcpy(client->logname, authres->logname); /* auth module specified profile */ if ( authres->profile != NULL ) { if ( (newprf = find_user_profile(client->username)) == NULL ) if ( (newprf=getprofile(authres->profile)) == NULL ) { client->authenticated--; semlock_unlock(master->semid); syslog(LOG_ERR, "Missing profile information from authenticator, rejecting user %s", authres->username); swriteclient(client, MSG_AUTH_ERR); free_authresult(authres); return 0; } } else { newprf = client->auth->profile; } PROFILE *p; if ( (p = prof_iplookup(newprf, client->addr.sin_addr)) != NULL ) newprf = p; if ( ! nullstr(newprf->Disabled) ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: 480 %s", client->hostname, authres->username, newprf->Disabled); return writeclient(client, "482 %s", newprf->Disabled); } /* Check and verify we are allowed in our new profile */ change_profile = 0; oldprf = client->profile; if ( client->profile != newprf ) { if ( newprf->connections > newprf->MaxConnections ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_TOOMANYCON); return swriteclient(client, MSG_AUTH_TOOMANYCON); } else if ( newprf->numusers > newprf->MaxUsers ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_TOOMANYUSR); return swriteclient(client, MSG_AUTH_TOOMANYUSR); } else { change_profile = 1; } } /* Find our other connections from this user to see if we are allowed */ newuser = find_user(client->username, newprf); if ( newuser != client->user && newuser != NULL ) { if ( newuser->connections > newprf->MaxUserConcurrent ) { client->authenticated--; drop_user(newuser->id, newprf); semlock_unlock(master->semid); sleep(cfg.RetryDelay); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_USERFULL); free_authresult(authres); return swriteclient(client, MSG_AUTH_USERFULL); } } if ( newuser == NULL ) syslog(LOG_ERR, "newuser == NULL"); /* check number of different connected hosts from new user */ int maxhosts = newprf->ASMaxHosts; int maxconns = newprf->ASMaxConns; if ( maxconns > 0 || maxhosts > 0 ) { char httpresult[2048]; semlock_unlock(master->semid); if ( ! check_http_accountsharing(client->username, client->hostname, maxhosts, maxconns, newprf->Name, httpresult) ) { syslog(LOG_DEBUG, "HTTP account sharing returned false. maxhosts=%d, maxconns=%d, user=%s, host=%s, newprf=%s, result=%s", maxhosts, maxconns, client->username, client->hostname, newprf->Name, httpresult); semlock_lock(master->semid); client->authenticated--; drop_user(newuser->id, newprf); semlock_unlock(master->semid); sleep(cfg.RetryDelay); free_authresult(authres); return writeclient(client, "482 %s", httpresult); } semlock_lock(master->semid); } if ( change_profile == 1 ) { if ( client->profile->connections == 0 ) syslog(LOG_ERR, "Trying to drop 0 connections profile from auth: %s", client->profile->Name); else client->profile->connections--; client->profile = newprf; client->profile->connections++; } drop_user(client->user->id, oldprf); client->user = newuser; client->user->bytesleft = authres->bytes; // client->initbytes; client->posting = authres->posting; if ( authres->userkbit > 0 ) client->user->MaxUserBPS = authres->userkbit * 1000 / 8; else client->user->MaxUserBPS = client->profile->MaxUserBPS; if ( authres->timeleft > 0 ) { client->user->timeleft = authres->timeleft; } if ( authres->readpat ) { strcpy(client->user->readpat, authres->readpat); } if ( authres->postpat ) { strcpy(client->user->postpat, authres->postpat); } // syslog(LOG_DEBUG, "%s: assigning-change %s userkey %s", client->hostname, client->profile->Name, client->user->key); /* init ratelimiter */ init_ratelimiter(client); semlock_unlock(master->semid); } if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, authres->message ? authres->message : "UNKNOWN"); swriteclient(client, authres->message ? authres->message : MSG_AUTH_ERR); free_authresult(authres); return 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; }
/* * Applies the parameters (i.e. computes all the samples, based on parameters); */ void PADnoteParameters::applyparameters(bool lockmutex) { const int samplesize = (((int) 1) << (Pquality.samplesize + 14)); int spectrumsize = samplesize / 2; float *spectrum = new float[spectrumsize]; int profilesize = 512; float profile[profilesize]; float bwadjust = getprofile(profile, profilesize); // for (int i=0;i<profilesize;i++) profile[i]*=profile[i]; float basefreq = 65.406f * powf(2.0f, Pquality.basenote / 2); if(Pquality.basenote % 2 == 1) basefreq *= 1.5f; int samplemax = Pquality.oct + 1; int smpoct = Pquality.smpoct; if(Pquality.smpoct == 5) smpoct = 6; if(Pquality.smpoct == 6) smpoct = 12; if(smpoct != 0) samplemax *= smpoct; else samplemax = samplemax / 2 + 1; if(samplemax == 0) samplemax = 1; //prepare a BIG FFT stuff FFTwrapper *fft = new FFTwrapper(samplesize); fft_t *fftfreqs = new fft_t[samplesize / 2]; float adj[samplemax]; //this is used to compute frequency relation to the base frequency for(int nsample = 0; nsample < samplemax; ++nsample) adj[nsample] = (Pquality.oct + 1.0f) * (float)nsample / samplemax; for(int nsample = 0; nsample < samplemax; ++nsample) { float tmp = adj[nsample] - adj[samplemax - 1] * 0.5f; float basefreqadjust = powf(2.0f, tmp); if(Pmode == 0) generatespectrum_bandwidthMode(spectrum, spectrumsize, basefreq * basefreqadjust, profile, profilesize, bwadjust); else generatespectrum_otherModes(spectrum, spectrumsize, basefreq * basefreqadjust); const int extra_samples = 5; //the last samples contains the first samples (used for linear/cubic interpolation) newsample.smp = new float[samplesize + extra_samples]; newsample.smp[0] = 0.0f; for(int i = 1; i < spectrumsize; ++i) //randomize the phases fftfreqs[i] = std::polar(spectrum[i], (float)RND * 6.29f); fft->freqs2smps(fftfreqs, newsample.smp); //that's all; here is the only ifft for the whole sample; no windows are used ;-) //normalize(rms) float rms = 0.0f; for(int i = 0; i < samplesize; ++i) rms += newsample.smp[i] * newsample.smp[i]; rms = sqrt(rms); if(rms < 0.000001f) rms = 1.0f; rms *= sqrt(262144.0f / samplesize); for(int i = 0; i < samplesize; ++i) newsample.smp[i] *= 1.0f / rms * 50.0f; //prepare extra samples used by the linear or cubic interpolation for(int i = 0; i < extra_samples; ++i) newsample.smp[i + samplesize] = newsample.smp[i]; //replace the current sample with the new computed sample if(lockmutex) { pthread_mutex_lock(mutex); deletesample(nsample); sample[nsample].smp = newsample.smp; sample[nsample].size = samplesize; sample[nsample].basefreq = basefreq * basefreqadjust; pthread_mutex_unlock(mutex); } else { deletesample(nsample); sample[nsample].smp = newsample.smp; sample[nsample].size = samplesize; sample[nsample].basefreq = basefreq * basefreqadjust; } newsample.smp = NULL; } delete (fft); delete[] fftfreqs; delete[] spectrum; //delete the additional samples that might exists and are not useful if(lockmutex) { pthread_mutex_lock(mutex); for(int i = samplemax; i < PAD_MAX_SAMPLES; ++i) deletesample(i); pthread_mutex_unlock(mutex); } else for(int i = samplemax; i < PAD_MAX_SAMPLES; ++i) deletesample(i); ; }