Exemplo n.º 1
0
void test_frame_small_no_mask(size_t *size, uint8_t **frame){
    int retval = mongrel2_ws_frame_create(0,111,size,frame);
    assert(retval == 0);

    mongrel2_ws_frame_set_fin(*size,*frame);
    mongrel2_ws_frame_set_opcode(*size,*frame,OP_TEXT);
}
Exemplo n.º 2
0
void test_frame_medium_no_mask(size_t *size, uint8_t **frame){
    int retval = mongrel2_ws_frame_create(0,2000,size,frame);
    assert(retval == 0);

    mongrel2_ws_frame_set_fin(*size,*frame);
    mongrel2_ws_frame_set_opcode(*size,*frame,OP_BIN);
}
Exemplo n.º 3
0
void test_frame_medium_with_mask(size_t *size, uint8_t **frame){
    int retval = mongrel2_ws_frame_create(1,2244,size,frame);
    assert(retval == 0);

    mongrel2_ws_frame_set_fin(*size,*frame);
    mongrel2_ws_frame_set_opcode(*size,*frame,OP_BIN);
    mongrel2_ws_frame_set_mask(*size,*frame,0xFFFFFFFF);
}
Exemplo n.º 4
0
/* Expected format
 * BYTE[0]     FIN  = 1 | 0x00 | 0x00 | 0x00
 * BYTE[1]     MASKP = 1 | SIZE = 0x04
 * BYTE[2]     MASK        0xFF
 * BYTE[3]     MASK        0xEE
 * BYTE[4]     MASK        0xAA
 * BYTE[5]     MASK        0xDD
 * BYTE[6]     PAYLOAD     'A'
 * BYTE[7]     PAYLOAD     'S'
 * BYTE[8]     PAYLOAD     'D'
 * BYTE[9]     PAYLOAD     'F'
 */
void test_frame_small_with_mask(size_t *size, uint8_t **frame){
    int retval = mongrel2_ws_frame_create(1,4,size,frame);
    assert(retval == 0);

    mongrel2_ws_frame_set_fin(*size,*frame);
    mongrel2_ws_frame_set_opcode(*size,*frame,OP_TEXT);
    uint8_t data[4];
    data[0] = 0xFF;
    data[1] = 0xEE;
    data[2] = 0xAA;
    data[3] = 0xDD;

    mongrel2_ws_frame_set_payload(*size,*frame,4,data);
    mongrel2_ws_frame_set_mask(*size,*frame,0xFFEEAADD);
}
Exemplo n.º 5
0
int mongrel2_ws_reply(mongrel2_socket *pub_socket, mongrel2_request *req, bstring data){
    size_t req_len = blength(data);
    uint8_t *req_data = (uint8_t*)bdata(data);

    size_t payload_len = 0;
    uint8_t *payload_data = NULL;
    // Simplest code but seems to be unsafe with chrome 14?
    int retval = mongrel2_ws_frame_create(0,req_len,&payload_len,&payload_data);

    if(retval != 0){
        fprintf(stderr,"mongrel2_ws_reply failed with errno %d\n",retval);
        return -1;
    }
    mongrel2_ws_frame_set_payload(payload_len,payload_data,req_len,req_data);
    mongrel2_ws_frame_set_opcode(payload_len,payload_data,OP_TEXT);
    mongrel2_ws_frame_set_fin(payload_len,payload_data);

    // Instead, let's chunk it to a bunch of small messages
    // int fullchunks = req_len % WEBSOCKET_SMALL_MAX;
    // int leftoverbytes = req_len / WEBSOCKET_SMALL_MAX;

    // bstring chunk;
    // for(int i=0; i<fullchunks; i++){
    //     uint8_t chunk_payload[WEBSOCKET_SMALL_MAX];
    //     chunk = bmidstr(data,i*WEBSOCKET_SMALL_MAX,i*WEBSOCKET_SMALL_MAX+WEBSOCKET_SMALL_MAX-1);
        

    //     fullchunks--;
    // }


    #ifndef NDEBUG
    mongrel2_ws_frame_debug(payload_len,payload_data);
    #endif

    bstring outgoing = blk2bstr(payload_data,payload_len);
    assert(blength(outgoing) == payload_len);

    mongrel2_reply(pub_socket,req,outgoing);
    free(payload_data);

    bdestroy(outgoing);
    return 0;
}