summary refs log tree commit diff stats
path: root/types.go
blob: 5032c5ac3f1d4a22fad82d932dc2f61bcca7e430 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main

import (
	"sync"
	"time"
)

// content-type consts
const txtutf8 = "text/plain; charset=utf-8"
const htmlutf8 = "text/html; charset=utf-8"
const cssutf8 = "text/css; charset=utf-8"

// Configuration object definition
type Configuration struct {
	Mu            sync.RWMutex
	Port          int           `json:"ListenPort"`
	LogFile       string        `json:"LogFile"`
	DBPath        string        `json:"DatabasePath"`
	StdoutLogging bool          `json:"StdoutLogging"`
	Version       string        `json:"-"`
	CacheInterval time.Duration `json:"StatusFetchInterval"`
	DBInterval    time.Duration `json:"DatabasePushInterval"`
	LastCache     time.Time     `json:"-"`
	LastPush      time.Time     `json:"-"`
	Instance      `json:"Instance"`
}

// Instance refers to this specific instance of getwtxt
type Instance struct {
	Name  string `json:"Instance.SiteName"`
	URL   string `json:"Instance.URL"`
	Owner string `json:"Instance.OwnerName"`
	Mail  string `json:"Instance.Email"`
	Desc  string `json:"Instance.Description"`
}

// RemoteRegistries holds a list of remote registries to
// periodically scrape for new users. The remote registries
// must have been added via POST like a user.
type RemoteRegistries struct {
	Mu   sync.RWMutex
	List []string
}

// ipCtxKey is the Context value key for user IP addresses
type ipCtxKey int

const ctxKey ipCtxKey = iota
tware Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see <http://www.gnu.org/licenses/>. * */ #include <time.h> #include <string.h> #include <ctype.h> #include <stdlib.h> void get_time(char *thetime) { time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); strftime(thetime, 80, "%H:%M", timeinfo); } char * str_replace (const char *string, const char *substr, const char *replacement) { char *tok = NULL; char *newstr = NULL; char *oldstr = NULL; char *head = NULL; if (string == NULL) return NULL; if ( substr == NULL || replacement == NULL || (strcmp(substr, "") == 0)) return strdup (string); newstr = strdup (string); head = newstr; while ( (tok = strstr ( head, substr ))) { oldstr = newstr; newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) + 1 ); if ( newstr == NULL ) { free (oldstr); return NULL; } memcpy ( newstr, oldstr, tok - oldstr ); memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) ); memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) ); memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) , 0, 1 ); head = newstr + (tok - oldstr) + strlen( replacement ); free (oldstr); } return newstr; }