summaryrefslogtreecommitdiff
path: root/HTMLCommonCode.c
blob: b86a7eb1902043ae20103e4728e9fe0ecc21efe2 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Copyright 2001-2018 John Wiseman G8BPQ

This file is part of LinBPQ/BPQ32.

LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

LinBPQ/BPQ32 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 LinBPQ/BPQ32.  If not, see http://www.gnu.org/licenses
*/	


// General C Routines common to bpq32 and linbpq.mainly moved from BPQ32.c

#pragma data_seg("_BPQDATA")

#define _CRT_SECURE_NO_DEPRECATE


#pragma data_seg("_BPQDATA")

#include "cheaders.h"

#include "templatedefs.c"				// Inline definitions from HTLMPages


char * GetTemplateFromFile(int Version, char * FN)
{
	int FileSize;
	char * MsgBytes;
	char MsgFile[265];
	FILE * hFile;
	size_t ReadLen;
	BOOL Special = FALSE;
	struct stat STAT;

	if (strcmp(FN, "WebMailMsg.txt") == 0)
		return WebMailMsgtxt();

	if (strcmp(FN, "FwdPage.txt") == 0)
		return FwdPagetxt();

	if (strcmp(FN, "FwdDetail.txt") == 0)
		return FwdDetailtxt();

	if (strcmp(FN, "webscript.js") == 0)
		return webscriptjs();

	if (strcmp(FN, "WebMailPage.txt") == 0)
		return WebMailPagetxt();

	if (strcmp(FN, "MainConfig.txt") == 0)
		return MainConfigtxt();

	if (strcmp(FN, "MsgPage.txt") == 0)
		return 	MsgPagetxt();

	if (strcmp(FN, "UserDetail.txt") == 0)
		return 	UserDetailtxt();

	if (strcmp(FN, "UserPage.txt") == 0)
		return UserPagetxt();

	if (strcmp(FN, "Housekeeping.txt") == 0)
		return Housekeepingtxt();

	if (strcmp(FN, "WP.txt") == 0)
		return WPtxt();

	if (strcmp(FN, "ChatConfig.txt") == 0)
		return ChatConfigtxt();

	if (strcmp(FN, "ChatStatus.txt") == 0)
		return ChatStatustxt();

	sprintf(MsgFile, "%s/HTML/%s", BPQDirectory, FN);

	if (stat(MsgFile, &STAT) == -1)
	{
		MsgBytes = _strdup("File is missing");
		return MsgBytes;
	}

	hFile = fopen(MsgFile, "rb");
	
	if (hFile == 0)
	{
		MsgBytes = _strdup("File is missing");
		return MsgBytes;
	}

	FileSize = STAT.st_size;
	MsgBytes = malloc(FileSize + 1);
	ReadLen = fread(MsgBytes, 1, FileSize, hFile); 
	MsgBytes[FileSize] = 0;
	fclose(hFile);

	// Check Version

	if (Version)
	{
		int PageVersion = 0;

		if (memcmp(MsgBytes, "<!-- Version", 12) == 0)
			PageVersion = atoi(&MsgBytes[13]);

		if (Version != PageVersion)
		{
			free(MsgBytes);
			MsgBytes = malloc(256);
			sprintf(MsgBytes, "Wrong Version of HTML Page %s - is %d should be %d. Please update", FN, PageVersion, Version);
		}
	}
	
	return MsgBytes;
}