9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: steve.simon@snellwilcox.com
To: 9fans@cse.psu.edu
Subject: [9fans] cookies
Date: Fri, 13 Jun 2003 12:17:40 +0100	[thread overview]
Message-ID: <ae0b6c644c0614fd374319b1514f4ed2@snellwilcox.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

Hi,

Answering my question, I wrote the cooke converter code attached.

I am using cookies because is that we have a web based bullitin board here,
behind the firewall, that uses a cookie for authentication, nothing
secret, just to ensure posts have their owners names attached so
I feel cookies are an apropriate level of security - no matter
wat you all say :-)

-Steve

[-- Attachment #2: cookconv.c --]
[-- Type: text/plain, Size: 1306 bytes --]

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

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

	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=%ld\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(args, i);
					for (j = 0; j < i; j++)
						free(args[j]);
					break;
				}
			}
		}
fin:
		Bterm(b);
	}
}

                 reply	other threads:[~2003-06-13 11:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae0b6c644c0614fd374319b1514f4ed2@snellwilcox.com \
    --to=steve.simon@snellwilcox.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).