tags:

views:

3401

answers:

8

Ok, please bear with me as this is sorta difficult to explain.

I have seen...

  • http://www...
  • ftp://blah.blah...
  • file://blah.blah...
  • unreal://blah.blah...
  • mailto://blah.blah...

What is that first section where you see http and the like called?

Can I register my own?

+1  A: 

A Protocol?

I found this, it appears to be a local setting for a computer...

http://kb.mozillazine.org/Register_protocol

Hugoware
A: 

You don't really have to do any registering as such. I've seen many programs, like emule, create their own protocol specificier (that's what I think it's called). After that, you basically just have to set some values in the registry as to what program handles that protocol. I'm not sure if there's any official registry of protocol specifiers. There isn't really much to stop you from creating your own protocol specifier for your own application if you want people to open your app from their browser.

Kibbee
+1  A: 

It's called the protocol. The only thing that prevents you from making your own protocol is you have to:

  1. Write a browser or user agent of some kinds that understands that protocol, both in its URL form and in the actual data format
  2. Write a server that understands that protocol
  3. Preferably, have a specification for the protocol so that browser and server can continue to work together.

Windows makes #1 really easy, an in many cases this is all you actually need. Viz:

Registering an Application to a URL Protocol

JSBangs
+1  A: 

The first section is called a protocol and yes you can register your own. On Windows (where I'm assuming you're doing this given the C# tag - sorry Mono fans), it's done via the registry.

GaryF
+19  A: 

You do this through the registry.

HKEY_CLASSES_ROOT/
  your-protocol-name/
    (Default)    "URL:your-protocol-name Protocol"
    URL Protocol ""
    shell/
      open/
        command/
          (Default) PathToExecutable
James Gregory
What about non-Windows OSes?
Bdoserror
"What about non-Windows OSes?"It's application-specific. I think it's actually frequently application-specific on Windows too (this won't make everything magically work).
Calum
Define everything. The registry entry tells Windows to pass the Uri with that protocol to the application specified, everything else should be handled by the application itself.
James Gregory
Pluggable protocol handler is definitely a better choice.
+8  A: 

Here's a list of the registered URI schemes. Each one has an RFC - a document defining it, which is almost a standard. The RFC tells the developers of new applications (such as browsers, ftp clients, etc.) what they need to support. If you need a new base-level protocol, you can use an unregistered one. The other answers tell you how. Please keep in mind you can do lots of things with the existing protocols, thus gaining their existing implementations.

Yuval F
Notwithstanding the technical details of how to make a protocol work in Windows - this is the most important answer. You shouldn't create a new URI scheme unless it's registered with IETF, or using an experimental namespace (like an X- prefix)
Alnitak
+12  A: 

This is different for each browser, in IE and windows you need to create what they call a pluggable protocol handler.

The basic steps are as follows:

  1. Implement the IInternetProtocol interface.
  2. Implement the IInternetProtocolRoot interface.
  3. Implement the IClassFactory interface.
  4. Optional. Implement the IInternetProtocolInfo interface. Support for the HTTP protocol is provided by the transaction handler.
  5. If IInternetProtocolInfo is implemented, provide support for PARSE_SECURITY_URL and PARSE_SECURITY_DOMAIN so the URL security zone manager can handle the security properly. Write the code for your protocol handler.
  6. Provide support for BINDF_NO_UI and BINDF_SILENTOPERATION.
  7. Add a subkey for your protocol handler in the registry under HKEY_CLASSES_ROOT\PROTOCOLS\Handler.
  8. Create a string value, CLSID, under the subkey and set the string to the CLSID of your protocol handler.

See http://msdn.microsoft.com/en-us/library/aa767916(VS.85).aspx for more details on the windows side. There is also a sample in the windows SDK.

A quick google also showed this article on codeproject: http://www.codeproject.com/KB/IP/DataProtocol.aspx.

Finally, as a security guy I have to point out that this code needs to be battled hardened. It's at a high risk because to do it reliably you can't do it in managed code and have to do it in C++ (I suppose you could use VB6). You should consider whether you really need to do this and if you do, design it carefully and code it securely. An attacker can easily control the content that gets passed to you by simply including a link on a page. For example if you have a simple buffer overflow then nobody better do this: <a href="custom:foooo{insert long string for buffer overflow here}"> Click me for free porn</a>

Strongly consider using strsafe and the new secure CRT methods included in the VC8 and above compilers. See http://blogs.msdn.com/michael_howard/archive/2006/02/27/540123.aspx if you have no idea what I'm talking about.

Peter Oehlert
That's just an example of something to entice users to click on it.
Peter Oehlert
+1  A: 

For most Microsoft products (Internet Explorer, Office, "open file" dialogs etc) you can register an application to be run when URI with appropriate prefix is opened. This is a part of more common explanation - how to implement your own protocol.

For Mozilla the explanation is here, Java - here.

Dmitry Khalatov