~ubuntu-branches/ubuntu/wily/steam/wily-proposed

« back to all changes in this revision

Viewing changes to server/libraries/Async.pmod

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class Return {
2
 
    function resultFunc = 0;
3
 
    function processFunc = 0;
4
 
    mixed userData = 0;
5
 
 
6
 
    int tid, oid, oclass, cmd;
7
 
    int id;
8
 
    mapping vars;
9
 
    string mimetype = "text/plain";
10
 
    
11
 
    void set_request(object request) {
12
 
    }
13
 
 
14
 
    void asyncResult(mixed _id, mixed result) {
15
 
        if ( functionp(processFunc) ) {
16
 
            if ( userData ) 
17
 
                result = processFunc(result, userData);
18
 
            else
19
 
                result = processFunc(result);
20
 
        }
21
 
        resultFunc(this_object(), result);
22
 
    }
23
 
    int is_async_return() { return 1; }
24
 
}
25
 
 
26
 
class HtmlHandler {
27
 
    inherit Return;
28
 
 
29
 
    string header = "HTTP/1.1 200 OK\r\nServer: sTeam HTTP\r\nContent-Type: text/html; charset=utf-8\r\nConnection: keep-alive\r\nDate: "+
30
 
    httplib.http_date(time())+"\r\n\r\n";
31
 
    string head, foot;
32
 
    object _fd;
33
 
    function htmlResultFunc;
34
 
    
35
 
    Return asReturn;
36
 
 
37
 
    void create(function f, void|object asReturnObj, void|mapping vars) { 
38
 
      htmlResultFunc = f; 
39
 
      if ( objectp(asReturnObj) ) {
40
 
          set_return_object(asReturnObj);
41
 
          if ( mappingp(vars) )
42
 
              asReturnObj->vars = vars;
43
 
      }
44
 
    }
45
 
    void set_return_object(object asReturnObj) {
46
 
        if ( !objectp(asReturnObj) )
47
 
            return;
48
 
        asReturn = asReturnObj;
49
 
        asReturn->resultFunc = asyncResult;
50
 
    }
51
 
    
52
 
    string set_html(string headHTML, string footHTML) {
53
 
        head = headHTML;
54
 
        foot = footHTML;
55
 
    }
56
 
 
57
 
    void output(string str) {
58
 
      if (objectp(_fd))
59
 
        _fd->write(str);
60
 
    }
61
 
 
62
 
    void set_request(object request) {
63
 
        _fd = request->my_fd;
64
 
        if ( stringp(header) ) {
65
 
            _fd->write(header);
66
 
            if ( stringp(head) )
67
 
                _fd->write(head);
68
 
            header = 0;
69
 
        }
70
 
    }
71
 
    void asyncResult(mixed id, mixed result) {
72
 
 
73
 
        if ( functionp(htmlResultFunc) )
74
 
            result = htmlResultFunc(id, result);
75
 
        _fd->write(result);
76
 
        if ( id == asReturn ) {
77
 
          if  (stringp(foot) && strlen(foot) > 0 )
78
 
            _fd->write(foot);
79
 
          _fd->close();
80
 
        }
81
 
    }
82
 
}