File: Service_Dotlearn.cc

package info (click to toggle)
postman 2.1-6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,248 kB
  • ctags: 3,249
  • sloc: cpp: 33,376; ansic: 2,014; sh: 768; makefile: 300
file content (157 lines) | stat: -rw-r--r-- 4,656 bytes parent folder | download | duplicates (2)
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
/*                               
Service_Dotlearn.cc
*/

#include "Service_Dotlearn.h"
#include "ClientHTTP.h"

extern Language *L;
extern Configuration *Conf;
extern Skin *skin;

bool Service_Dotlearn_Initialized = false;
TBuffer DotlearnURL2Get;

#define POSTMAN_HOST "correo.uv.es"
#define DOTLEARN_HOST "pizarra.uv.es"
#define DOTLEARN_URL_BEGIN  "/dotlrn/postman_redir?username={username}"
#define DOTLEARN_PORT 80
//In seconds
#define DOTLEARN_TIMEOUT 240

class HTMLPages: public HTMLBasic
  {
  private:
    //
  public:
    void PrintDotlearnDisplayPage (const char *lang, const char *user, const char *connid, UserOptions *uo, 
                                     StringList *SLHead, StringList *SLBody);
  };

//retrieve the url for the Service icon
const char *GetService_Dotlearn_ICO_URL (void)
  {
  return skin->getI(L_DOTLEARN);
  }

//Retrieve the ALT tag for the Service icon
const char *GetService_Dotlearn_ICO_ALT (void)
  {
  return L->get(L_DOTLEARN);
  }

//Retrieve the Service name
const char *GetService_Dotlearn_NAME (void)
  {
  return L->get(L_DOTLEARN);
  }

//Retrieve the Service Description
const char *GetService_Dotlearn_DESCRIPTION (void)
  {
  return L->get(L_DOTLEARN_DESCRIPTION);
  }

//Entry point to service init
bool DoService_Dotlearn_BEGIN (TProgData *pd)
  {
  TBuffer file2show;
  XString XS;
  if (CheckServiceDisabled (TranslateServiceR(pd->service), file2show) == true) 
    {pd->html->dumpFile (file2show, "TEXT/HTML"); return false;}
  if (Service_Dotlearn_Initialized == true) {return true;}
  LOG ("Initializating Service Dotlearn for user=%s", pd->username);
  Service_Dotlearn_Initialized = true;
  
  XS = XString (DOTLEARN_URL_BEGIN);
  XS.replace ("{username}", pd->username);
  XS.replace ("{password}", pd->password);  
  xstrncpy (DotlearnURL2Get, CMAXBUFFER, XS.cstr());  
    
  return true;
  }

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

//Entry point to execute a service command
bool DoService_Dotlearn_CMD (TProgData *pd)
  {
  ClientHTTP *CliHTTP;
  HTMLPages *html;
  int cmd, httpcode;
  StringList *SLHTTPHead, *SLHTTPBody;
  bool b;
  TBuffer header2send, url2back, abuff;

  html = (HTMLPages *)pd->html;
  cmd = pd->cmd;

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

  SLHTTPHead = new StringList;    
  SLHTTPBody = new StringList;
  
  sprintf (header2send, "GET %s HTTP/1.0\n", DotlearnURL2Get);
  xsnprintf (url2back, CMAXBUFFER, "http://%s%s/%s/root/noop/%s/%s/%s/%d/%d/%d/%ld/", 
                                   POSTMAN_HOST, PATH_CGI, SERVICE_MAIN, pd->stlang, pd->username, pd->connid,
                                   pd->uo->getValidator(), pd->uo->getPageId(), pd->uo->getLastCmd(), pd->uo->getCurrentPosition());
  xstrncat(header2send, CMAXBUFFER, "Cookie: Backurl="); xstrncat (header2send, CMAXBUFFER, url2back);
  xstrncat(header2send, CMAXBUFFER, "\n");
  xstrncat (header2send, CMAXBUFFER, "Connection: close\n");
  xstrncat (header2send, CMAXBUFFER, "\n");
  
  switch (pd->cmd)    
    {    
    case (CMD_DOTLEARN_GOTO):  
      {       
      CliHTTP = new ClientHTTP (DOTLEARN_HOST, DOTLEARN_PORT, DOTLEARN_TIMEOUT);
      b = CliHTTP->doGetHTTPSL (header2send, SLHTTPHead, SLHTTPBody, &httpcode);
      if (b == false)
        {
        LOG ("ERROR: Service_Dotlearn: Get: %s", CliHTTP->getErrorMsg());
        sprintf (abuff, "http://%s/register/?return_url=/dotlrn/index", DOTLEARN_HOST);
        pd->html->Redirect (abuff);
        break;
        }
      delete CliHTTP;
      html->PrintDotlearnDisplayPage  (pd->stlang, pd->username, pd->connid, pd->uo, SLHTTPHead, SLHTTPBody);
      break;
      }
    default: 
      {    
      LOG ("ERROR: Service_Dotlearn: Here we can not go! cmd=%d, stcmd=--%s--, stsubcmd=--%s--", pd->cmd, pd->stcmd, pd->stsubcmd);
      pd->html->PrintInvalidCommand (pd->stlang, pd->username, pd->connid, pd->uo);
      break;
      }                                   
    }  

  delete SLHTTPHead;  
  delete SLHTTPBody;
  return false;  
  }  

void HTMLPages::PrintDotlearnDisplayPage (const char *lang, const char *user, const char *connid, UserOptions *uo, 
                                            StringList *SLHead, StringList *SLBody)
  { 
  for (int i = 0; i < SLHead->Count(); ++i) 
    {
    WRITE ("%s\n", SLHead->getString (i).cstr());
    }  
  WRITE ("\n");
  for (int i = 0; i < SLBody->Count(); ++i)
    {
    WRITE ("%s\n", SLBody->getString (i).cstr());
    }
  }