File: Service_PersonalData.cc

package info (click to toggle)
postman 2.0-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,036 kB
  • ctags: 3,078
  • sloc: cpp: 31,131; ansic: 1,948; sh: 787; makefile: 285
file content (182 lines) | stat: -rw-r--r-- 4,699 bytes parent folder | download
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
/*                               
Service_PersonalData.cc
*/

#include "Service_PersonalData.h"

#include "ClientHTTP.h"

extern Language *L;
extern Configuration *Conf;

bool Service_PersonalData_Initialized = false;

#define PERSONALDATA_HOST    "bancuv.uv.es"
#define PERSONALDATA_PORT    80
#define PERSONALDATA_TIMEOUT 3
#define PASSWORD "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
#define URL2GetFoto "/fotoini/"
#define URL2GetName "/cgi-bin/get_nombre/"

TPersonalInfo PersonalInfo;

class HTMLPages: public HTMLBasic
  {
  private:
    //
  public:
    void PrintPersonalDataDisplayPage (const char *stlang, const char *user, const char *connid, UserOptions *uo, StringList *SLRes);
  };

//retrieve the url for the Service icon
const char *GetService_PersonalData_ICO_URL (void)
  {
  return "";
  }

//Retrieve the ALT tag for the Service icon
const char *GetService_PersonalData_ICO_ALT (void)
  {
  return "";
  }

//Retrieve the Service name
const char *GetService_PersonalData_NAME (void)
  {
  return "";
  }

//Retrieve the Service Description
const char *GetService_PersonalData_DESCRIPTION (void)
  {
  return "";
  }

//Entry point to service init
bool DoService_PersonalData_BEGIN (TProgData *pd)
  {
  TBuffer file2show, toencript, bufencriptado, header2send;
  int ir, maxbufencriptado = CMAXBUFFER, httpcode;
  StringList SLHTTPHead, SLHTTPBody;
  ClientHTTP *CliHTTP;
  bool b;

  if (Service_PersonalData_Initialized == true) {return true;}
  
  initStr (PersonalInfo.Name);
  initStr (PersonalInfo.PAN);  
  initStr (PersonalInfo.NPI);  
  initStr (PersonalInfo.RefFoto);  
  initStr (PersonalInfo.URLFoto);  

  if (CheckServiceDisabled (TranslateServiceR(pd->service), file2show) == true) 
    {pd->html->dumpFile (file2show, "TEXT/HTML"); return false;}        
  LOG ("Initializating Service PersonalData for user=%s", pd->username);

  ir = Rand (strlen(PASSWORD));
  xsnprintf (toencript, CMAXBUFFER, "%.3d:%s:%s:%s:", ir, pd->username, pd->username, "postman");
  encryptcasero (PASSWORD, toencript, strlen(toencript), bufencriptado, &maxbufencriptado);

  /*PHOTO IMG SRC*/
  xsnprintf (PersonalInfo.URLFoto, CMAXBUFFER, "%s%s", URL2GetFoto, bufencriptado);

  /*USER FIRST ANS SECOND NAME*/
  CliHTTP = new ClientHTTP (PERSONALDATA_HOST, PERSONALDATA_PORT, PERSONALDATA_TIMEOUT);
  sprintf (header2send, "GET %s%s HTTP/1.0\n\n", URL2GetName, bufencriptado);
  b = CliHTTP->doGetHTTPSL (header2send, &SLHTTPHead, &SLHTTPBody, &httpcode);
  if (b == true)
    {      
    if (SLHTTPBody.Count() > 0) 
      {
      xstrncpy (PersonalInfo.Name, CMAXBUFFER, SLHTTPBody.getString(0).cstr());
      Rtrim (PersonalInfo.Name);
      }
    }
  else
    {
    Service_PersonalData_Initialized = false;
    }    
  delete CliHTTP;

  Service_PersonalData_Initialized = true;
  return true;
  }

//Entry point to service end
bool DoService_PersonalData_END (TProgData *pd)
  {
  Service_PersonalData_Initialized = false;
  return true;
  }

//Entry point to execute a service command
bool DoService_PersonalData_CMD (TProgData *pd)
  {
  HTMLPages *html;
  int cmd;

  html = (HTMLPages *)pd->html;

  TBuffer file2show;
  if (CheckServiceDisabled (TranslateServiceR(pd->service), file2show) == true) 
    {pd->html->dumpFile (file2show, "TEXT/HTML"); return false;}        

  cmd = pd->cmd;
    
  switch (pd->cmd)
    {
    default: 
      {    
      LOG ("ERROR: Service_PersonalData: Here we can not go!! cmd=%s, subcmd=%s", pd->stcmd, pd->stsubcmd);
      pd->html->PrintInvalidCommand (pd->stlang, pd->username, pd->connid, pd->uo);
      break;
      }         
    }
  return false;  
  }  

bool getPersonalInfo (const char *token_name, TBuffer tokeninfo)
  {
  TBuffer uptoken;
  initStr (tokeninfo);
  if (IsEmpty(token_name)) {return false;}
  xstrncpy (uptoken, CMAXBUFFER, token_name); xucase (uptoken);
  
  if (strcmp (uptoken, "NAME")== 0)         {xstrncpy (tokeninfo, CMAXBUFFER, PersonalInfo.Name);}
  else if (strcmp (uptoken, "PAN")== 0)     {xstrncpy (tokeninfo, CMAXBUFFER, PersonalInfo.PAN);}
  else if (strcmp (uptoken, "NPI")== 0)     {xstrncpy (tokeninfo, CMAXBUFFER, PersonalInfo.NPI);}
  else if (strcmp (uptoken, "REFFOTO")== 0) {xstrncpy (tokeninfo, CMAXBUFFER, PersonalInfo.RefFoto);}
  else if (strcmp (uptoken, "URLFOTO")== 0) {xstrncpy (tokeninfo, CMAXBUFFER, PersonalInfo.URLFoto);}
  else {return false;}
  
  if (IsEmpty(tokeninfo)) return false; 
  else return true;  
  }

void HTMLPages::PrintPersonalDataDisplayPage (const char *stlang, const char *user, const char *connid, UserOptions *uo, StringList *SLRes)
  {
  
  }