From: Ferran P. <fer...@re...> - 2002-08-08 14:32:51
|
It's easy. To call the routine you should terminate the parametre wirh a NULL (binary 0). Somryhing like this should work : move spaces to parameter-wor. string address-to-verify delimited by size x'00' delimited by size into parameter-wor. call "cgi_goodemailaddress" using parameter-wor. Then you should coimpile the COBOL sources and link it with the C object. to make an executable. Hudson Reis wrote: >Hi all, > >I'm trying to interface my COBOL programs with the cgi-util library. However I've been having a problem: > >I'm only a COBOL programmer, I don't know C, and I would like to use the routines cgi_goodemailaddress and cgi_getcookie. > >Could any C programmer help me? > >The routines are attached below: > >Thanks >Hudson > >/* Returns whether or not an e-mail address appears to be in the correct > syntax ("use...@ho...main"): */ > >int cgi_goodemailaddress(const char * addr) >{ > int i; > > /* No "@".. what? */ > > if (strchr(addr, '@') == NULL) > return 0; > > > /* "@" or "." at the end or beginning? */ > > if (addr[strlen(addr - 1)] == '@' || > addr[strlen(addr - 1)] == '.' || > addr[0] == '@' || addr[0] == '.') > return 0; > > > /* No "." after the "@"? More than one "@"? */ > > if (strchr(strchr(addr, '@'), '.') == NULL || > strchr(strchr(addr, '@') + 1, '@') != NULL) > return 0; > > > /* Any illegal characters within the string? */ > > for (i = 0; i < strlen(addr); i++) > { > if (isalnum(addr[i]) == 0 && > addr[i] != '.' && addr[i] != '@' && addr[i] != '_' && > addr[i] != '-') > return(0); > } > > > /* Must be ok... */ > > return 1; >} > >/* Grab a cookie, if it exists. Return NULL if it doesn't: */ >/* (Based on code by Pete Cassidy (pca...@io...) - May 10, 2000) */ > >const char * cgi_getcookie(const char * cookie_name) >{ > char * cookieval, * tmpcookie, * rawcookie, * left, * right; > int done; > printf(cookie_name); > > > /* Get raw cookie data: */ > > rawcookie = getenv("HTTP_COOKIE"); > if (rawcookie == NULL) > { > /* No cookies at all? The cookie we want can't exist! */ > > cgi_errno = CGIERR_NO_COOKIES; > return(NULL); > } > > > /* Strtok is destructive, so make a temporary copy of the raw cookie data: */ > > tmpcookie = malloc(sizeof(char) * (strlen(rawcookie) + 1)); > if (tmpcookie == NULL) > { > cgi_errno = CGIERR_OUT_OF_MEMORY; > return(NULL); > } > > strcpy(tmpcookie, rawcookie); > > > /* Tokenize out all cookies and check for the one we're looking for: */ > > left = strtok(tmpcookie, ";"); > cookieval = NULL; > done = 0; > > do > { > /* Grab the righthand size of the current cookie pair's "=" sign: */ > > right = strchr(left, '=') + (1 * sizeof(char)); > > > /* Change the "=" into a NULL character, to get the lefthand side: */ > > *strchr(left, '=') = '\0'; > > > /* See if this is our cookie: */ > > if (strcmp(left, cookie_name) == 0) > { > /* If so, set our return-string to the value (righthand side): */ > > cookieval = malloc(sizeof(char) * (strlen(right) + 1)); > if (cookieval == NULL) > { > cgi_errno = CGIERR_OUT_OF_MEMORY; > return(NULL); > } > > strcpy(cookieval, right); > done = 1; > } > > > /* Jump to next cookie: */ > > if (!done) > { > left = strtok(NULL, ";"); > if (left == NULL) > { > /* No more to parse? */ > > done = 1; > } > else > { > /* Skip the extra space: */ > > left++; > } > } > } > while (!done); > > > /* Free the temporary copy of the raw cookie data: */ > > free(tmpcookie); > > > /* Return the cookie value (which may be NULL if we never found it): */ > > if (cookieval == NULL) > cgi_errno = CGIERR_COOKIE_NOT_FOUND; > else > cgi_errno = CGIERR_NONE; > > return(cookieval); >} > > > > > > > > -- Salutacions / Regards +---------------------------------------------------------------+ | Ferran Pegueroles Forcadell | | mailto:fer...@re... | | Tels (+34)937252106 - (+34)667658535 | | C/Unió 44 2n 2a 08201 Sabadell (BCN) | +---------------------------------------------------------------+ |