Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/misc/cookconv.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/* cookieconv.c - convert Microsoft IE6 cookie files into webcookies(4) format */
#include <u.h>
#include <libc.h>
#include <bio.h>

int
parse(int n, char **args)
{
	char *name, *value, *path, *domain;
	vlong expire;
	int secure;

	if (n < 8)
		sysfatal("parse: not enough args\n");

	if (strcmp(args[8], "*") != 0)
		return -1;

	name = args[0];
	value = args[1];
	if ((path = strchr(args[2], '/')) == nil)
		return -1;
	*path++ = 0;
	domain = args[2];
	secure = atoi(args[3]) & 1;

	expire = atoll(args[4]) + (atoll(args[5]) << 32);
	expire /= 10000000LL;		// nanosec to sec
	expire -= 11644473600LL;	// MS epoch to POSIX epoch

	print("name=%s value=%s path=/%s domain=%s secure=%d expire=%lld\n",
	    name, value, path, domain, secure, expire);

	return 0;
}

void
main(int argc, char *argv[])
{
	int i, j;
	Biobuf *b;
	char *args[20];		// the most I have seen is 10

	argv0 = argv[0];
	while(argv++, --argc){
		if ((b = Bopen(*argv, OREAD)) == nil){
			fprint(2, "%s: %s cannot open - %r\n", argv0, *argv);
			continue;
		}
		while(1){
			for (i = 0; i < nelem(args); i++){
				if ((args[i] = Brdstr(b, '\n', 1)) == nil)
					goto fin;
				if (strcmp(args[i], "*") == 0){
					parse(i, args);
					for (j = 0; j < i; j++)
						free(args[j]);
					break;
				}
			}
		}		
fin:
		Bterm(b);
	}
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.