+
+/* Options for --divert:
+ --op, -o [register|enable|query|disable|erasure] REQ
+ --type, -t [all|busy|noans|outofreach|notavail] REQ
+ --call, -c [all|voice|fax|data] REQ
+ --timeout, m time_in_seconds OPT
+ --number, -n number OPT
+ */
+int divert(int argc, char **argv)
+{
+ int opt;
+ GSM_CallDivert cd;
+ GSM_Statemachine *sm = &State;
+ GSM_Data data;
+ GSM_Error error;
+ struct option options[] = {
+ { "op", required_argument, NULL, 'o'},
+ { "type", required_argument, NULL, 't'},
+ { "call", required_argument, NULL, 'c'},
+ { "number", required_argument, NULL, 'n'},
+ { "timeout", required_argument, NULL, 'm'},
+ { NULL, 0, NULL, 0}
+ };
+
+ optarg = NULL;
+ optind = 0;
+
+ /* Skip --divert */
+ argc--; argv++;
+
+ memset(&cd, 0, sizeof(GSM_CallDivert));
+
+ while ((opt = getopt_long(argc, argv, "o:t:n:c:m:", options, NULL)) != -1) {
+ switch (opt) {
+ case 'o':
+ if (!strcmp("register", optarg)) {
+ cd.Operation = GSM_CDV_Register;
+ } else if (!strcmp("enable", optarg)) {
+ cd.Operation = GSM_CDV_Enable;
+ } else if (!strcmp("disable", optarg)) {
+ cd.Operation = GSM_CDV_Disable;
+ } else if (!strcmp("erasure", optarg)) {
+ cd.Operation = GSM_CDV_Erasure;
+ } else if (!strcmp("query", optarg)) {
+ cd.Operation = GSM_CDV_Query;
+ } else {
+ usage();
+ exit(-1);
+ }
+ break;
+ case 't':
+ if (!strcmp("all", optarg)) {
+ cd.DType = GSM_CDV_AllTypes;
+ } else if (!strcmp("busy", optarg)) {
+ cd.DType = GSM_CDV_Busy;
+ } else if (!strcmp("noans", optarg)) {
+ cd.DType = GSM_CDV_NoAnswer;
+ } else if (!strcmp("outofreach", optarg)) {
+ cd.DType = GSM_CDV_OutOfReach;
+ } else if (!strcmp("notavail", optarg)) {
+ cd.DType = GSM_CDV_NotAvailable;
+ } else {
+ usage();
+ exit(-1);
+ }
+ break;
+ case 'c':
+ if (!strcmp("all", optarg)) {
+ cd.CType = GSM_CDV_AllCalls;
+ } else if (!strcmp("voice", optarg)) {
+ cd.CType = GSM_CDV_VoiceCalls;
+ } else if (!strcmp("fax", optarg)) {
+ cd.CType = GSM_CDV_FaxCalls;
+ } else if (!strcmp("data", optarg)) {
+ cd.CType = GSM_CDV_DataCalls;
+ } else {
+ usage();
+ exit(-1);
+ }
+ break;
+ case 'm':
+ cd.Timeout = atoi(optarg);
+ break;
+ case 'n':
+ strcpy(cd.Number.number, optarg);
+ if (cd.Number.number[0] == '+') cd.Number.type = SMS_International;
+ else cd.Number.type = SMS_Unknown;
+ break;
+ default:
+ usage();
+ exit(-1);
+ }
+ }
+ data.CallDivert = &cd;
+ error = SM_Functions(GOP_CallDivert, &data, sm);
+
+ if (error == GE_NONE) {
+ fprintf(stderr, "Divert succeeded.\n");
+ } else {
+ fprintf(stderr, "%s\n", print_error(error));
+ }
+ return 0;
+}
+