src/guid.c

00001 /*
00002  * Copyright (C) 2005 Jukka Zitting <jz@yukatan.fi>
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License as published
00006  * by the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 #include <config.h>
00019 #include "midgard/guid.h"
00020 #include "midgard/uuid.h"
00021 
00022 gboolean midgard_is_guid(const gchar *guid) {
00023         g_assert(guid != NULL);
00024         int i;
00025         for (i = 0; guid[i] != 0 && i < 80; i++) {
00026                 if (guid[i] != '-' && !g_ascii_isxdigit(guid[i])) {
00027                         return FALSE;
00028                 }
00029         }
00030         return (i >= 21);
00031 }
00032 
00033 static void uuid2guid(gchar *uuid) {
00034         gchar *guid = uuid;
00035         do {
00036                 if (*uuid == '-') {
00037                         uuid++;
00038                 }
00039                 *guid++ = *uuid++;
00040         } while (*uuid);
00041 }
00042 
00043 gchar *midgard_guid_new(midgard *mgd) {
00044         g_assert(mgd != NULL);
00045         gchar *uuid = midgard_uuid_new();
00046         uuid2guid(uuid);
00047         return uuid;
00048 }
00049 
00050 gchar *midgard_guid_external(midgard *mgd, const gchar *external) {
00051         g_assert(mgd != NULL);
00052         g_assert(external != NULL);
00053         gchar *uuid = midgard_uuid_external(external);
00054         uuid2guid(uuid);
00055         return uuid;
00056 }
00057 
00058 gchar *mgd_create_guid(midgard *mgd, const gchar *table, guint id) {
00059         g_assert(mgd != NULL);
00060         g_assert(table != NULL);
00061         return midgard_guid_new(mgd);
00062 }

Generated on Thu Feb 22 06:15:14 2007 for midgard-core by  doxygen 1.4.6