Generating GUIDs
From MDC
GUIDs are used in Mozilla programming for identifying several types of entities, including XPCOM Interfaces (this type of GUIDs is callled IID), components (CID), and add-ons, like extensions and themes, although add-ons can (and should) be identified with IDs of form extensionname@organization.tld since Firefox 1.5.
Contents |
[edit] Canonical form
The common form of a GUID is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx, where each x stands for a hexadecimal digit. There are a number of tools that can be used to generate a GUID in the canonical form.
[edit] Online tools
- Generate GUID Online
- UUID (GUID) Generator on the WEB
- UUID Generator for Mozilla Code (both IDL and C++.h forms)
- You can get a GUID from one of the bots (such as botbot, firebot) on #firefox IRC channel by /msging "uuid" to them.
[edit] Windows
Windows users can use the GuidGen tool from Microsoft to obtain a GUID. (This tool is also part of MS Visual C++)
[edit] Linux
Use /usr/bin/uuidgen. This can be found in package libuuid1 (Debian).
[edit] Perl
jkeiser's Mozilla tools include a UUID generator with output format of both C++ and IDL style.
[edit] nsIUUIDGenerator
A UUID can be generated from privileged Mozilla code using nsIUUIDGenerator. See the linked page for details.
[edit] COM/XPCOM format
When #define-ing IIDs and CIDs in Mozilla C++ code, you generally use the following format:
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
#define NS_...ID \
{ 0xXXXXXXXX, 0xXXXX, 0xXXXX, \
{ 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX } }
You can generate code in this format using one of the following tools.
[edit] Online tools
[edit] guidgen
guidgen.exe, part of Microsoft Visual Studio, can generate UUIDs in this format.
[edit] bash
You can put the following into your .bashrc file:
uuidgen-c++()
{
local UUID=$(uuidgen)
echo "// $UUID"
echo "#define NS__IID \\"
echo "{ 0x${UUID:0:8}, 0x${UUID:9:4}, 0x${UUID:14:4}, \\"
echo -n " { 0x${UUID:19:2}, 0x${UUID:21:2}, 0x${UUID:24:2}, "
echo -n "0x${UUID:26:2}, 0x${UUID:28:2}, 0x${UUID:30:2}, "
echo "0x${UUID:32:2}, 0x${UUID:34:2} } }"
}
[edit] Perl
#!/usr/bin/perl
$uuid = `uuidgen`;
chomp $uuid;
print $uuid, "\n";
@parts = ($uuid =~ /^(.{8})-(.{4})-(.{4})-(..)(..)-(..)(..)(..)(..)(..)(..)$/);
print "{ 0x$parts[0], 0x$parts[1], 0x$parts[2], \\", "\n", " { ";
for (3 .. 9) {
print "0x$parts[$_], ";
}
print "0x$parts[10] } }", "\n";