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
|
/*
* Utils.h
*
* Created on: 2014. 6. 10.
* Author: oskwon
*/
#ifndef UTILS_H_
#define UTILS_H_
#include <map>
#include <string>
#include <vector>
#include <stdint.h>
#include "Source.h"
#include "Encoder.h"
//----------------------------------------------------------------------
int strtollu(std::string data);
std::string ultostr(int64_t data);
std::string trim(std::string& s, const std::string& drop = " \t\n\v\r");
int split(std::string data, const char delimiter, std::vector<std::string>& tokens);
bool split_key_value(std::string data, std::string delimiter, std::string &key, std::string &value);
std::string read_request();
//----------------------------------------------------------------------
typedef enum {
REQ_TYPE_UNKNOWN = 0,
REQ_TYPE_LIVE,
REQ_TYPE_TRANSCODING_LIVE,
REQ_TYPE_FILE,
REQ_TYPE_TRANSCODING_FILE
} RequestType;
//----------------------------------------------------------------------
class RequestHeader
{
public:
RequestType type;
std::string method;
std::string path;
std::string version;
std::map<std::string, std::string> params;
std::map<std::string, std::string> extension;
public:
bool parse_header(std::string header);
};
//----------------------------------------------------------------------
#define HTTP_OK "HTTP/1.1 200 OK\r\n"
#define HTTP_PARTIAL "HTTP/1.1 206 Partial Content\r\n"
#define HTTP_PARAMS "Connection: Close\r\n" \
"Content-Type: video/mpeg\r\n" \
"Server: transtreamproxy\r\n"
#define HTTP_DONE "\r\n"
//----------------------------------------------------------------------
typedef struct _thread_params_t {
Source *source;
Encoder *encoder;
RequestHeader *request;
} ThreadParams;
//----------------------------------------------------------------------
off_t make_response(ThreadParams *params, std::string& response);
//----------------------------------------------------------------------
class Util
{
public:
static void vlog(const char * format, ...) throw();
};
//----------------------------------------------------------------------
void kill_process(int pid);
std::string get_host_addr();
std::vector<int> find_process_by_name(std::string name, int mypid);
//----------------------------------------------------------------------
#endif /* UTILS_H_ */
|