-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_list.c
More file actions
277 lines (236 loc) · 8.28 KB
/
post_list.c
File metadata and controls
277 lines (236 loc) · 8.28 KB
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <err.h>
#include <string.h>
#include <wchar.h>
#include <math.h>
#include <time.h>
#include <locale.h>
#include "main_proc.c"
#include "test_http.h"
#include "http_data.c"
#include "post_list.h"
#include "utils.c"
#include "tbl.c"
extern ptb *p_glob_t;
extern ssize_t write2(int _fd, const void *buf, size_t _n);
extern void make_header(char *dest, char *MIME, int m_size, int m_cash, int m_conn);
/*
void test_func(int pid,int client_fd)
{
char data_out[256] = "ФЙЙ; xx=";
//strcat(data_out,p_m->param_vals[0]);
int len_data_out=strlen(data_out);
sleep(10);
write(client_fd, response0, sizeof(response0) - 1);
write(client_fd, data_out, sizeof(*data_out)*len_data_out);
//write(client_fd, responseE, sizeof(responseE) - 1);
//free(err_out);
close(client_fd);
}
*/
int http_list(int pid,int client_fd,struct parse_ret *p_m)
{
int ret=0;
if(p_m->qc==0)
{
;
}
else
{
if(pid<0)
{
;
}
if(!strcmp(p_m->path_chain[0], "page_001"))
{
char dbuf[64]="; dd=";
char data_out[256] = "ФЙЙ; xx=";
strcat(data_out,p_m->param_vals[0]);
strcat(data_out,dbuf);
double dd=atof(p_m->param_vals[0]);
dd=dd/100.0;
//char dbuf[64];
//sprintf(dbuf,"; dd=%f", dd);
//str_0_trim(dbuf,dd,',');
strcat(data_out,dbuf);
//sleep(10);
int len_data_out=strlen(data_out);
write(client_fd, response0, sizeof(response0) - 1);
write(client_fd, data_out, sizeof(*data_out)*len_data_out);
//write(client_fd, responseE, sizeof(responseE) - 1);
ret=1;
}
if(!strcmp(p_m->path_chain[0], "view_tbl_001"))
{
int N=10;
int M=5;
char data_out[2048] = {'\0',};
char buf[1024]={'\0',};
int len_data_out=0;
//usleep(500000);
write2(client_fd, response0, sizeof(response0) - 1);
write2(client_fd, "\n\r", sizeof("\n\r") - 1);
if(!strcmp(p_m->bufr1[0], "GET"))
{
strcat(data_out,"<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title>");
strcat(data_out,p_m->path_chain[0]);
strcat(data_out,"</title></head><body>");
}
strcat(data_out,"<table border=1>");
for(int n=0; n<N; n++)
{
strcat(data_out,"<tr>");
strcat(data_out,"<td>");
sprintf(buf,"%d",n);
strcat(data_out,buf);
strcat(data_out,"</td>");
for(int m=0; m<M; m++)
{
strcat(data_out,"<td>");
sprintf(buf,"C_%d_%d",m,n);
strcat(data_out,buf);
strcat(data_out,"</td>");
//buf[1024]={'\000',};
memset(buf,'\0',sizeof(buf));
}
strcat(data_out,"</tr>");
len_data_out=strlen(data_out);
write2(client_fd, data_out, sizeof(*data_out)*len_data_out);
data_out[0]='\0';
}
data_out[0]='\0';
strcat(data_out,"</table>");
if(!strcmp(p_m->bufr1[0], "GET"))
{
strcat(data_out,"</body></html>");
}
len_data_out=strlen(data_out);
write2(client_fd, data_out, sizeof(*data_out)*len_data_out);
if(!strcmp(p_m->bufr1[0], "GET"))
{
write2(client_fd, responseE, sizeof(responseE) - 1);
}
ret=1;
}
if(!strcmp(p_m->path_chain[0], "view_tbl_002"))
{
ptb *pmt=p_glob_t;
/*
pmt = create_tbl();
read_csv_file(pmt,L"test_data_02W.csv",1,L',',L'"');
int res_conv = -1;
res_conv=conver_to_num(pmt,0,L'.');
res_conv=conver_to_num(pmt,1,L'.');
if(res_conv)
{
;
}
*/
//show(pmt,10,NULL,0);
int N_=pmt->zq;
int N=0;
int LIM=1000;
int M=pmt->cq;
if(N_>LIM)
{
N=LIM;
}
else
{
N=N_;
}
wchar_t data_out[2048] = L"";
char buf[1024]={'\0',};
wchar_t wbuf[1024]={'\0',};
wchar_t wbuf2[1024]={'\0',};
int len_data_out=0;
//usleep(500000);
write2(client_fd, response0, sizeof(response0) - 1);
write2(client_fd, "\n\r", sizeof("\n\r") - 1);
if(!strcmp(p_m->bufr1[0], "GET"))
{
wcscat(data_out,L"<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title>");
mbstowcs(wbuf, p_m->path_chain[0], 2048);
wcscat(data_out,wbuf);
wcscat(data_out,L"</title></head><body>");
}
wcscat(data_out,L"<table border=1>");
if(pmt!=NULL)
{
if(wcslen(((pmt->cc)+0)->cname )>0)
{
wcscat(data_out,L"<tr>");
wcscat(data_out,L"<td>");
//sprintf(buf,"%d",n);
//swprintf(wbuf2, 1024, L"%d", n);
//wcscat(data_out,wbuf2);
wcscat(data_out,L"</td>");
for(int m=0; m<M; m++)
{
wcscat(data_out,L"<td>");
//get_cell_sval(pmt,m,n,wbuf,L',',12);
//pmt->
//sprintf(buf,"C_%d_%d",m,n);
wcscat(data_out,((pmt->cc)+m)->cname);
wcscat(data_out,L"</td>");
memset(wbuf,'\0',sizeof(wbuf));
}
wcscat(data_out,L"</tr>");
wcstombs(buf, data_out, 2048);
len_data_out=strlen(buf);
write2(client_fd, buf, sizeof(*buf)*len_data_out);
data_out[0]=L'\0';
}
for(int n=0; n<N; n++)
{
wcscat(data_out,L"<tr>");
wcscat(data_out,L"<td>");
//sprintf(buf,"%d",n);
swprintf(wbuf2, 1024, L"%d", n);
wcscat(data_out,wbuf2);
wcscat(data_out,L"</td>");
for(int m=0; m<M; m++)
{
wcscat(data_out,L"<td>");
get_cell_sval(pmt,m,n,wbuf,L',',12);
//pmt->
//sprintf(buf,"C_%d_%d",m,n);
wcscat(data_out,wbuf);
wcscat(data_out,L"</td>");
memset(wbuf,'\0',sizeof(wbuf));
}
wcscat(data_out,L"</tr>");
wcstombs(buf, data_out, 2048);
len_data_out=strlen(buf);
write2(client_fd, buf, sizeof(*buf)*len_data_out);
data_out[0]=L'\0';
}
data_out[0]=L'\0';
wcscat(data_out,L"</table>");
if(!strcmp(p_m->bufr1[0], "GET"))
{
wcscat(data_out,L"</body></html>");
}
wcstombs(buf, data_out, 2048);
len_data_out=strlen(buf);
write2(client_fd, buf, sizeof(*buf)*len_data_out);
//drop_tbl(&pmt);
}
if(!strcmp(p_m->bufr1[0], "GET"))
{
write2(client_fd, responseE, sizeof(responseE) - 1);
}
ret=1;
}
}
//close(client_fd);
return ret;
}