Ticket #303: windows_uuid.patch

File windows_uuid.patch, 7.4 KB (added by Richard Boulton, 16 years ago)

Improved patch, based on patch26.

  • xapian-core/common/safeuuid.h

     
     1/** @file safeuuid.h
     2 *  @brief #include <uuid/uuid.h>, with alternative implementation for windows.
     3 */
     4/* Copyright (C) 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#ifndef XAPIAN_INCLUDED_SAFEUUID_H
     22#define XAPIAN_INCLUDED_SAFEUUID_H
     23
     24#ifdef __WIN32__
     25# include "common/win32_uuid.h"
     26#else
     27# include <uuid/uuid.h>
     28#endif
     29
     30#endif // XAPIAN_INCLUDED_SAFEUUID_H
  • xapian-core/common/win32_uuid.h

    Property changes on: xapian-core/common/safeuuid.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
     1/* @file win32_uuid.h
     2 * @brief Provide UUID functions compatible with libuuid from e2fsprogs.
     3 */
     4/* Copyright 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU General Public License as
     8 * published by the Free Software Foundation; either version 2 of the
     9 * License, or (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#ifndef XAPIAN_INCLUDED_WIN32_UUID_H
     22#define XAPIAN_INCLUDED_WIN32_UUID_H
     23
     24#if !defined __CYGWIN__ && !defined __WIN32__
     25# error Including win32_uuid.h, but neither __CYGWIN__ nor __WIN32__ defined!
     26#endif
     27
     28#include "safewindows.h"
     29#include <rpc.h>
     30
     31// Unfortunately Windows defines uuid_t as GUID, so we redefine it to match the
     32// Unix definition.
     33#undef uuid_t
     34typedef unsigned char uuid_t[16];
     35
     36void uuid_generate(uuid_t uu);
     37
     38int uuid_parse(const char * in, uuid_t uu);
     39
     40void uuid_unparse_lower(const uuid_t uu, char * out);
     41
     42void uuid_clear(uuid_t uu);
     43
     44int uuid_is_null(const uuid_t uu);
     45
     46#endif /* XAPIAN_INCLUDED_WIN32_UUID_H */
  • xapian-core/common/win32_uuid.cc

    Property changes on: xapian-core/common/win32_uuid.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
     1/* @file win32_uuid.cc
     2 * @brief Provide UUID functions compatible with libuuid from e2fsprogs.
     3 */
     4/* Copyright (C) 2008 Lemur Consulting Ltd
     5 *
     6 * This program is free software; you can redistribute it and/or modify
     7 * it under the terms of the GNU General Public License as published by
     8 * the Free Software Foundation; either version 2 of the License, or
     9 * (at your option) any later version.
     10 *
     11 * This program is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 * GNU General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU General Public License
     17 * along with this program; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
     19 */
     20
     21#include <config.h>
     22
     23#include "win32_uuid.h"
     24
     25#include <xapian/error.h>
     26
     27void
     28uuid_generate(uuid_t uu)
     29{
     30    UUID uuid;
     31    if (UuidCreate(&uuid) != RPC_S_OK) {
     32        // Throw a DatabaseCreateError, since we can't make a UUID.  The
     33        // windows API documentation is a bit unclear about the situations in
     34        // which this can happen, but if this behaviour causes a problem, an
     35        // alternative would be to create a UUID ourselves somehow in this
     36        // situation.
     37        throw Xapian::DatabaseCreateError("Cannot create UUID");
     38    }
     39    memcpy(uu, &uuid, 16);
     40}
     41
     42int
     43uuid_parse(const char * in, uuid_t uu)
     44{
     45    UUID uuid;
     46    if (UuidFromString((unsigned char*)in, &uuid) != RPC_S_OK)
     47        return -1;
     48    memcpy(uu, &uuid, 16);
     49    return 0;
     50}
     51
     52void uuid_unparse_lower(const uuid_t uu, char *  out)
     53{
     54    UUID uuid;
     55    char *uuidstr;
     56    memcpy(&uuid, uu, 16);
     57    if (UuidToString(&uuid, (unsigned char **)(&uuidstr)) != RPC_S_OK)
     58        return;
     59    int uuidlen = strlen(uuidstr);
     60    strncpy( out, strlwr(uuidstr), uuidlen );
     61    RpcStringFree((unsigned char**)(&uuidstr));
     62}
     63
     64void uuid_clear(uuid_t uu)
     65{
     66    memset(uu, 0x00, 16);
     67}
     68
     69int uuid_is_null(const uuid_t uu)
     70{
     71    int i = 0;
     72    while (i < 16) {
     73        if (uu[i++])
     74            return 0;
     75    }
     76    return 1;
     77}
  • xapian-core/backends/chert/chert_version.h

    Property changes on: xapian-core/common/win32_uuid.cc
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
    2424#include <cstring>
    2525#include <string>
    2626
    27 #include <uuid/uuid.h>
     27#include "common/safeuuid.h"
    2828
    2929/** The ChertVersion class manages the "iamchert" file.
    3030 *
  • xapian-core/backends/chert/chert_version.cc

     
    3838#include <cstring> // For memcmp() and memcpy().
    3939#include <string>
    4040
    41 #include <uuid/uuid.h>
     41#include "common/safeuuid.h"
    4242
    4343using namespace std;
    4444
  • xapian-core/backends/flint/flint_version.cc

     
    3737#include <cstring> // For memcmp() and memcpy().
    3838#include <string>
    3939
    40 #include <uuid/uuid.h>
     40#include "common/safeuuid.h"
    4141
    4242using std::string;
    4343
  • xapian-core/backends/flint/flint_version.h

     
    2424#include <cstring>
    2525#include <string>
    2626
    27 #include <uuid/uuid.h>
     27#include "common/safeuuid.h"
    2828
    2929/** The FlintVersion class manages the "iamflint" file.
    3030 *