summaryrefslogtreecommitdiff
path: root/cgitcgi/ctx.h
blob: 999acb0602dc8ab2879cc97465fcf27e1f964a21 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#ifndef    __CONTEXT_H
#define    __CONTEXT_H

#ifdef __cplusplus
extern "C" {
#endif


#define CONTEXT_MEM_SIZE  524288

struct __context
{
  void *_cur_brk;
  unsigned char _mem[CONTEXT_MEM_SIZE];
};

extern struct __context *pmctx;

#define __cur_brk  (*((void **)&(pmctx->_cur_brk)))
#define __mem      ((unsigned char *)&((pmctx->_mem)[0]))

extern void __mctx_init( void );
extern void *__sbrk( int incr );


struct cgit_tmplt_vars {
  const char *css;
  const char *owner;
  const char *author;
  const char *description;
  const char *keywords;
  const char *title;
  const char *favicon_path;
  const char *syntax_highlight_css;
  const char *logo;
  const char *logo_alt;
  const char *logo_link;
  const char *home_page;
  const char *snapshots;
  const char *status_line;
  const char *main_menu_logo;
  const char *main_menu_item;
  const char *left_menu_items;
  const char *popup_menu_items;
  const char *right_menu_items;
  const char *copyright_notice;
  const char *copyright;
  const char *page_type;
  const char *page_size;
  const char *num_of_repos;
};

#define CGIT_INFO_INIT  (struct cgit_info) { .kind = GIT_OBJECT_INVALID, .revision = { 0 }, .oid = { 0 }, .mode = GIT_FILEMODE_TREE, .author = NULL, .date = -1, .offset = 0, .mime = NULL, .lang = NULL }

struct cgit_info {
  git_object_t kind;
  char    revision[GIT_OID_HEXSZ+1];
  char         oid[GIT_OID_HEXSZ+1];
  git_filemode_t  mode;
  const char     *author;
  git_time_t      date;
  int             offset;
  const char     *mime;
  const char     *lang;
};

struct cgit_repository {
  const char       *name;
  struct cgit_info  info;
  const char       *git_root;
  const char       *repo_root;
  const char       *relative_path;
  struct cgit_info  relative_info;
  const char       *relative_html;
  const char       *relative_href;
  const char       *search_placeholder;
  const char       *trunk;    /* trunk    directory name */
  const char       *clone_prefix;
  const char       *clone_ro_prefix;
  int               nbranches; /* number of branches */
  int               ncommits;  /* number of commits (no more than 9999) */
  int               ntags;     /* number of tags     */
};

struct cgit_page {
  time_t modified;
  time_t expires;
  size_t size;
  const char *mimetype;
  const char *charset;
  int status;
  const char *status_message;
  const char *header;
  const char *footer;
};

struct cgit_environment {
  const char *http_host;
  const char *https;
  const char *no_http;
  const char *path_info;
  const char *query_string;
  const char *request_uri;
  const char *request_scheme;
  const char *request_method;
  const char *script_name;
  const char *server_name;
  const char *server_port;
  const char *http_cookie;
  unsigned int content_lenght;
  const char *http_root;
  int authenticated;
};

struct cgit_query {
  int ofs;
  const char *rev;
  const char *revision;
  const char *operation;
  const char *search;
};

struct cgit_versions {
  const char *git;
  const char *nginx;
  const char *cgit;
};

struct cgit_promotion {
  const char *analytic_links;
  const char *analytic_scripts;
  int donate;
  const char *donate_css;
  const char *donate_html;
  const char *donate_js;
  const char *donate_header;
  const char *donate_purpose;
};

struct cgit_context {
  struct cgit_environment  env;
  struct cgit_promotion    promo;
  struct cgit_query        query;
  struct cgit_page         page;
  struct cgit_tmplt_vars   vars;
  struct cgit_repository   repo;
  struct cgit_versions     vers;
};


extern const char *ptype_repolist;
extern const char *ptype_repo;

extern struct cgit_context ctx;

/*
  header/footer template variables:
  ================================
  ${css}
  ${owner}
  ${author}
  ${description}
  ${keywords}
  ${title}
  ${favicon-path}
  ${syntax-highlight-css}
  ${logo}
  ${logo-alt}
  ${logo-link}
  ${home-page}
  ${snapshots}
  ${status-line}
  ${main-menu-logo}
  ${main-menu-item}
  ${left-menu-items}
  ${popup-menu-items}
  ${right-menu-items}
  ${relative-html}
  ${search-placeholder}

  ${analytic-links}
  ${analytic-scripts}
  ${donate-css}
  ${donate-html}
  ${donate-js}
  ${donate-header}
  ${donate-purpose}

  ${git-version}
  ${nginx-version}
  ${cgit-version}
  ${copyright-notice}
  ${copyright}

  ${page-type}
  ${page-size}
  ${num-of-repos}
 */

extern void cgit_prepare_context( void );
extern void cgit_prepare_template_variables( void );
extern void cgit_release_template_variables( void );

extern void cgit_parse_query( void );

extern int ctx_grab_int_query_param( const char *name );
extern const char *ctx_grab_str_query_param( const char *name );
extern const char *ctx_remove_query_param( const char *query_string, const char *name );


#ifdef __cplusplus
}
#endif

#endif  /* __CONTEXT_H */