home *** CD-ROM | disk | FTP | other *** search
- /*
- * member.c
- * Handle membership forms.
- *
- * Copyright 1995 First Virtual Holdings Inc. All Rights Reserved.
- */
-
- /*
- Copyright (c) 1994 FIRST VIRTUAL HOLDINGS INCORPORATED
- FIRST VIRTUAL (TM) and the FIRST VIRTUAL logo are service marks
- of First Virtual Holdings Incorporated.
-
- Permission to use, copy, modify, and distribute this material
- for any purpose and without fee is hereby granted, provided
- that the above copyright notice and this permission notice
- appear in all copies, and that the name of First Virtual not be
- used in advertising or publicity pertaining to this
- material without the specific, prior written permission
- of First Virtual Holdings Incorporated. FIRST VIRTUAL
- MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
- OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
- WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
-
- */
-
- /* SEE config.h for installation configuration */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h> /* for isalpha and isdigit */
- #include <string.h> /* for strstr() and the usual */
- #include <time.h> /* for time() */
- #include <unistd.h> /* for getpid() */
-
- #include "config.h" /* for configuring this program */
-
- extern char *membershipContents, *badacctContents, *blewitContents, *noaccessContents, *thankyouContents;
-
- int goodfinger(s) char * s;
- {
- /* This return 1 if the PIN described by the finger in s is
- active, else zero */
- int ret;
- char * p;
- char * q;
- char * r;
-
- ret = 0;
- p = strstr(s, "Account-Status:");
- if (p) {
- q = strstr(p, "active");
- if (q) {
- ret = 1;
- for (r = p; r < q; r++) {
- if (*r=='\n') ret = 0;
- }
- }
- }
- return ret;
- }
-
- void main()
- {
- char * qs; /* Query string */
- char * as; /* Action string */
- char FVPIN[50]; /* First Virtual ID */
- char price[40]; /* The price to charge */
- char * * fnp; /* Field name pointer */
- char fc[2000]; /* Field contents */
- char * fcp; /* Field contents pointer */
- char xferid[40];/* Transfer ID */
- FILE * pf; /* pipe file */
- char junkbuf[2000];
- char inbuf[4000]; /* Input buffer for POST method */
- char * cl; /* content length */
- int cli; /* content length as an integer */
- int i; /* temp int */
-
- as = getenv("SCRIPT_NAME");
- if (as == NULL) as = "?NONE?";
- cl = getenv("CONTENT_LENGTH");
- if (cl && *cl && 0 != (cli = atoi(cl))) {
- if (sizeof(inbuf) < cli + 5) {
- printf("Content-type: text/plain\n\nServer error one?\n");
- exit(0);
- }
- qs = inbuf;
- while (0 < cli) {
- i = read(0, qs, cli);
- if (i < 1) {
- printf("Content-type: text/plain\n\nServer error two?\n");
- exit(0); /* Eh? */
- }
- qs += i; cli -= i;
- }
- *qs = 0;
- qs = inbuf;
- }
- else {
- qs = getenv("QUERY_STRING");
- }
- if (!qs || !*qs) {
- int i = 0;
- printf("Content-type: text/html\n\n");
- fflush(stdout);
- while (0 != strncmp("ACTIONPROGURL", membershipContents+i,
- strlen("ACTIONPROGURL"))) {
- putchar(membershipContents[i]);
- i++;
- }
- fputs(as, stdout); i += strlen("ACTIONPROGURL");
- puts(membershipContents + i);
- exit(0);
- }
- /* Here he has filled out the form */
- /* See if he gave us a FVPIN and check it if so. */
- FVPIN[0] = 0; xferid[0] = 0;
- parseurl(qs, "FVPIN", FVPIN, sizeof(FVPIN));
- strcpy(price, amount);
- if (!price[0]) parseurl(qs, "price", price, sizeof(price));
- for (i = 0; price[i]; i++) {
- if (!isdigit(price[i]) && price[i] != '.')
- price[i] = ' ';
- }
- if (atof(price) <= 0.0) price[0] = 0; /* not a valid price */
- else sprintf(price, "%0.2f", atof(price));
- if (FVPIN[0] && price[0]) {
- /* He gave us an ID and an amount -- check and charge */
- char fingerout[2000];
- char fingerin[200];
- int i;
- strcpy(fingerin, fingerpath);
- strcat(fingerin, " ");
- for (i=0; FVPIN[i]; i++) {
- if (isalpha(FVPIN[i])||isdigit(FVPIN[i])) {
- fingerin[strlen(fingerin)+1]=0;
- fingerin[strlen(fingerin)]=FVPIN[i];
- }
- }
- strcat(fingerin, fingeraddr);
- pf = popen(fingerin, "r");
- if (!pf) {
- /* What to do if you can't finger? */
- puts(noaccessContents);
- exit(1);
- }
- i = fread(fingerout, 1, sizeof(fingerout)-2, pf);
- if (i < 1) {
- /* Again, can't finger */
- puts(noaccessContents);
- exit(1);
- }
- fingerout[i] = 0;
- if (goodfinger(fingerout)) {
- /* Bill them */
- /* First, a transfer ID */
- sprintf(xferid, "<%d.%d@%s>",
- time(NULL), getpid(), mymach);
- sprintf(junkbuf, "%s %s %s", mailpath, xferaddr, handleraddr);
- pf = popen(junkbuf, "w");
- if (!pf) {
- puts(noaccessContents);
- exit(1);
- }
- fprintf(pf, "Content-type: application/green-commerce; transaction=transfer-request\n");
- fprintf(pf, "Subject: %s (TRANSFER)\n", desc);
- fprintf(pf, "From: %s\n", handleraddr);
- fprintf(pf, "To: %s\nCC: %s\n\n", xferaddr, handleraddr);
- fprintf(pf, "Seller: %s\nBuyer: %s\n",
- mysellid, FVPIN);
- fprintf(pf, "Amount: %s\nCurrency: %s\n",
- price, currency);
- fprintf(pf, "Payment-expected: no\n");
- fprintf(pf, "Description: %s\nTransfer-id: %s\n",
- desc, xferid);
- fprintf(pf, "\n\n");
- /* Add more descriptive text here if you want. */
- pclose(pf);
- }
- else {
- /* The account is not active */
- puts(badacctContents);
- printf("%s\n</pre>\n", fingerout);
- exit(0);
- }
- }
- else {
- /* Here, they didn't give us a FVPIN */
- /* Do nothing except set the form properly below */
- }
- /* If we got this far, we submitted a bill if we had their ID. */
- /* Here, we collect the other info. */
- sprintf(junkbuf, "%s %s", mailpath, handleraddr);
- pf = popen(junkbuf, "w");
- if (!pf) {
- puts(blewitContents);
- exit(0);
- }
- fprintf(pf, "Subject: %s (FIELDS)\n", desc);
- fprintf(pf, "From: %s\n", handleraddr);
- fprintf(pf, "To: %s\n\n", handleraddr);
- for (fnp=fields; *fnp; fnp++) {
- fc[0] = 0;
- parseurl(qs, *fnp, fc, sizeof(fc));
- if (fc[0]) {
- /* We got a field. Add it to the output */
- fprintf(pf, "%s: ", *fnp);
- for (fcp=fc; *fcp; fcp++) {
- if ('\r'!=*fcp)
- fputc(*fcp, pf);
- if ('\n'==*fcp)
- fputc(' ', pf);
- }
- fputc('\n', pf);
- }
- }
- fprintf(pf, "Script: %s\n", as);
- fprintf(pf, "Transfer-id: %s\n", xferid);
- fprintf(pf, "Price: %s\n", price);
- pclose(pf);
- puts(thankyouContents);
- exit(0);
- }
-