Rename openpli-streamproxy to external.
[vuplus_transtreamproxy] / src / Utils.h
1 /*
2  * Utils.h
3  *
4  *  Created on: 2014. 6. 10.
5  *      Author: oskwon
6  */
7
8 #ifndef UTILS_H_
9 #define UTILS_H_
10
11 #include <map>
12 #include <string>
13 #include <vector>
14
15 #include <stdint.h>
16
17 #include "Source.h"
18 #include "Encoder.h"
19 //----------------------------------------------------------------------
20
21 int strtollu(std::string data);
22 std::string ultostr(int64_t data);
23 std::string trim(std::string& s, const std::string& drop = " \t\n\v\r");
24 int split(std::string data, const char delimiter, std::vector<std::string>& tokens);
25 bool split_key_value(std::string data, std::string delimiter, std::string &key, std::string &value);
26
27 std::string read_request();
28 //----------------------------------------------------------------------
29
30 typedef enum {
31         REQ_TYPE_UNKNOWN = 0,
32         REQ_TYPE_LIVE,
33         REQ_TYPE_TRANSCODING_LIVE,
34         REQ_TYPE_FILE,
35         REQ_TYPE_TRANSCODING_FILE
36 } RequestType;
37 //----------------------------------------------------------------------
38
39 class RequestHeader
40 {
41 public:
42         RequestType type;
43         std::string method;
44         std::string path;
45         std::string version;
46         std::map<std::string, std::string> params;
47         std::map<std::string, std::string> extension;
48
49 public:
50         bool parse_header(std::string header);
51 };
52 //----------------------------------------------------------------------
53
54 #define HTTP_OK      "HTTP/1.1 200 OK\r\n"
55 #define HTTP_PARTIAL "HTTP/1.1 206 Partial Content\r\n"
56 #define HTTP_PARAMS      "Connection: Close\r\n" \
57                                          "Content-Type: video/mpeg\r\n" \
58                                          "Server: transtreamproxy\r\n"
59 #define HTTP_DONE    "\r\n"
60 //----------------------------------------------------------------------
61
62 typedef struct _thread_params_t {
63         Source *source;
64         Encoder *encoder;
65         RequestHeader *request;
66 } ThreadParams;
67 //----------------------------------------------------------------------
68
69 off_t make_response(ThreadParams *params, std::string& response);
70 //----------------------------------------------------------------------
71
72 class Util
73 {
74 public:
75         static void     vlog(const char * format, ...) throw();
76 };
77 //----------------------------------------------------------------------
78
79 void kill_process(int pid);
80 std::string get_host_addr();
81 std::vector<int> find_process_by_name(std::string name, int mypid);
82 //----------------------------------------------------------------------
83
84 #endif /* UTILS_H_ */