Exemple #1
0
/* MW. This function should not use cp_lastone, see cp_parse in cpshar.c
 *      Many things are deleted here and memory leak closed */
wordlist *
cp_doalias(wordlist *wlist)
{
    wordlist *comm;

    /* The alias process is going to modify the "last" line typed, so
     * save a copy of what it really is and restore it after aliasing
     * is done. We have to do tricky things do get around the problems
     * with ; ...  */
    comm = wlist;

    while (comm) {

        int ntries;
        wordlist *end, *nextc;

        nextc = wl_find(cp_csep, comm);

        if (nextc == comm) {     /* skip leading `;' */
            comm = comm->wl_next;
            continue;
        }

        /* Temporarily hide the rest of the command... */
        end = comm->wl_prev;
        wl_chop(comm);
        wl_chop(nextc);

        for (ntries = 21; ntries; ntries--) {
            wordlist *nwl = asubst(comm);
            if (nwl == NULL)
                break;
            if (eq(nwl->wl_word, comm->wl_word)) {
                /* Just once through... */
                wl_free(comm);
                comm = nwl;
                break;
            } else {
                wl_free(comm);
                comm = nwl;
            }
        }

        if (!ntries) {
            fprintf(cp_err, "Error: alias loop.\n");
            wlist->wl_word = NULL;
            return (wlist);
        }

        wl_append(end, comm);
        wl_append(comm, nextc);

        if (!end)
            wlist = comm;

        comm = nextc;
    }

    return (wlist);
}
Exemple #2
0
void
mgv_magstep_text(Widget w, XtPointer closure, XtPointer call)
{
	MGV   *m = (MGV *)closure;
	Widget label, text, value;
	String s;
	Arg    a;
	USEUP(w);
	assert(MgvOK(m));

	wl_find(m->main,
		&text,	"*statusLine*magstepFrame*text",
		&label,	"*statusLine*magstepFrame*label",
		&value,	"*statusLine*magstepFrame*value",
		NULL);
	XtUnmanageChild(text);
	XtManageChild(value);

	XtSetArg(a, XmNrightWidget, value);
	XtSetValues(label, &a, 1);

	if(((XmAnyCallbackStruct *)call)->reason == XmCR_ACTIVATE) {
		Arg a;

		XtSetArg(a, XmNvalue, &s);
		XtGetValues(text, &a, 1);

		if(mgv_ui_magnify(m, atoi(s)))
			mgv_show(m, m->page);
	}
}
Exemple #3
0
static double *
getlims(wordlist *wl, char *name, int number)
{
    double *d;
    wordlist *beg, *wk;
    int n;

    if (number < 1)
        return NULL;

    beg = wl_find(name, wl->wl_next);

    if (!beg)
        return NULL;

    wk = beg->wl_next;

    d = TMALLOC(double, number);

    for (n = 0; n < number; n++) {

        char *ss;
        double *td;

        if (!wk) {
            fprintf(cp_err,
                    "Syntax error: not enough parameters for \"%s\".\n", name);
            txfree(d);
            return NULL;
        }

        ss = wk->wl_word;
        td = ft_numparse(&ss, FALSE);

        if (!td) {
            fprintf(cp_err,
                    "Syntax error: bad parameters for \"%s\".\n", name);
            txfree(d);
            return NULL;
        }

        d[n] = *td;

        wk = wk->wl_next;
    }

    wl_delete_slice(beg, wk);

    return d;
}
int wl_ir_init_rwl(void **irh)
{
    switch (rwl_get_remote_type()) {
    case NO_REMOTE:
    case REMOTE_WIFI: {
        struct ifreq *ifr;
        ifr = malloc(sizeof(struct ifreq));
        if (ifr) {
            memset(ifr, 0, sizeof(ifr));
            wl_find(ifr);
        }
        *irh = ifr;
    }
    break;
    default:
        break;
    }

    return 0;
}
Exemple #5
0
void
soup_cookie_jar_add_cookie(SoupCookieJar *jar, SoupCookie *cookie)
{
	struct wl_entry		*w = NULL;
	SoupCookie		*c;
	FILE			*r_cookie_f;
	char			*public_suffix;

	DNPRINTF(XT_D_COOKIE, "soup_cookie_jar_add_cookie: %p %p %p\n",
	    jar, p_cookiejar, s_cookiejar);

	if (cookies_enabled == 0)
		return;

	/* see if we are up and running */
	if (p_cookiejar == NULL) {
		_soup_cookie_jar_add_cookie(jar, cookie);
		return;
	}
	/* disallow p_cookiejar adds, shouldn't happen */
	if (jar == p_cookiejar)
		return;

	/* sanity */
	if (jar == NULL || cookie == NULL)
		return;

	/* check if domain is valid */
	public_suffix = tld_get_suffix(cookie->domain[0] == '.' ?
			cookie->domain + 1 : cookie->domain);

	if (public_suffix == NULL ||
	    (enable_cookie_whitelist &&
	    (w = wl_find(cookie->domain, &c_wl)) == NULL)) {
		blocked_cookies++;
		DNPRINTF(XT_D_COOKIE,
		    "soup_cookie_jar_add_cookie: reject %s\n",
		    cookie->domain);
		if (save_rejected_cookies) {
			if ((r_cookie_f = fopen(rc_fname, "a+")) == NULL) {
				show_oops(NULL, "can't open reject cookie file");
				return;
			}
			fseek(r_cookie_f, 0, SEEK_END);
			fprintf(r_cookie_f, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n",
			    cookie->http_only ? "#HttpOnly_" : "",
			    cookie->domain,
			    *cookie->domain == '.' ? "TRUE" : "FALSE",
			    cookie->path,
			    cookie->secure ? "TRUE" : "FALSE",
			    cookie->expires ?
			        (gulong)soup_date_to_time_t(cookie->expires) :
			        0,
			    cookie->name,
			    cookie->value);
			fflush(r_cookie_f);
			fclose(r_cookie_f);
		}
		if (!allow_volatile_cookies)
			return;
	}

	if (cookie->expires == NULL && session_timeout) {
		soup_cookie_set_expires(cookie,
		    soup_date_new_from_now(session_timeout));
		print_cookie("modified add cookie", cookie);
	}

	/* see if we are white listed for persistence */
	if ((w && w->handy) || (enable_cookie_whitelist == 0)) {
		/* add to persistent jar */
		c = soup_cookie_copy(cookie);
		print_cookie("soup_cookie_jar_add_cookie p_cookiejar", c);
		_soup_cookie_jar_add_cookie(p_cookiejar, c);
	}

	/* add to session jar */
	print_cookie("soup_cookie_jar_add_cookie s_cookiejar", cookie);
	_soup_cookie_jar_add_cookie(s_cookiejar, cookie);
}
int
wl_lib(char *input_str)
{
    struct ifreq ifr;
    char *ifname = NULL;
    int err = 0;
    int help = 0;
    int status = CMD_WL;
    void* serialHandle = NULL;
    char *tmp_argv[LINUX_NUM_ARGS];
    char **argv = tmp_argv;
    int argc;

    /* buf_to_args return 0 if no args or string too long
     * or return NDIS_NUM_ARGS if too many args
     */
    if (((argc = buf_to_args(input_str, argv)) == 0) || (argc == LINUX_NUM_ARGS)) {
        printf("wl:error: can't convert input string\n");
        return (-1);
    }
#else
/* Main client function */
int
main(int argc, char **argv)
{
    struct ifreq ifr;
    char *ifname = NULL;
    int err = 0;
    int help = 0;
    int status = CMD_WL;
#if defined(RWL_DONGLE) || RWL_SERIAL
    void* serialHandle = NULL;
#endif

#endif /* WLMSO */
    wlu_av0 = argv[0];

    wlu_init();
    memset(&ifr, 0, sizeof(ifr));
    (void)*argv++;

    if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
        if (ifname)
        {
            if (strcmp(ifname, "eth1") == 0)
            {
                strncpy(ifr.ifr_name, "wl0", IFNAMSIZ);
            }
            else if (strcmp(ifname, "eth2") == 0)
            {
                strncpy(ifr.ifr_name, "wl1", IFNAMSIZ);
            }
            else
            {
                strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
            }
        }
        /* Bug fix: If -h is used as an option, the above function call
         * will notice it and raise the flag but it won't be processed
         * in this function so we undo the argv increment so that the -h
         * can be spotted by the next call of wl_option. This will ensure
         * that wl -h [cmd] will function as desired.
         */
        else if (help)
            (void)*argv--;
    }

    /* Linux client looking for a indongle reflector */
    if (*argv && strncmp (*argv, "--indongle", strlen(*argv)) == 0) {
        rwl_dut_autodetect = FALSE;
        (void)*argv++;
    }
    /* Linux client looking for a WinVista server */
    if (*argv && strncmp (*argv, "--vista", strlen(*argv)) == 0) {
        rwl_os_type = WINVISTA_OS;
        rwl_dut_autodetect = FALSE;
        (void)*argv++;
    }

    /* Provide option for disabling remote DUT autodetect */
    if (*argv && strncmp(*argv, "--nodetect", strlen(*argv)) == 0) {
        rwl_dut_autodetect = FALSE;
        argv++;
    }

    if (*argv && strncmp (*argv, "--debug", strlen(*argv)) == 0) {
        debug = TRUE;
        argv++;
    }

    /* RWL socket transport Usage: --socket ipaddr/hostname [port num] */
    if (*argv && strncmp (*argv, "--socket", strlen(*argv)) == 0) {
        (void)*argv++;

        remote_type = REMOTE_SOCKET;

        if (!(*argv)) {
            rwl_usage(remote_type);
            return err;
        }
        /* IP address validation is done in client_shared file */
        g_rwl_servIP = *argv;
        (void)*argv++;

        g_rwl_servport = DEFAULT_SERVER_PORT;
        if ((*argv) && isdigit(**argv)) {
            g_rwl_servport = atoi(*argv);
            (void)*argv++;
        }
    }

    /* RWL from system serial port on client to uart serial port on server */
    /* Usage: --serial /dev/ttyS0 */
    if (*argv && strncmp (*argv, "--serial", strlen(*argv)) == 0) {
        (void)*argv++;
        remote_type = REMOTE_SERIAL;
    }

    /* RWL from system serial port on client to uart dongle port on server */
    /* Usage: --dongle /dev/ttyS0 */
    if (*argv && strncmp (*argv, "--dongle", strlen(*argv)) == 0) {
        (void)*argv++;
        remote_type = REMOTE_DONGLE;
    }

#if defined(RWL_SERIAL) || defined(RWL_DONGLE)
    if (remote_type == REMOTE_SERIAL || remote_type == REMOTE_DONGLE) {
        if (!(*argv)) {
            rwl_usage(remote_type);
            return err;
        }
        g_rwl_device_name_serial = *argv;
        (void)*argv++;
        if ((serialHandle = rwl_open_pipe(remote_type, g_rwl_device_name_serial, 0, 0))
                == NULL) {
            DPRINT_ERR(ERR, "serial device open error\r\n");
            return -1;
        }
        ifr = (*(struct ifreq *)serialHandle);
    }
#endif /*  RWL_SERIAL */

    /* RWL over wifi.  Usage: --wifi mac_address */
    if (*argv && strncmp (*argv, "--wifi", strlen(*argv)) == 0) {
        (void)*argv++;
        /* use default interface */
        if (!*ifr.ifr_name)
            wl_find(&ifr);
        /* validate the interface */
        if (!*ifr.ifr_name) {
            errno = ENXIO;
            syserr("interface");
        }
        if ((err = wl_check((void *)&ifr)) < 0) {
            fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
            exit(1);
        }

        remote_type = REMOTE_WIFI;

        if (argc < 4) {
            rwl_usage(remote_type);
            return err;
        }
        /* copy server mac address to local buffer for later use by findserver cmd */
        if (!wl_ether_atoe(*argv, (struct ether_addr *)g_rwl_buf_mac)) {
            fprintf(stderr,
                    "could not parse as an ethternet MAC address\n");
            return FAIL;
        }
        (void)*argv++;
    }

    if ((*argv) && (strlen(*argv) > 2) &&
            (strncmp(*argv, "--interactive", strlen(*argv)) == 0)) {
        interactive_flag = 1;
    }

    /* Process for local wl */
    if (remote_type == NO_REMOTE) {
        if (interactive_flag == 1)
            (void)*argv--;
        err = process_args(&ifr, argv);
        return err;
    } else {
#ifndef OLYMPIC_RWL
        /* Autodetect remote DUT */
        if (rwl_dut_autodetect == TRUE)
            rwl_detect((void*)&ifr, debug, &rwl_os_type);
#endif /* OLYMPIC_RWL */
    }

    /* RWL client needs to initialize ioctl_version */
    if (wl_check((void *)&ifr) != 0) {
        fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
        exit(1);
    }

    if (interactive_flag == 1) {
        err = do_interactive(&ifr);
        return err;
    }

    if ((*argv) && (interactive_flag == 0)) {
        err = process_args(&ifr, argv);
        if ((err == SERIAL_PORT_ERR) && (remote_type == REMOTE_DONGLE)) {
            DPRINT_ERR(ERR, "\n Retry again\n");
            err = process_args((struct ifreq*)&ifr, argv);
        }
        return err;
    }
    rwl_usage(remote_type);
#if defined(RWL_DONGLE) || RWL_SERIAL
    if (remote_type == REMOTE_DONGLE || remote_type == REMOTE_SERIAL)
        rwl_close_pipe(remote_type, (void*)&ifr);
#endif /* RWL_DONGLE || RWL_SERIAL */
    return err;
}

