⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookies.c

📁 this gives details of the network programming
💻 C
字号:
#include <stdio.h>#include <stdlib.h>	/* for getenv */#include <string.h>/* extract a list of cookies from the HTTP_COOKIE environment variable.   fills in 2 arrays with the names and values of each cookie found.   cookies are seperated by the ';'.   returns the number of cookies found.   the cookie names are put in the array names, the    values in vals - this function assumes both exist and   have room for maxcookies elements (each element is a (char *).   I have a hard time with a variable named maxcookies, since   there is no such thing as a maximum number of cookies.    There are never enough cookies for me...*/int get_cookies(char **names, char **vals, int maxcookies) {  int n=0;  char *cookies;  char *ptr;  char *eqs;  cookies = getenv("HTTP_COOKIE");  if (! cookies)     return(0);	/* no cookies found (sigh...) */    ptr = strtok(cookies,";");  while (ptr) {		/* while cookies remain */    /* find the = sign everything before it is the name       and everything after it is the value */    eqs = strchr(ptr,'=');    if (!eqs) break;  /* not found - give up */    *eqs=0;    if (*ptr==' ') ptr++;    names[n]=strdup(ptr);	/* make a copy of the cookie name */    vals[n] = strdup(eqs+1);	/* make a copy of the cookie value */        /* if everything worked - move on        otherwise give up looking any furthur    */    if (names[n] && vals[n]) {      n++;    } else {      break;  /* some problem, give up and return what we now have */    }    ptr = strtok(NULL,";");  }  return(n);}/* given a pair of arrays containing pointers to cookie names   and values, extract a named cookie and return it's value */char *cookie_lookup(char **names, char **vals, int num, char *cookiename) {  int i;  int len = strlen(cookiename);  for (i=0;i<num;i++) {    if (strncmp(names[i],cookiename,len)==0 ) {      /* found it - return the value */      return(vals[i]);    }  }  return(NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -