/
comment.c
253 lines (188 loc) · 6.04 KB
/
comment.c
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/********************************************************
Konferanssystem version 2.1
Programmet används för att kommentera ett annat inlägg
Program: comment.c
Version: 2.1.1.7
Date: 99/05/21
*********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define SELECT 0
#define INSERT 1
#define UPDATE 2
#define DELETE 3
#define EDIT 4
#define LIST 5
#define TRUE 1
#define FALSE 0
/* funktioner för hantering av cgi-anrop och felhantering */
#include "../cgi.h"
#include "../utils.h"
#include "intra.h"
#include "db.h"
#include "html.h"
/* gemensamma funktioner för konferanssystemet */
/* följande funktioner anropas */
/* huvudprogram comment */
main ( int argc, char *argv[])
{
char path[255] ;
int method ;
char *instring ;
struct _CGI CGI ;
struct _CGIarg CGIarg ;
struct _user user ; /* information om användaren */
struct _message message ;
struct _title title ;
struct _category category ;
message.indent = 0 ;
message.category = 0 ;
message.subject = 0 ;
message.id = 0 ;
message.owner = -1 ;
message.title[0] = (char) NULL ;
message.author[0] = (char) NULL ;
message.email[0] = (char) NULL ;
message.text[0] = (char) NULL ;
message.created[0] = (char) NULL ;
message.company[0] = (char) NULL ;
message.comment = 0 ;
message.reply[0] = (char) NULL ;
strcpy ( path, argv[0] ) ;
InitIntra ( path ) ;
InitCGI () ;
GetCGI ( &instring, &CGI ) ;
bURLencode ( instring, &CGIarg ) ;
ExpandMethod ( &CGIarg, &method ) ;
ExpandComment ( &CGIarg, &message ) ;
findUser ( CGI.remote_user, &user ) ;
/* släpp reserverat minne för formulärvärden */
/* visa ett inlägg */
if ( method == EDIT )
{
catHTML ( HEADER ) ; /* skriv ut ett sidhuvud i HTML */
/* skriv ut meny för konferanssystem */
if ( !FRAMES )
exit(0) ;
if ( message.id != 0 ) /* kommentar till tidigare inlägg */
{
selectMessage ( message.category, message.subject, message.id, &message ) ;
message.comment = message.id ;
message.indent ++ ;
sprintf( title.name, "Re:%s", message.title ) ;
strcpy ( message.title, title.name ) ;
}
if ( user.id > 0 ) /* om inte inloggad användare nollställ namn */
{
strcpy ( message.author, user.name ) ;
strcpy ( message.email, user.epost ) ;
message.owner = user.id ;
}
else
{
message.author[0] = (char) NULL ;
message.email[0] = (char) NULL ;
message.owner = -1 ;
}
if ( strcmp ( EDITION, "Limited"))
{
if ( message.category > 0 )
printCommentForm ( message ) ; /* skriv ut ett formulär för ett nytt meddelande */
else
{ category.id = message.category ;
printCommentCategoryForm ( category ) ; /* välj vilken katagori som avses */
}
}
else
printCommentForm ( message ) ;
catHTML ( FOOTER ) ; /* skriv ut en sidfot i HTML */
}
return ( TRUE ) ;
} /* end of main () */
int ExpandComment ( struct _CGIarg *CGIarg, struct _message *message )
/*
Funktionen översätter argument från CGI-script till en post i en länkad lista
Om inga fel inträffar returneras TRUE
Om värde överskrider min eller maxvärde så returnerar funktionen FALSE
Om någon annan typ av fel inträffar så returneras ERROR
CGIarg innhåller en länkad lista med variabelnamn och värden
*message innehåller en pekare till en post med värden.
Om värden saknas sätts NULL
Följande argument från formulär används av funktionen
id=
group=
subject=
title=
public=
reply=
comment=
author=
email=
to=
company=
text=
*/
{
int size ; /* antal tecken som varialbel innehåller */
struct _CGIarg *first ;
first = malloc ( sizeof ( *CGIarg )) ;
first = CGIarg ;
while ( CGIarg != NULL )
{
size = strlen ( CGIarg->value ) ;
if ( !strncmp("category", CGIarg->name, 8 )) {
message->category = atoi ( CGIarg->value ) ;
}
if ( !strncmp("id", CGIarg->name, 2 )) {
message->id = atoi ( CGIarg->value ) ;
}
if ( !strncmp("group", CGIarg->name, 5 )) {
message->group = atoi ( CGIarg->value ) ;
}
if ( !strncmp("subject", CGIarg->name, 7 )) {
message->subject = atoi ( CGIarg->value ) ;
}
if ( !strncmp("target", CGIarg->name, 6 )) {
message->target = atoi ( CGIarg->value ) ;
}
if ( !strncmp("public", CGIarg->name, 6 )) {
message->security = atoi ( CGIarg->value ) ;
}
if ( !strncmp("comment", CGIarg->name, 7 )) {
message->comment = atoi ( CGIarg->value ) ;
}
if ( !strncmp("indent", CGIarg->name, 6 )) {
message->indent = atoi ( CGIarg->value ) ;
}
if ( !strncmp("title", CGIarg->name, 5 )) {
strncpy( message->title, CGIarg->value, 64 ) ;
message->title[size] = (char) NULL ;
}
if ( !strncmp("author", CGIarg->name, 6 )) {
strncpy( message->author, CGIarg->value,64 ) ;
message->author[size] = (char) NULL ;
}
if ( !strncmp("email", CGIarg->name, 4 )) {
strncpy( message->email, CGIarg->value,128 ) ;
message->email[size] = (char) NULL ;
}
if ( !strncmp("to", CGIarg->name, 2 )) {
strncpy( message->to, CGIarg->value,128 ) ;
message->to[size] = (char) NULL ;
}
if ( !strncmp("company", CGIarg->name, 7 )) {
strncpy( message->company, CGIarg->value, 64 ) ;
message->company[size] = (char) NULL ;
}
if ( !strncmp("text", CGIarg->name, 4 )) {
strncpy( message->text, CGIarg->value,strlen(CGIarg->value) ) ;
message->text[size] = (char) NULL ;
}
CGIarg = CGIarg->next ;
}
CGIarg = first ;
/*free ( first ) ;*/
return ( TRUE ) ;
} /* end of ExpandComment */