static inline bool inspect_headers(Request* request) { Py_ssize_t i; PyObject* tuple; for(i=0; i<PyList_GET_SIZE(request->headers); ++i) { PyObject* field; PyObject* value; tuple = PyList_GET_ITEM(request->headers, i); if(!PyTuple_Check(tuple) || PyTuple_GET_SIZE(tuple) != 2) goto err; field = PyTuple_GET_ITEM(tuple, 0); value = PyTuple_GET_ITEM(tuple, 1); if(!PyString_Check(field) || !PyString_Check(value)) goto err; if(!SCMP(PyString_AS_STRING(field), "Content-Length", PyString_GET_SIZE(field))) request->state.response_length_unknown = false; } return true; err: TYPE_ERROR_INNER("start_response argument 2", "a list of 2-tuples", "(found invalid '%.200s' object at position %zd)", Py_TYPE(tuple)->tp_name, i); return false; }
char *xml_get_attr(xmlNode * a_node, char *attr) { xmlAttr *cur_attr = NULL; for (cur_attr = a_node->properties; cur_attr; cur_attr = cur_attr->next) { if ((cur_attr->type == XML_ATTRIBUTE_NODE) && !SCMP(cur_attr->name, attr)) { //printf("Attribute %s, value %s\n", cur_attr->name, cur_attr->children->content); return cur_attr->children->content; } } return 0; }
void xml_walk_tree(xmlNode * a_node, char *url, OMS_PAGE *p) { xmlNode *cur_node = NULL; xmlNode *ch_node = NULL; xmlAttr *cur_attr = NULL; char *i; int j; for (cur_node = a_node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { //printf("Tag: %s\n", cur_node->name); char *l, *link, *name; switch(xml_get_tag_id(cur_node->name)) { case HTML_TAG_HTML: case HTML_TAG_HEAD: break; case HTML_TAG_TITLE: name = "Page title"; ch_node = xml_find_text_node(cur_node); if (ch_node) { // Dirty hack ch_node->extra = XML_TEXT_MAGIC; oms_add_plus(p); oms_add_text(p, ch_node->content); } break; case HTML_TAG_BODY: l = xml_get_attr(cur_node, "bgcolor"); if (l) oms_add_bgcolor(p, l); l = xml_get_attr(cur_node, "text"); if (l) oms_add_textcolor(p, l); break; case HTML_TAG_BR: oms_add_break(p); break; case HTML_TAG_P: oms_add_paragraph(p); break; case HTML_TAG_A: //printf("z"); l = xml_get_attr(cur_node, "href"); if (l != 0) { link = malloc(strlen(l) + 10 + strlen(url)); if(!strstr(l, "://")) // Нет протокола -> ссылка неполная (не всегда так, но пох) { if (l[0] == '/') // Путь от корня сайта i = strchr(url+7, '/'); else // Относительно текущей директории { i = strrchr(url, '/'); if (i == (url+6)) // А нету в конце слеша i = NULL; } if (i != NULL) *i = 0; sprintf(link, "0/%s/%s", url, l); if (i != NULL) *i = '/'; } else sprintf(link, "0/%s", l); } else { link = strcpy(malloc(12), "error:link"); } name = "Link"; //printf("e"); ch_node = xml_find_text_node(cur_node); if (ch_node) { // Dirty hack ch_node->extra = XML_TEXT_MAGIC; name = ch_node->content; } oms_add_link(p, link, name); free(link); //printf("q"); break; case HTML_TAG_IMG: oms_add_text(p, "[Img]"); break; case HTML_TAG_FORM: link = xml_get_attr(cur_node, "action"); oms_add_form(p, link); break; case HTML_TAG_TEXTAREA: // HACK for google.com and similar name = xml_get_attr(cur_node, "style"); if (!name || !strstr(name, "display:none")) { name = xml_get_attr(cur_node, "name"); if (!name) name = "dname"; link = xml_get_attr(cur_node, "value"); if (!link) link = ""; oms_add_text_input(p, name, link); } break; case HTML_TAG_INPUT: l = xml_get_attr(cur_node, "type"); if (!l) l = "text"; name = xml_get_attr(cur_node, "name"); if (!name) name = "dname"; link = xml_get_attr(cur_node, "value"); if (!link) link = ""; if (!SCMP(l, "text")) oms_add_text_input(p, name, link); else if (!SCMP(l, "password")) oms_add_pass_input(p, name, link); else if (!SCMP(l, "submit")) oms_add_submit(p, name, link); else if (!SCMP(l, "checkbox")) { link = xml_get_attr(cur_node, "checked"); j = 0; if (link && (!SCMP(link, "true"))) j = 1; oms_add_checkbox(p, name, 1); } break; default: break; } /* for (cur_attr = cur_node->properties; cur_attr; cur_attr = cur_attr->next) { if (cur_attr->type == XML_ATTRIBUTE_NODE) { printf("Attribute %s, value %s\n", cur_attr->name, cur_attr->children->content); } }*/ } else if ((cur_node->type == XML_TEXT_NODE) && (cur_node->extra != XML_TEXT_MAGIC)) { //printf("Text node %s\n", cur_node->content); oms_add_text(p, cur_node->content); } xml_walk_tree(cur_node->children, url, p); // printf("Boo!\n"); } }
static int xml_get_tag_id(char *tag) { if (!SCMP(tag, "html")) return HTML_TAG_HTML; else if (!SCMP(tag, "head")) return HTML_TAG_HEAD; else if (!SCMP(tag, "title")) return HTML_TAG_TITLE; else if (!SCMP(tag, "body")) return HTML_TAG_BODY; else if (!SCMP(tag, "a")) return HTML_TAG_A; else if (!SCMP(tag, "br")) return HTML_TAG_BR; else if (!SCMP(tag, "p")) return HTML_TAG_P; else if (!SCMP(tag, "img")) return HTML_TAG_IMG; else if (!SCMP(tag, "input")) return HTML_TAG_INPUT; else if (!SCMP(tag, "form")) return HTML_TAG_FORM; else if (!SCMP(tag, "textarea")) return HTML_TAG_TEXTAREA; return HTML_TAG_UNK; }
int main(int argc, char *argv[]) { register int i; int xpos = XPOS; int ypos = YPOS; int font = -1; int shape = 1; char *getenv(); char *home = getenv("HOME"); int clean(), update(); /* make sure we have a valid environment to run in */ ckmgrterm( *argv ); if (home==NULL || *home=='\0') { fprintf(stderr,"%s: Can't find your home directory\n",argv[0]); exit(1); } if ((bounds = fopen(BOUNDS,"r")) == NULL) { fprintf(stderr,"%s: Can't find a bounds file\n",argv[0]); exit(2); } sprintf(line,"%s/%s",home,RC); if ((rc = fopen(line,"r")) == NULL) { fprintf(stderr,"%s: Can't find %s\n",argv[0],line); exit(3); } /* process arguments */ for(i=1;i<argc;i++) { if (Isflag(argv[i],"-s")) shape = 0; else if (Isflag(argv[i],"-x")) xpos = atoi(argv[i]+2); else if (Isflag(argv[i],"-y")) ypos = atoi(argv[i]+2); else if (Isflag(argv[i],"-f")) font = atoi(argv[i]+2); else if (Isflag(argv[i],"-p")) poll = Max(atoi(argv[i]+2),10); else usage(argv[0],argv[i]); } /* setup mgr stuff */ m_setup(M_FLUSH); m_push(P_MENU|P_EVENT|P_FLAGS); m_setmode(M_NOWRAP); m_ttyset(); signal(SIGTERM,clean); signal(SIGINT,clean); signal(SIGALRM,update); menu_load(1,MENU_COUNT,menu); m_selectmenu(1); old_msg_cnt = MSGS(); get_msg(line,old_msg_cnt); if (shape) { m_setmode(M_ACTIVATE); m_size(strlen(line)+2,1); } m_printstr(line); m_setevent(REDRAW,"R\n"); m_setevent(ACTIVATED,"A\n"); m_clearmode(M_ACTIVATE); alarm(poll); while(1) { char buff[80]; m_gets(buff); alarm(0); /* read msgs */ old_msg_cnt = msg_cnt; msg_cnt = MSGS(); if (msg_cnt > 0 && *buff == 'A') { m_push(P_POSITION|P_EVENT|P_FLAGS|P_FONT); if (font != -1) m_font(font); m_sizeall(xpos,ypos,80,24); m_printstr("\freading msgs...\r"); m_ttyreset(); system(MSGSCMD); m_gets(buff); m_ttyset(); m_pop(); } /* wait for window to deactivate */ else if (*buff == 'A') { m_setevent(DEACTIVATED,RESUME); do { m_printstr("\f Your msgs system here "); m_gets(buff); } while(!SCMP(buff,RESUME)); m_clearevent(DEACTIVATED); } old_msg_cnt = msg_cnt; msg_cnt = MSGS(); get_msg(line,msg_cnt); m_printstr(line); m_clearmode(M_ACTIVATE); alarm(poll); } return 0; }