int addParentProxy(char *parentAddr,char *parentKey,char *srvIP,char *srvPort, char *friendName) //modified by yangkun { ParentProxyPtr prtPrxs,node; AtomPtr allowIP; AtomListPtr tempList; prtPrxs=ParentProxys; allowIP=internAtom(srvIP); tempList=findProxyClient(allowIP->string); while(prtPrxs){ if(strcmp(prtPrxs->addr->string,parentAddr)==0){ prtPrxs->key=internAtom(parentKey); prtPrxs->keyHash=keyHasher(prtPrxs->key->string, prtPrxs->key->length); if (node->port) { releaseAtom(node->port); } if (node->friendName) { releaseAtom(node->friendName); } node->port=internAtom(srvPort); node->friendName=internAtom(friendName); if(prtPrxs->allowIP){ free(prtPrxs->allowIP); prtPrxs->allowIP=NULL; } if(tempList){ prtPrxs->allowIP=parseNetAddress(tempList); } return(1); } if(prtPrxs->next==NULL)break; prtPrxs=prtPrxs->next; } node=malloc(sizeof(ParentProxyRec)); node->next=NULL; node->addr=internAtom(parentAddr); node->key=internAtom(parentKey); node->keyHash=keyHasher(node->key->string, node->key->length); node->port=internAtom(srvPort); node->friendName=internAtom(friendName); if(tempList){ node->allowIP=parseNetAddress(tempList); } if(ParentProxys) prtPrxs->next=node; /*{ node->next=ParentProxys; ParentProxys=node; }*/ else ParentProxys=node; return(1); }
int updateParentProxy(char *parentAddr,char *parentKey,char *srvIP) //add by humeng @2011.5.12 { ParentProxyPtr node,temp; AtomPtr allowIP; AtomListPtr tempList; node=malloc(sizeof(ParentProxyRec)); node->next=NULL; node->addr=internAtom(parentAddr); node->key=internAtom(parentKey); node->keyHash=keyHasher(node->key->string, node->key->length); node->port=internAtom("8123"); allowIP=internAtom(srvIP); tempList=findProxyClient(allowIP->string); if(tempList){ node->allowIP=parseNetAddress(tempList); } if(ParentProxys==NULL) { ParentProxys=node; return 1; }else{ temp=ParentProxys; //add by humeng @ 2011.5.16 node->next=ParentProxys->next; ParentProxys=node; free(temp); //add by humeng @ 2011.5.16 } return 1; }
void initHttp() { char *buf = NULL; int namelen; int n; struct hostent *host; initHttpParser(); atom100Continue = internAtom("100-continue"); if(clientTimeout <= serverTimeout) { clientTimeout = serverTimeout + 1; do_log(L_WARN, "Value of clientTimeout too small -- setting to %d.\n", clientTimeout); } if(displayName == NULL) displayName = internAtom("Polipo"); if(authCredentials != NULL && authRealm == NULL) authRealm = internAtom("Polipo"); if(allowedClients) { allowedNets = parseNetAddress(allowedClients); if(allowedNets == NULL) exit(1); } if(allowedPorts == NULL) { allowedPorts = makeIntList(0); if(allowedPorts == NULL) { do_log(L_ERROR, "Couldn't allocate allowedPorts.\n"); exit(1); } intListCons(80, 100, allowedPorts); intListCons(1024, 0xFFFF, allowedPorts); } if(tunnelAllowedPorts == NULL) { tunnelAllowedPorts = makeIntList(0); if(tunnelAllowedPorts == NULL) { do_log(L_ERROR, "Couldn't allocate tunnelAllowedPorts.\n"); exit(1); } intListCons(22, 22, tunnelAllowedPorts); /* ssh */ intListCons(80, 80, tunnelAllowedPorts); /* HTTP */ intListCons(109, 110, tunnelAllowedPorts); /* POP 2 and 3*/ intListCons(143, 143, tunnelAllowedPorts); /* IMAP 2/4 */ intListCons(443, 443, tunnelAllowedPorts); /* HTTP/SSL */ intListCons(873, 873, tunnelAllowedPorts); /* rsync */ intListCons(993, 993, tunnelAllowedPorts); /* IMAP/SSL */ intListCons(995, 995, tunnelAllowedPorts); /* POP/SSL */ intListCons(2401, 2401, tunnelAllowedPorts); /* CVS */ intListCons(5222, 5223, tunnelAllowedPorts); /* Jabber */ intListCons(9418, 9418, tunnelAllowedPorts); /* Git */ } if(proxyName) return; buf = get_chunk(); if(buf == NULL) { do_log(L_ERROR, "Couldn't allocate chunk for host name.\n"); goto fail; } n = gethostname(buf, CHUNK_SIZE); if(n != 0) { do_log_error(L_WARN, errno, "Gethostname"); strcpy(buf, "polipo"); goto success; } /* gethostname doesn't necessarily NUL-terminate on overflow */ buf[CHUNK_SIZE - 1] = '\0'; if(strcmp(buf, "(none)") == 0 || strcmp(buf, "localhost") == 0 || strcmp(buf, "localhost.localdomain") == 0) { do_log(L_WARN, "Couldn't determine host name -- using ``polipo''.\n"); strcpy(buf, "polipo"); goto success; } if(strchr(buf, '.') != NULL) goto success; host = gethostbyname(buf); if(host == NULL) { goto success; } if(host->h_addrtype != AF_INET) goto success; host = gethostbyaddr(host->h_addr_list[0], host->h_length, AF_INET); if(!host || !host->h_name || strcmp(host->h_name, "localhost") == 0 || strcmp(host->h_name, "localhost.localdomain") == 0) goto success; namelen = strlen(host->h_name); if(namelen >= CHUNK_SIZE) { do_log(L_ERROR, "Host name too long.\n"); goto success; } memcpy(buf, host->h_name, namelen + 1); success: proxyName = internAtom(buf); if(proxyName == NULL) { do_log(L_ERROR, "Couldn't allocate proxy name.\n"); goto fail; } dispose_chunk(buf); return; fail: if(buf) dispose_chunk(buf); exit(1); return; }
int insertParentProxy(char *buf,int i) //humeng add 11.5.10 { ParentProxyPtr node,prtPrxs; AtomPtr temp,addr,key,atom, port,allowIP; AtomListPtr tempList; int x,y,rc; if(!buf[i]=='=') return(0); i++; skipBlank(buf,i); x=i; while(!(buf[i] == '\n' || buf[i] == '\0' || buf[i] == '#')) { skipBlank(buf,i); i++; } if(i>x+1) temp=internAtomN(buf+x,i-x-1); rc = atomSplit(temp, ':', &addr, &temp); if(rc <= 0) { do_log(L_ERROR, "Couldn't parse parentProxy."); return -1; } node=malloc(sizeof(ParentProxyRec)); node->addr=addr; rc = atomSplit(temp, ':', &port, &temp); if(rc <= 0) { do_log(L_ERROR, "Couldn't parse parentProxy."); return -1; } node->port=port; //node->friendName=intern; rc = atomSplit(temp, '-', &key, &allowIP); if(rc <= 0) { do_log(L_ERROR, "Couldn't parse parentProxy."); return -1; } node->key=key; node->keyHash=keyHasher(key->string, key->length); tempList=findProxyClient(allowIP->string); if(tempList){ node->allowIP=parseNetAddress(tempList); } if(ParentProxys==NULL) { ParentProxys=node; //updateParentProxy("59.66.24.76","123","166.111.132.138"); return 1; }else { prtPrxs=ParentProxys; while(prtPrxs) { if(strcmp(prtPrxs->addr->string,node->addr->string)==0) { prtPrxs->port=node->port; prtPrxs->key=node->key; prtPrxs->keyHash=node->keyHash; prtPrxs->allowIP=node->allowIP; return 1; } if(prtPrxs->next==NULL) { prtPrxs->next=node; return 1; } prtPrxs=prtPrxs->next; } } return 1; }
/* -------------------------------------------------------------------- */ void forwardaddr(void) { char name[NAMESIZE+NAMESIZE+2]; label forward; label rnode; label rregion; label rcountry; label temp; int logno; doCR(); getNormStr("forwarding name", name, NAMESIZE+NAMESIZE+1, ECHO); doCR(); if( !strlen(name) ) { logBuf.FORtOnODE = 0; mPrintf("Exclusive messages now routed to you"); doCR(); logBuf.forward[0] = '\0'; } else { parseNetAddress(name, forward, rnode, rregion, rcountry); if (!*rnode) /* if not forwarding to a node */ { logno = findPerson(name, lBuf2); if (logno == ERROR) { mPrintf("No '%s' known.", name); doCR(); return; } logBuf.FORtOnODE = 0; mPrintf("Exclusive messages now forwarded to %s", lBuf2->lbname); doCR(); strcpy(logBuf.forward, lBuf2->lbname); } else /* forwarding to node */ { alias(rnode); /* logno = findPerson(rnode, lBuf2); */ /* if (logno == ERROR) */ /* { */ strcpy(temp, rnode); route(temp); if (!getnode(temp)) { if (!*rregion) { mPrintf("Don't know how to reach '%s'", rnode); return; } } else { strcpy(logBuf.forward, forward); strcpy(logBuf.forward_node, rnode); logBuf.FORtOnODE = 1; mPrintf("Exclusive messages now forwarded to %s @ %s", logBuf.forward, logBuf.forward_node); doCR(); } /* } */ } } }