/*
 * Function called for  'local' execution and for 'remote' non-interactive session
 * (shell cmd, wl cmd)
 */
int
process_args(struct ifreq* ifr, char **argv)
{
    char *ifname = NULL;
    int help = 0;
    int status = 0;
    int vista_cmd_index;
    int err = 0;
    cmd_t *cmd = NULL;
#ifdef RWL_WIFI
    int retry;
#endif

    while (*argv) {
        if ((strcmp (*argv, "sh") == 0) && (remote_type != NO_REMOTE)) {
            (void)*argv++; /* Get the shell command */
            if (*argv) {
                /* Register handler in case of shell command only */
                err = rwl_shell_cmd_proc((void*)ifr, argv, SHELL_CMD);
            } else {
                DPRINT_ERR(ERR, "Enter the shell "
                           "command, e.g. ls(Linux) or dir(Win CE)\n");
                err = -1;
            }
            return err;
        }

#ifdef RWLASD
        if ((strcmp (*argv, "asd") == 0) && (remote_type != NO_REMOTE)) {
            (void)*argv++; /* Get the asd command */
            if (*argv) {
                err = rwl_shell_cmd_proc((void*)ifr, argv, ASD_CMD);
            } else {
                DPRINT_ERR(ERR, "Enter the ASD command, e.g. ca_get_version\n");
                err = -1;
            }
            return err;
        }
#endif
        if (rwl_os_type == WINVISTA_OS) {
            for (vista_cmd_index = 0; remote_vista_cmds[vista_cmd_index] &&
                    strcmp(remote_vista_cmds[vista_cmd_index], *argv);
                    vista_cmd_index++);
            if (remote_vista_cmds[vista_cmd_index] != NULL) {
                err = rwl_shell_cmd_proc((void *)ifr, argv, VISTA_CMD);
                if ((remote_type == REMOTE_WIFI) && ((!strcmp(*argv, "join")))) {
#ifdef RWL_WIFI
                    DPRINT_INFO(OUTPUT,
                                "\nChannel will be synchronized by Findserver\n\n");
                    sleep(RWL_WIFI_JOIN_DELAY);
                    for (retry = 0; retry < RWL_WIFI_RETRY; retry++) {
                        if ((rwl_find_remote_wifi_server(ifr,
                                                         &g_rwl_buf_mac[0]) == 0)) {
                            break;
                        }
                    }
#endif /* RWL_WIFI */
                }
                return err;
            }
        }

        if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
            if (help)
                break;
            if (ifname) {
                if (remote_type == NO_REMOTE) {
                    strncpy((*ifr).ifr_name, ifname, IFNAMSIZ);
                }
                else {
                    strncpy(g_rem_ifname, ifname, IFNAMSIZ);
                }
            }
            continue;
        }
        /* parse error */
        else if (status == CMD_ERR)
            break;

        if (remote_type == NO_REMOTE) {
            /* use default interface */
            if (!*(*ifr).ifr_name)
                wl_find(ifr);
            /* validate the interface */
            if (!*(*ifr).ifr_name) {
                errno = ENXIO;
                syserr("interface");
            }
            if ((err = wl_check((void *)ifr)) < 0) {
                fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
                exit(1);
            }

            if ((strcmp (*argv, "--interactive") == 0) || (interactive_flag == 1)) {
                err = do_interactive(ifr);
                return err;
            }
        }
        /* search for command */
        cmd = wl_find_cmd(*argv);
        /* if not found, use default set_var and get_var commands */
        if (!cmd) {
            cmd = &wl_varcmd;
        }
#ifdef RWL_WIFI
        if (!strcmp(cmd->name, "findserver")) {
            remote_wifi_ser_init_cmds((void *) ifr);
        }
#endif /* RWL_WIFI */

        /* RWL over Wifi supports 'lchannel' command which lets client
         * (ie *this* machine) change channels since normal 'channel' command
         * applies to the server (ie target machine)
         */
        if (remote_type == REMOTE_WIFI)	{
#ifdef RWL_WIFI
            if (!strcmp(argv[0], "lchannel")) {
                strcpy(argv[0], "channel");
                rwl_wifi_swap_remote_type(remote_type);
                err = (*cmd->func)((void *) ifr, cmd, argv);
                rwl_wifi_swap_remote_type(remote_type);
            } else {
                err = (*cmd->func)((void *) ifr, cmd, argv);
            }
            /* After join cmd's gets exeuted on the server side , client needs to know
            * the channel on which the server is associated with AP , after delay of
            * few seconds client will intiate the scan on diffrent channels by calling
            * rwl_find_remote_wifi_server fucntion
            */
            if ((!strcmp(cmd->name, "join") || ((!strcmp(cmd->name, "ssid") &&
                                                 (*(++argv) != NULL))))) {
                DPRINT_INFO(OUTPUT, "\n Findserver is called to synchronize the"
                            "channel\n\n");
                sleep(RWL_WIFI_JOIN_DELAY);
                for (retry = 0; retry < RWL_WIFI_RETRY; retry++) {
                    if ((rwl_find_remote_wifi_server(ifr,
                                                     &g_rwl_buf_mac[0]) == 0)) {
                        break;
                    }
                }
            }
#endif /* RWL_WIFI */
        } else {
            /* do command */
            err = (*cmd->func)((void *) ifr, cmd, argv);
        }
        break;
    } /* while loop end */

    /* provide for help on a particular command */
    if (help && *argv) {
        cmd = wl_find_cmd(*argv);
        if (cmd) {
            wl_cmd_usage(stdout, cmd);
        } else {
            DPRINT_ERR(ERR, "%s: Unrecognized command \"%s\", type -h for help\n",
                       wlu_av0, *argv);
        }
    } else if (!cmd)
        wl_usage(stdout, NULL);
    else if (err == USAGE_ERROR)
        wl_cmd_usage(stderr, cmd);
    else if (err == IOCTL_ERROR)
        wl_printlasterror((void *) ifr);
    else if (err == BCME_NODEVICE)
        DPRINT_ERR(ERR, "%s : wl driver adapter not found\n", g_rem_ifname);

    return err;
}
Exemple #7
0
/* Note that we only do io redirection when we get to here - we also
 * postpone some other things until now.  */
