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
		//! Open a URL in the default application, usually a browser
	void OpenURL(const std::string urlString)
	{
		// Thanks to Willard Myers, on the qt-interest mailing list.
		ICInstance icInstance;
		if (ICStart ( &icInstance, '????') == noErr)  
		{
			ConstStr255Param hint (0x0);
			long l = urlString.length();
			long s = 0;
			ICLaunchURL (icInstance, hint, urlString.c_str(), l, &s, &l);
			ICStop (icInstance);
		}
	}
Esempio n. 3
0
static iciobject *
newiciobject(OSType creator)
{
	iciobject *self;
	OSStatus err;
	
	self = PyObject_NEW(iciobject, &Icitype);
	if (self == NULL)
		return NULL;
	if ((err=ICStart(&self->inst, creator)) != 0 ) {
		(void)PyMac_Error(err);
		PyObject_DEL(self);
		return NULL;
	}
	return self;
}
Esempio n. 4
0
Boolean UrlPane::Click(Point where, short modifiers)
{
	ICInstance icInst;
	OSStatus err = ICStart(&icInst, mCreator);
	if (err) return 0;
	
	#if !TARGET_API_MAC_CARBON
		err = ICFindConfigFile(icInst, 0, 0);
	#endif
	
	long selStart=0, selEnd=0;
	if (mURL[0]) err = ICLaunchURL(icInst, "\p", (char*)(&mURL[1]), mURL[0], &selStart, &selEnd);
	else err = ICLaunchURL(icInst, "\p", (char*)(&mText[1]), mText[0], &selStart, &selEnd);

	err = ICStop(icInst);
	return 1;
}
Esempio n. 5
0
Word BURGER_API Burger::Globals::LaunchURL(const char *pURL)
{
	ICInstance inst;

	OSStatus err = -1;
	if (ICStart!=NULL) {
		err = ICStart(&inst,'????');		// Use your creator code if you have one!
		if (err == noErr) {
#if !TARGET_API_MAC_CARBON
			err = ICFindConfigFile(inst, 0, nil);
			if (err == noErr)
#endif
			{
				long startSel = 0;
				long endSel = StringLength(pURL);
				err = ICLaunchURL(inst, "\p",const_cast<char *>(pURL),endSel,&startSel,&endSel);
			}
Esempio n. 6
0
File: main.cpp Progetto: boredzo/CCX
void LaunchURL( const char* url )
{
#ifdef __linux__
	printf("URL: %s\n", url);
#else
#if TARGET_API_MAC_CARBON
	OSStatus err = -1;
	ICInstance inst;
	long startSel;
	long endSel;
	
	if( ICStart != NULL )
	{
		err = ICStart( &inst, 'Skit' );
		if (err == noErr)
		{
			startSel = 0;
			endSel = strlen(url);
			err = ICLaunchURL( inst, "\p", url, strlen(url), &startSel, &endSel );
			ICStop(inst);
		}
Esempio n. 7
0
Word BURGERCALL LaunchURL(const char *URLPtr)
{
	OSStatus err;
	ICInstance inst;
	long startSel;
	long endSel;
	
	err = -1;
	if (ICStart) {
		err = ICStart(&inst,'????');           // Use your creator code if you have one!
		if (err == noErr) {
#if !TARGET_API_MAC_CARBON
			err = ICFindConfigFile(inst, 0, nil);
			if (err == noErr)
#endif
			{
				startSel = 0;
				endSel = strlen(URLPtr);
				err = ICLaunchURL(inst, "\p", (char *)URLPtr,endSel, &startSel, &endSel);
			}
			ICStop(inst);
		}
Esempio n. 8
0
//  CJL Hack ... pass the length of the string
static OSStatus MacLaunchURL(ConstStr255Param urlStr, SInt32 len)
{
    OSStatus err;
    ICInstance inst;
    SInt32 startSel;
    SInt32 endSel;

    err = ICStart(&inst, 'Cn3D');
    if (err == noErr) {
#if !TARGET_CARBON
        err = ICFindConfigFile(inst, 0, nil);
#endif
        if (err == noErr) {
            startSel = 0;
//            endSel = strlen(urlStr);   //  OSX didn't like this:  invalid conversion from
//                                          'const unsigned char*' to 'const char*' compiler error.
// ConstStr255Param is an unsigned char*.  Mac developer docs do not seem to indicate the '255'
// means there are any length restrictions on such strings, and that implementations have some
// backing store for longer strings.   But to be safe, I'm truncating this to 255.
// As used in Cn3D none of the URLs are terribly long ... except when multiple annotations are selected.
// (Also see CoreFoundation header CFBase.h; used in ncbi_os_mac.hpp Pstrncpy)
            endSel = (len > 0 && len <= 255) ? len : 255;
            err = ICLaunchURL(inst, "\p", urlStr, endSel, &startSel, &endSel);
        }
Esempio n. 9
0
static bool wxLaunchDefaultBrowserBaseImpl(const wxString& url, int flags)
{
    wxUnusedVar(flags);

#if defined(__WXMSW__)

#if wxUSE_IPC
    if ( flags & wxBROWSER_NEW_WINDOW )
    {
        // ShellExecuteEx() opens the URL in an existing window by default so
        // we can't use it if we need a new window
        wxURI uri(url);
        wxRegKey key(wxRegKey::HKCR, uri.GetScheme() + _T("\\shell\\open"));
        if ( !key.Exists() )
        {
            // try default browser, it must be registered at least for http URLs
            key.SetName(wxRegKey::HKCR, _T("http\\shell\\open"));
        }

        if ( key.Exists() )
        {
            wxRegKey keyDDE(key, wxT("DDEExec"));
            if ( keyDDE.Exists() )
            {
                // we only know the syntax of WWW_OpenURL DDE request for IE,
                // optimistically assume that all other browsers are compatible
                // with it
                static const wxString TOPIC_OPEN_URL = wxT("WWW_OpenURL");
                wxString ddeCmd;
                wxRegKey keyTopic(keyDDE, wxT("topic"));
                bool ok = keyTopic.Exists() && (keyTopic.QueryDefaultValue() = TOPIC_OPEN_URL);
                if ( ok )
                {
                    ddeCmd = keyDDE.QueryDefaultValue();
                    ok = !ddeCmd.empty();
                }

                if ( ok )
                {
                    // for WWW_OpenURL, the index of the window to open the URL
                    // in is -1 (meaning "current") by default, replace it with
                    // 0 which means "new" (see KB article 160957)
                    ok = ddeCmd.Replace(wxT("-1"), wxT("0"),
                                        false /* only first occurence */) == 1;
                }

                if ( ok )
                {
                    // and also replace the parameters: the topic should
                    // contain a placeholder for the URL
                    ok = ddeCmd.Replace(wxT("%1"), url, false) == 1;
                }

                if ( ok )
                {
                    // try to send it the DDE request now but ignore the errors
                    wxLogNull noLog;

                    const wxString ddeServer = wxRegKey(keyDDE, wxT("application")).QueryDefaultValue();
                    if ( wxExecuteDDE(ddeServer, TOPIC_OPEN_URL, ddeCmd) )
                        return true;

                    // this is not necessarily an error: maybe browser is
                    // simply not running, but no matter, in any case we're
                    // going to launch it using ShellExecuteEx() below now and
                    // we shouldn't try to open a new window if we open a new
                    // browser anyhow
                }
            }
        }
    }
#endif // wxUSE_IPC

    WinStruct<SHELLEXECUTEINFO> sei;
    sei.lpFile = url.c_str();
    sei.lpVerb = _T("open");
    sei.nShow = SW_SHOWNORMAL;
    sei.fMask = SEE_MASK_FLAG_NO_UI; // we give error message ourselves

    BOOL nExecResult = ::ShellExecuteEx(&sei);

    //From MSDN for wince
    //hInstApp member is only valid if the function fails, in which case it
    //receives one of the following error values, which are less than or
    //equal to 32.
    const int nResult = (int) sei.hInstApp;

    // Firefox returns file not found for some reason, so make an exception
    // for it
    if ( nResult > 32 || nResult == SE_ERR_FNF  || nExecResult == TRUE )
    {
#ifdef __WXDEBUG__
        // Log something if SE_ERR_FNF happens
        if ( nResult == SE_ERR_FNF || nExecResult == FALSE )
            wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
#endif // __WXDEBUG__
        return true;
    }
#elif defined(__WXMAC__)
    OSStatus err;
    ICInstance inst;
    long int startSel;
    long int endSel;

    err = ICStart(&inst, 'STKA'); // put your app creator code here
    if (err == noErr)
    {
#if !TARGET_CARBON
        err = ICFindConfigFile(inst, 0, NULL);
#endif
        if (err == noErr)
        {
            ConstStr255Param hint = 0;
            startSel = 0;
            endSel = url.length();
            err = ICLaunchURL(inst, hint, url.fn_str(), endSel, &startSel, &endSel);
            if (err != noErr)
                wxLogDebug(wxT("ICLaunchURL error %d"), (int) err);
        }
        ICStop(inst);
        return true;
    }
    else
    {
        wxLogDebug(wxT("ICStart error %d"), (int) err);
        return false;
    }
#else
    // (non-Mac, non-MSW)

#ifdef __UNIX__

    // Our best best is to use xdg-open from freedesktop.org cross-desktop
    // compatibility suite xdg-utils
    // (see http://portland.freedesktop.org/wiki/) -- this is installed on
    // most modern distributions and may be tweaked by them to handle
    // distribution specifics. Only if that fails, try to find the right
    // browser ourselves.
    wxString path, xdg_open;
    if ( wxGetEnv(_T("PATH"), &path) &&
         wxFindFileInPath(&xdg_open, path, _T("xdg-open")) )
    {
        if ( wxExecute(xdg_open + _T(" ") + url) )
            return true;
    }

    wxString desktop = wxTheApp->GetTraits()->GetDesktopEnvironment();

    // GNOME and KDE desktops have some applications which should be always installed
    // together with their main parts, which give us the
    if (desktop == wxT("GNOME"))
    {
        wxArrayString errors;
        wxArrayString output;

        // gconf will tell us the path of the application to use as browser
        long res = wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
                              output, errors, wxEXEC_NODISABLE );
        if (res >= 0 && errors.GetCount() == 0)
        {
            wxString cmd = output[0];
            cmd << _T(' ') << url;
            if (wxExecute(cmd))
                return true;
        }
    }
    else if (desktop == wxT("KDE"))
    {
        // kfmclient directly opens the given URL
        if (wxExecute(wxT("kfmclient openURL ") + url))
            return true;
    }
#endif

    bool ok = false;
    wxString cmd;

#if wxUSE_MIMETYPE
    wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("html"));
    if ( ft )
    {
        wxString mt;
        ft->GetMimeType(&mt);

        ok = ft->GetOpenCommand(&cmd, wxFileType::MessageParameters(url));
        delete ft;
    }
#endif // wxUSE_MIMETYPE

    if ( !ok || cmd.empty() )
    {
        // fallback to checking for the BROWSER environment variable
        cmd = wxGetenv(wxT("BROWSER"));
        if ( !cmd.empty() )
            cmd << _T(' ') << url;
    }

    ok = ( !cmd.empty() && wxExecute(cmd) );
    if (ok)
        return ok;

    // no file type for HTML extension
    wxLogError(_T("No default application configured for HTML files."));

#endif // !wxUSE_MIMETYPE && !__WXMSW__
    return false;
}
Esempio n. 10
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;  
}