Skip to content
Snippets Groups Projects
Select Git revision
  • e099ac514a38a9a2d365c01671d9c8654036162c
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

compiler.ts

Blame
  • Requests.inc 1.49 KiB
    <?php
    
    // vim: expandtab sw=4 ts=4 sts=4 :
    
    namespace WebMMB;
    
    define('MTYPE_JSON', 'application/json');
    define('MTYPE_OCTET', 'application/octet-stream');
    define('EP_ADDITIONAL_FILE', 'additional_file');
    define('EP_API', 'api');
    define('EP_AUTH', 'auth');
    define('EP_STRUCTURE', 'structure');
    define('EP_XFR', 'xfr');
    
    require_once('Exceptions.inc');
    require_once('internal/Api.inc');
    require_once('internal/HttpUtil.inc');
    
    function api_request($ch, string $url, Api\ApiRequest $req, Cookie $auth_cookie)
    {
        $resp = post_request($ch, $url, EP_API, MTYPE_JSON, $req->toJSON(), [ $auth_cookie ]);
        if (!$resp) {
            throw new ServerError('Invalid server response');
        }
    
        return $resp;
    }
    
    function auth_request($ch, string $url, Api\AuthRequest $req)
    {
        $resp = post_request($ch, $url, EP_AUTH, MTYPE_JSON, $req->toJSON());
        if (!$resp) {
            throw new ServerError('Invalid server response');
        }
    
        if ($resp->hasCookie('webmmb_auth')) {
            return $resp->getCookie('webmmb_auth');
        }
        return false;
    }
    
    function fetch_request($ch, $url, $auth_cookie)
    {
        $resp = get_request_raw($ch, $url, [ $auth_cookie ]);
        if (!$resp) {
            throw new ServerError('Invalid server response');
        }
    
        return $resp;
    }
    
    function xfr_request($ch, $url, Api\FileTransferChunk $req, $auth_cookie)
    {
        $resp = post_request($ch, $url, EP_XFR, MTYPE_OCTET, $req->toBytes(), [ $auth_cookie ]);
        if (!$resp) {
            throw new ServerError('Invalid server response');
        }
    
        return $resp;
    }