static void
docommand(wordlist *wlist)
{
    wordlist *rwlist;

    if (cp_debug) {
        printf("docommand ");
        wl_print(wlist, stdout);
        putc('\n', stdout);
    }

    /* Do all the things that used to be done by cshpar when the line
     * was read...  */
    wlist = cp_variablesubst(wlist);
    pwlist(wlist, "After variable substitution");

    wlist = cp_bquote(wlist);
    pwlist(wlist, "After backquote substitution");

    wlist = cp_doglob(wlist);
    pwlist(wlist, "After globbing");

    pwlist_echo(wlist, "Becomes >");

    if (!wlist || !wlist->wl_word) /*CDHW need to free wlist in second case? CDHW*/
        return;

    /* Now loop through all of the commands given. */
    rwlist = wlist;
    while (wlist) {

        char *s;
        int i;
        struct comm *command;
        wordlist *nextc, *ee;

        nextc = wl_find(cp_csep, wlist);

        if (nextc == wlist) {   /* skip leading `;' */
            wlist = wlist->wl_next;
            continue;
        }

        /* Temporarily hide the rest of the command... */
        ee = wlist->wl_prev;
        wl_chop(nextc);
        wl_chop(wlist);

        /* And do the redirection. */
        cp_ioreset();
        for (i = 0; noredirect[i]; i++)
            if (eq(wlist->wl_word, noredirect[i]))
                break;
        if (!noredirect[i])
            if ((wlist = cp_redirect(wlist)) == NULL) {
                cp_ioreset();
                return;
            }

        /* Get rid of all the 8th bits now... */
        cp_striplist(wlist);

        s = wlist->wl_word;

        /* Look for the command in the command list. */
        for (i = 0; cp_coms[i].co_comname; i++)
            if (strcasecmp(cp_coms[i].co_comname, s) == 0)
                break;

        command = &cp_coms[i];

        /* Now give the user-supplied command routine a try... */
        if (!command->co_func && cp_oddcomm(s, wlist->wl_next))
            goto out;

        /* If it's not there, try it as a unix command. */
        if (!command->co_comname) {
            if (cp_dounixcom && cp_unixcom(wlist))
                goto out;
            fprintf(cp_err, "%s: no such command available in %s\n",
                    s, cp_program);
            goto out;

            /* If it hasn't been implemented */
        } else if (!command->co_func) {
            fprintf(cp_err, "%s: command is not implemented\n", s);
            goto out;
            /* If it's there but spiceonly, and this is nutmeg, error. */
        } else if (ft_nutmeg && command->co_spiceonly) {
            fprintf(cp_err, "%s: command available only in spice\n", s);
            goto out;
        }

        /* The command was a valid spice/nutmeg command. */
        {
            int nargs = wl_length(wlist->wl_next);
            if (nargs < command->co_minargs) {
                if (command->co_argfn) {
                    command->co_argfn (wlist->wl_next, command);
                } else {
                    fprintf(cp_err, "%s: too few args.\n", s);
                }
            } else if (nargs > command->co_maxargs) {
                fprintf(cp_err, "%s: too many args.\n", s);
            } else {
                command->co_func (wlist->wl_next);
            }
        }

    out:
        wl_append(ee, wlist);
        wl_append(wlist, nextc);

        if (!ee)
            rwlist = wlist;

        wlist = nextc;
    }

    wl_free(rwlist);

    /* Do periodic sorts of things... */
    cp_periodic();

    cp_ioreset();
}
Exemple #8
0
static void
file_save_write(Widget w, XtPointer closure, XtPointer call)
{
	MGV	*m = (MGV *)closure;
	MGV_APP *r;
	FILE	*fp;
	Boolean	unmark, marked;
	int	i;
	Widget	sm, su;
	char	*p;
	USEUP(w); USEUP(call);
	assert(MgvOK(m));

	assert(m->savefile != NULL);

	wl_find(m->fs_save,
		&sm,	"*saveMarked",
		&su,	"*saveUnmark",
		NULL);

	/*
	 * saveMarked and saveUnmark should always have the same
	 * sensitivity
	 */
	assert(XtIsSensitive(su) == XtIsSensitive(sm));
	marked = unmark = False;
	if(XtIsSensitive(sm)) {
		marked = XmToggleButtonGetState(sm);
		unmark = XmToggleButtonGetState(su);
	}

	fp = NULL;
	r = mgv_appres(m->main);
	if((p = strrchr(m->savefile, '.')) != NULL) {
		if(strcmp(p, ".gz") == 0)
			fp = comp(m, r->gzip, m->savefile);
		else if(strcmp(p, ".Z") == 0)
			fp = comp(m, r->compress, m->savefile);
		else if(strcmp(p, ".bz2") == 0)
			fp = comp(m, r->bzip, m->savefile);
	}
	if(fp == NULL)
		fp = fopen(m->savefile, "w");

	if(fp == NULL) {
		wl_error(w, "%s %s: %s", mgv_s(w, MgvScantOpen),
					m->savefile, strerror(errno));
		XtFree((XtPointer)m->savefile);
		m->savefile = NULL;
		if(m->save_query != NULL)
			XtUnmanageChild(m->save_query);
		return;
	}

	XtFree((XtPointer)m->savefile);
	m->savefile = NULL;

	mgv_write(m, fp, marked);
	fclose(fp);

	if(unmark && m->dsc != NULL) {
		for(i = 0; i < m->dsc->n_pages; ++i)
			mgv_mark(m, i, FALSE, FALSE);
		mgv_list_update(m, -1);
	}

	wl_dlg_popdown(m->fs_save);
}
Exemple #9
0
int
wl_save(struct tab *t, struct karg *args, int list)
{
	char			file[PATH_MAX], *lst_str = NULL;
	FILE			*f = NULL;
	char			*line = NULL, *lt = NULL, *dom;
	size_t			linelen;
	const gchar		*uri;
	struct karg		a;
	struct domain		*d;
	GSList			*cf;
	SoupCookie		*ci, *c;

	if (t == NULL || args == NULL)
		return (1);

	if (runtime_settings[0] == '\0')
		return (1);

	switch (list) {
	case XT_WL_JAVASCRIPT:
		lst_str = "JavaScript";
		break;
	case XT_WL_COOKIE:
		lst_str = "Cookie";
		break;
	case XT_WL_PLUGIN:
		lst_str = "Plugin";
		break;
	default:
		show_oops(t, "Invalid list id: %d", list);
		return (1);
	}

	uri = get_uri(t);
	dom = find_domain(uri, args->i & XT_WL_TOPLEVEL);
	if (uri == NULL || dom == NULL ||
	    webkit_web_view_get_load_status(t->wv) == WEBKIT_LOAD_FAILED) {
		show_oops(t, "Can't add domain to %s white list", lst_str);
		goto done;
	}

	switch (list) {
	case XT_WL_JAVASCRIPT:
		lt = g_strdup_printf("js_wl=%s", dom);
		break;
	case XT_WL_COOKIE:
		lt = g_strdup_printf("cookie_wl=%s", dom);
		break;
	case XT_WL_PLUGIN:
		lt = g_strdup_printf("pl_wl=%s", dom);
		break;
	default:
		/* can't happen */
		show_oops(t, "Invalid list id: %d", list);
		goto done;
	}

	snprintf(file, sizeof file, "%s" PS "%s", work_dir, runtime_settings);
	if ((f = fopen(file, "r+")) == NULL) {
		show_oops(t, "can't open file %s");
		goto done;
	}

	while (!feof(f)) {
		line = fparseln(f, &linelen, NULL, NULL, 0);
		if (line == NULL)
			continue;
		if (!strcmp(line, lt))
			goto done;
		free(line);
		line = NULL;
	}

	fprintf(f, "%s\n", lt);

	a.i = XT_WL_ENABLE;
	a.i |= args->i;
	switch (list) {
	case XT_WL_JAVASCRIPT:
		d = wl_find(dom, &js_wl);
		if (!d) {
			settings_add("js_wl", dom);
			d = wl_find(dom, &js_wl);
		}
		toggle_js(t, &a);
		break;

	case XT_WL_COOKIE:
		d = wl_find(dom, &c_wl);
		if (!d) {
			settings_add("cookie_wl", dom);
			d = wl_find(dom, &c_wl);
		}
		toggle_cwl(t, &a);

		/* find and add to persistent jar */
		cf = soup_cookie_jar_all_cookies(s_cookiejar);
		for (;cf; cf = cf->next) {
			ci = cf->data;
			if (!strcmp(dom, ci->domain) ||
			    !strcmp(&dom[1], ci->domain)) /* deal with leading . */ {
				c = soup_cookie_copy(ci);
				_soup_cookie_jar_add_cookie(p_cookiejar, c);
			}
		}
		soup_cookies_free(cf);
		break;

	case XT_WL_PLUGIN:
		d = wl_find(dom, &pl_wl);
		if (!d) {
			settings_add("pl_wl", dom);
			d = wl_find(dom, &pl_wl);
		}
		toggle_pl(t, &a);
		break;
	default:
		abort(); /* can't happen */
	}
	if (d)
		d->handy = 1;

done:
	if (line)
		free(line);
	if (dom)
		g_free(dom);
	if (lt)
		g_free(lt);
	if (f)
		fclose(f);

	return (0);
}
Exemple #10
0
int
main(int argc, char **argv)
#endif
{
	struct ifreq ifr;
	cmd_t *cmd = NULL;
	int err = 0;
	char *ifname = NULL;
	int help = 0;
	int status = CMD_WL;

	av0 = argv[0];

	memset(&ifr, 0, sizeof(ifr));

	for (++argv; *argv;) {

		/* command option */
		if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
			if (help)
				break;
			if (ifname)
				strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
			continue;
		}
		/* parse error */
		else if (status == CMD_ERR)
			break;
		/* wl command */
		/*
		 * else if (status == CMD_WL)
		 *	;
		 */

		/* use default interface */
		if (!*ifr.ifr_name)
			wl_find(&ifr);
		/* validate the interface */
		if (!*ifr.ifr_name || wl_check((void *)&ifr)) {
			fprintf(stderr, "%s: wl driver adapter not found\n", av0);
#ifdef DSLCPE_SHLIB
			return -1;
#else			
			exit(1);
#endif			
		}

		/* search for command */
		cmd = wl_find_cmd(*argv);

		/* defaults to using the set_var and get_var commands */
		if (!cmd)
			cmd = &wl_varcmd;

		/* do command */
		err = (*cmd->func)((void *) &ifr, cmd, argv);

		break;
	}

	if (help && *argv) {
		cmd = wl_find_cmd(*argv);
		if (cmd)
			cmd_usage(stdout, cmd);
		else {
			printf("%s: Unrecognized command \"%s\", type -h for help\n",
			       av0, *argv);
		}
	}
	else if (!cmd)
		wl_usage(stdout, NULL);
	else if (err == USAGE_ERROR)
		cmd_usage(stderr, cmd);
	else if (err == IOCTL_ERROR)
		wl_printlasterror((void *) &ifr);
	return err;
}