-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg_process_admin.c
60 lines (48 loc) · 1 KB
/
tg_process_admin.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
#include "tg_process_admin.h"
#include "tg_context.h"
// The function is used to
// admin server
// pReq:
// tg://1040/ display all clients write clients data to fd descriptor
// tg://1041/pid shutdown client accroding to pid : no data write to descriptor of fd
void write_data(int fd,char * pReq)
{
if(pReq==NULL || *pReq=='\0')
{
return;
}
//TODO check fd is available
if(strncmp(pReq,"tg://1040/",10)==0)
{
char * pData=NULL;
getCurrentClientsInfo(&pData);
if(pData!=NULL)
{
write(fd,pData,strlen(pData));
write(fd,"\n\n",2);
}
else
{
write(fd,"none\n",4);
}
}
else if(strncmp(pReq,"tg://1041/",10)==0)
{
int id=atoi(&pReq[10]);
if(id>0)
{
TGClient *pCli;
if(findClient(id,&pCli)==0 &&pCli!=NULL)
{
// write message to client pipe
write(pCli->writePipe,"tg://1005",10);
return;
}
}
// write error message
char buf[100];
memset(buf,0,sizeof(buf));
sprintf(buf,"unkown pid:%d\n",id);
write(fd,buf,strlen(buf));
}
}