Esempio n. 1
0
static
PGPError pgpGetProxyServer(PGPContextRef context, PGPProxyServerType type,
                           char **proxyAddress, PGPUInt16 *proxyPort)
{
    PGPMemoryMgrRef	mgr = PGPGetContextMemoryMgr(context);
    PGPError			err = kPGPError_NoErr;
    ICError				icErr;
    ICInstance			icInstance;
    Str255				proxy;
    SInt32				bufSize;
    ICAttr				icAttr;
    Boolean				useProxy;
    static PGPUInt32	kDefaultPort = 80;
    char *				host = (char *) proxy;
    char *				port = NULL;

    if (type != kPGPProxyServerType_HTTP) {
        return kPGPError_BadParams;
    }
    if (ICStart != (void *) kUnresolvedCFragSymbolAddress) {
        icErr = ICStart(&icInstance, '????');
        if (icErr == noErr) {
            icErr = ICFindConfigFile(icInstance, 0, NULL);
            if (icErr == noErr) {
                bufSize = sizeof(Boolean);
                icErr = ICGetPref(icInstance, kICUseHTTPProxy, &icAttr, (Ptr) &useProxy, &bufSize);
                if ((icErr == noErr) && useProxy) {
                    bufSize = sizeof(Str255);
                    icErr = ICGetPref(icInstance, kICHTTPProxyHost, &icAttr, (Ptr) proxy, &bufSize);
                    if (icErr == noErr) {
                        p2cstr(proxy);
                        port = strchr(host, ':');
                        if (port == NULL) {
                            port = strchr(host, ' ');
                        }
                        if (port == NULL) {
                            *proxyPort = kDefaultPort;
                        } else {
                            *port++ = 0;
                            *proxyPort = atoi(port);
                        }
                        *proxyAddress = (char *) PGPNewData(mgr, strlen(host) + 1,
                                                            kPGPMemoryMgrFlags_None);
                        if (*proxyAddress == NULL) {
                            err = kPGPError_OutOfMemory;
                            *proxyPort = 0;
                        } else {
                            strcpy(*proxyAddress, host);
                        }
                    }
                }
            }
            ICStop(icInstance);
        }
    }

    return err;
}
Esempio n. 2
0
struct servent *getservent(void)
{
	static int	preferedProto = 0;
	OSStatus	err;
	long		len;
	ICAttr		attr;
	ICServices	*buf;
	ICServiceEntry tmpICSvc; /* We use this to store an aligned copy of *curSvc. */
	static ICServiceEntry *curICSvc = NULL;
	static struct servent svc = {NULL, NULL, 0, NULL};
  
	ncbi_ClearErrno(); 
  
	// Deallocate the last service name we returned.
	if (svc.s_name!=NULL)
	{
		free(svc.s_name);
		svc.s_name=NULL;
	}
  
	// If we haven't loaded the service table, load it now.
	if (gServices==NULL)
	{
		err=ICStart(&gConfig, 'Sock');
		if (err) {
			ncbi_SetOTErrno(err); 
			return NULL; 
		}
#if !TARGET_API_MAC_CARBON
	// Need to #ifdef this out for Carbon builds
		err=ICFindConfigFile(gConfig, 0, nil);
		if (err) { 
			ncbi_SetOTErrno(err);
			return NULL;
		}
	// End of #ifdef for Carbon
#endif

		len = 0;
		err = ICGetPref(gConfig, kICServices, &attr, NULL, &len);
		if (err) { 
			ncbi_SetOTErrno(err);
			return NULL;
		}
		buf=(ICServices*)NewPtr(len);
		if (buf==NULL || MemError()!=noErr) {
			ncbi_SetOTErrno(MemError());
			return NULL;
		}
		err=ICGetPref(gConfig, kICServices, &attr, (char*)buf, &len);
		if (err){
			ncbi_SetOTErrno(err);
			return NULL;
		}

		gServices=buf;
		curICSvc=&gServices->services[0];
		gServiceIndex=0;
	}
  
	/* If we are out of entries, return NULL. */
	if (curICSvc==NULL || gServiceIndex>=gServices->count)  return NULL;
  
	/* gServices is "packed", which means we cannot directly index gServices->services.
	 * So, we have to manually increment the current record pointer.  We also have to
	 * memmove any numbers into an aligned variable, because entries in gServices are
	 * not guaranteed to be on whatever boundary the current processor prefers. 
	 */

	/* Make an aligned copy of *curICSvc */
	memmove(tmpICSvc.name, curICSvc, ((char*)curICSvc)[0]+1);
	memmove(&tmpICSvc.port, (char*)curICSvc+((char*)curICSvc)[0]+1, 2);
	memmove(&tmpICSvc.flags, (char*)curICSvc+((char*)curICSvc)[0]+3, 2);

	/* Put together a servent based on the current service table entry. */
	len = tmpICSvc.name[0]+1;
	svc.s_name = malloc(len);
	if (svc.s_name == NULL) { 
		ncbi_SetOTErrno(memFullErr); 
		return NULL;
	}
	//memmove(svc.s_name, tmpICSvc.name, len);
	//p2cstr((StringPtr)svc.s_name);
	p2cstrcpy(svc.s_name, tmpICSvc.name);

	svc.s_aliases=(char**)&not_an_alias;

	svc.s_port=tmpICSvc.port;

	switch(preferedProto){
		case 0:
			switch(tmpICSvc.flags){
				case 0:
					svc.s_proto=(char*)prot_none;
					break;
				case kICServicesUDPMask:
					svc.s_proto=(char*)prot_udp;
					break;
				case kICServicesTCPMask:
					svc.s_proto=(char*)prot_tcp;
					break;
				case 3:
					svc.s_proto=(char*)prot_udp;
					preferedProto=kICServicesTCPMask;
					break;
			}
			break;
		case kICServicesUDPMask:
			svc.s_proto=(char*)prot_udp;      
			preferedProto=0;
			break;
		case kICServicesTCPMask:
			svc.s_proto=(char*)prot_tcp;
			preferedProto=0;
			break;
		default:
			// Assert_(0); /* We have set a preferedProto that we don't support. */
			break;
	}

	if (preferedProto==0){
		if ((++gServiceIndex)<gServices->count){
			/* Cast gCurrentService to char* so we can play pointer arithmetic games in
			 * byte-sized increments. The 5 is the length byte plus two 2-byte ints.
			 */
			curICSvc=(ICServiceEntry*)((char*)curICSvc+((char*)curICSvc)[0]+5);
		}
		else {
			curICSvc=NULL;
		}
	}
  
  return &svc;  
}