22#include "../dpip/dpip.h"
29#define MSG(...) fprintf(stderr, "[vsource dpi]: " __VA_ARGS__)
34 "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
51 int bytes_read = 0, token_size;
56 while (bytes_read < data_size &&
58 bytes_read += token_size;
59 _MSG(
"data_size=%d bytes_read=%d\n", data_size, bytes_read);
71 int bytes_read = 0, line = 1, token_size = 0;
72 char *p, *q, *token, line_str[32];
77 while (bytes_read < data_size &&
79 bytes_read += token_size;
83 snprintf(line_str, 32,
"%2d: ", line);
85 if ((p = strpbrk(q,
"\r\n"))) {
87 if (*p ==
'\r' && p[1] ==
'\n')
107 int bytes_read = 0, old_line = 0, line = 1, token_size = 0;
108 char *p, *q, *token, line_str[128];
111 strncmp(url+4,
"/vsource/:", 10) == 0)
121 "<title>Source for %s</title>\n"
122 "<style type=\"text/css\">\n"
124 " white-space: pre-wrap;\n"
125 " font-family: monospace;\n"
129 " table { border:0 }\n"
131 " padding-top: 1px;\n"
132 " padding-bottom: 1px;\n"
133 " padding-left: 0.5em;\n"
134 " padding-right: 0.5em;\n"
135 " text-align: right;\n"
136 " border-right: 1px solid #999999;\n"
137 " background-color: #c6c6c6;\n"
139 " td.src { padding-left:0.25em; }\n"
140 " a { color: black; text-decoration:none; }\n"
143 "<body id=\"dillo_vs\">\n<table cellspacing='0' cellpadding='0'>\n", url);
145 while (bytes_read < data_size &&
147 bytes_read += token_size;
151 if (line > old_line) {
152 snprintf(line_str, 128,
153 "<tr><td class='num' id='L%d'><a href='#L%d'>%d</a><td class='src'>",
158 if ((p = strpbrk(q,
"\r\n<&"))) {
159 if (*p ==
'\r' || *p ==
'\n') {
161 if (*p ==
'\r' && p[1] ==
'\n')
188 char *dpip_tag, *cmd = NULL, *cmd2 = NULL, *url = NULL, *size_str = NULL;
191 _MSG(
"starting...\n");
207 MSG(
"can't authenticate request: %s\n",
dStrerror(errno));
218 _MSG(
"tag = [%s]\n", dpip_tag);
234 if (strcmp(cmd2,
"start_send_page") == 0 &&
236 data_size = strtol(size_str, NULL, 10);
241 }
else if (strcmp(cmd2,
"DpiError") == 0) {
245 "ERROR: Page not cached.\n");
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
char * a_Dpip_dsh_read_token2(Dsh *dsh, int blocking, int *DataSize)
Return a newlly allocated string with the next dpip token in the socket.
void a_Dpip_dsh_free(Dsh *dsh)
Free the SockHandler structure.
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str)
Convenience function.
char * a_Dpip_get_attr(const char *tag, const char *attrname)
Task: given a tag and an attribute name, return its value.
char * a_Dpip_dsh_read_token(Dsh *dsh, int blocking)
Return a newlly allocated string with the next dpip token in the socket.
void a_Dpip_dsh_close(Dsh *dsh)
Close this socket for reading and writing.
int a_Dpip_check_auth(const char *auth_tag)
Check whether the given 'auth' string equals what dpid saved.
int a_Dpip_dsh_write(Dsh *dsh, int flush, const char *Data, int DataSize)
Streamed write to socket.
Dsh * a_Dpip_dsh_new(int fd_in, int fd_out, int flush_sz)
Create and initialize a dpip socket handler.
#define a_Dpip_dsh_printf(sh, flush,...)
Dpip socket handler type.
void send_numbered_text(Dsh *sh, int data_size)
void send_dpip_tag(Dsh *sh, char *dpip_tag)
void send_plain_text(Dsh *sh, int data_size)
void send_html_text(Dsh *sh, const char *url, int data_size)