2
Copyright 2013-2014 Canonical Ltd.
4
This program is free software: you can redistribute it and/or modify it
5
under the terms of the GNU General Public License version 3, as published
6
by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranties of
10
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program. If not, see <http://www.gnu.org/licenses/>.
17
// Package identifier wraps libwhoopsie, and is thus the
18
// source of an anonymous and stable system id used by the Ubuntu
19
// error tracker and the Ubuntu push notifications service.
23
#cgo pkg-config: libwhoopsie
25
#include <libwhoopsie/identifier.h>
32
// an Id knows how to generate itself, and how to stringify itself.
38
// Identifier is the default Id implementation.
39
type Identifier struct {
41
generator func(**C.char, **C.GError)
44
func generator(csp **C.char, errp **C.GError) {
45
C.whoopsie_identifier_generate(csp, errp)
48
// New creates an Identifier, but does not call Generate() on it.
50
return &Identifier{generator: generator}
53
// Generate makes the Identifier create the identifier itself.
54
func (id *Identifier) Generate() error {
57
defer C.g_free((C.gpointer)(unsafe.Pointer(cs)))
59
for i := 0; i < 200; i++ {
60
id.generator(&cs, &gerr)
62
if gerr == nil && cs != nil {
65
C.g_clear_error(&gerr)
66
time.Sleep(600 * time.Millisecond)
68
return errors.New("whoopsie_identifier_generate still bad after 2m; giving up")
71
id.value = C.GoString(cs)
75
// String returns the system identifier as a string.
76
func (id *Identifier) String() string {