mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
january 2009
This commit is contained in:
parent
94530cc322
commit
bdfae4e350
64 changed files with 79 additions and 794 deletions
|
@ -257,7 +257,7 @@ xmlparse(a) {
|
|||
# ifdef JABBER_TRANSPARENCY
|
||||
ixbuf = lasta = 0;
|
||||
innerxml = ixbuf;
|
||||
#endif
|
||||
# endif
|
||||
// handle stuff
|
||||
funcall(nodeHandler, currentnode);
|
||||
currentnode = 0;
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
// $Id: parse.c,v 1.10 2005/03/14 10:23:28 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// the actual RSS parser
|
||||
// why the file is called "parse.c" i don't know
|
||||
// it certainly wouldn't be a good idea to have several parsers in one file
|
||||
// so you may as well rename it into rss.c? TODO
|
||||
//
|
||||
#include <net.h>
|
||||
inherit NET_PATH "xml/common";
|
||||
|
||||
xmlparse(str) {
|
||||
// DOM-style XML parser for parsing RSS and RDF
|
||||
// see CHANGESTODO for discussion on how to make it compliant
|
||||
mapping dom;
|
||||
string namespace;
|
||||
string tag, lasttag, data, params;
|
||||
int pos, close;
|
||||
|
||||
pos = 0;
|
||||
close = -1;
|
||||
namespace = "";
|
||||
dom = ([ ]);
|
||||
while(pos = strstr(str, "<", pos) + 1){
|
||||
// D2(D("looping xmlparser...\n");)
|
||||
data = xmlunquote(str[close + 1..pos - 2]);
|
||||
close = strstr(str, ">", pos);
|
||||
sscanf(str[pos..close - 1], "%s%t%s", tag, params) || tag = str[pos..close - 1];
|
||||
if (strlen(tag) && (tag[0] == '!' || tag[0] == '?' || tag[0..2] == "rdf" || tag[0..2] == "rss")) {
|
||||
if(tag[0..2] == "rdf" || tag[0..2] == "rss")
|
||||
dom["type"] = tag[0..2];
|
||||
} else if (strlen(tag) && tag[0] == '/') {
|
||||
// D2(D("closing " + tag + "\n");)
|
||||
// closing tag
|
||||
if (tag[1..] != lasttag){
|
||||
// D2(D("warning: XML may be malformed\n");)
|
||||
;
|
||||
} else {
|
||||
// handle data
|
||||
if (data != "\n") {
|
||||
if (stringp(dom[namespace]) )
|
||||
dom[namespace] = ({ dom[namespace], data });
|
||||
else if (pointerp(dom[namespace]))
|
||||
dom[namespace] += ({ data });
|
||||
else
|
||||
dom[namespace] = data;
|
||||
}
|
||||
namespace = namespace[..<strlen(lasttag) + 2];
|
||||
lasttag = explode(namespace, "_")[<1];
|
||||
}
|
||||
} else {
|
||||
// open tag
|
||||
if ((params && params[<1] == '/') || tag[<1] == '/') {
|
||||
// better than before, but not really
|
||||
// correct to simply skip it
|
||||
continue;
|
||||
}
|
||||
// D2(D("opening " + tag + "\n");)
|
||||
namespace += "_" + tag;
|
||||
lasttag = tag;
|
||||
}
|
||||
pos = close;
|
||||
}
|
||||
// P2(("DOM: %O\n", dom))
|
||||
return dom;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// $Id: common.c,v 1.8 2005/03/14 10:23:28 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// yes even we can't avoid having XML parsing classes
|
||||
// used by jabber and RSS (place/news)
|
||||
//
|
||||
#include <interface.h>
|
||||
|
||||
#include "xml.h"
|
||||
|
||||
string xmlquote(string s) {
|
||||
// return xml escaped version of s
|
||||
s = replace(s, "&", "&");
|
||||
s = replace(s, "<", "<");
|
||||
s = replace(s, ">", ">");
|
||||
s = replace(s, "\"", """);
|
||||
s = replace(s, "'", "'");
|
||||
return s;
|
||||
}
|
||||
|
||||
string xmlunquote(string s) {
|
||||
// return unquoted xml version of s
|
||||
s = replace(s, "&", "&");
|
||||
s = replace(s, "<", "<");
|
||||
s = replace(s, ">", ">");
|
||||
s = replace(s, """, "\"");
|
||||
s = replace(s, "'", "'");
|
||||
// should this take care of ß-style thingies
|
||||
// s = regreplace(s, "ß", 223);
|
||||
s = regreplace(s, "&#[0-9][0-9][0-9];",
|
||||
(: return sprintf("%c", to_int($1[2..<2])); :), 1);
|
||||
return s;
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
// $Id: parse.c,v 1.10 2005/03/14 10:23:28 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// the actual RSS parser
|
||||
// why the file is called "parse.c" i don't know
|
||||
// it certainly wouldn't be a good idea to have several parsers in one file
|
||||
// so you may as well rename it into rss.c? TODO
|
||||
//
|
||||
#include <net.h>
|
||||
inherit NET_PATH "xml/common";
|
||||
|
||||
rssparse(str) {
|
||||
// DOM-style XML parser for parsing RSS and RDF
|
||||
// see CHANGESTODO for discussion on how to make it compliant
|
||||
mapping dom;
|
||||
string namespace;
|
||||
string tag, lasttag, data, params;
|
||||
int pos, close;
|
||||
|
||||
pos = 0;
|
||||
close = -1;
|
||||
namespace = "";
|
||||
dom = ([ ]);
|
||||
while(pos = strstr(str, "<", pos) + 1){
|
||||
// D2(D("looping xmlparser...\n");)
|
||||
data = xmlunquote(str[close + 1..pos - 2]);
|
||||
close = strstr(str, ">", pos);
|
||||
sscanf(str[pos..close - 1], "%s%t%s", tag, params) || tag = str[pos..close - 1];
|
||||
if (strlen(tag) && (tag[0] == '!' || tag[0] == '?' || tag[0..2] == "rdf" || tag[0..2] == "rss")) {
|
||||
if(tag[0..2] == "rdf" || tag[0..2] == "rss")
|
||||
dom["type"] = tag[0..2];
|
||||
} else if (strlen(tag) && tag[0] == '/') {
|
||||
// D2(D("closing " + tag + "\n");)
|
||||
// closing tag
|
||||
if (tag[1..] != lasttag){
|
||||
// D2(D("warning: XML may be malformed\n");)
|
||||
;
|
||||
} else {
|
||||
// handle data
|
||||
if (data != "\n") {
|
||||
if (stringp(dom[namespace]) )
|
||||
dom[namespace] = ({ dom[namespace], data });
|
||||
else if (pointerp(dom[namespace]))
|
||||
dom[namespace] += ({ data });
|
||||
else
|
||||
dom[namespace] = data;
|
||||
}
|
||||
namespace = namespace[..<strlen(lasttag) + 2];
|
||||
lasttag = explode(namespace, "_")[<1];
|
||||
}
|
||||
} else {
|
||||
// open tag
|
||||
if ((params && params[<1] == '/') || tag[<1] == '/') {
|
||||
// better than before, but not really
|
||||
// correct to simply skip it
|
||||
continue;
|
||||
}
|
||||
// D2(D("opening " + tag + "\n");)
|
||||
namespace += "_" + tag;
|
||||
lasttag = tag;
|
||||
}
|
||||
pos = close;
|
||||
}
|
||||
// P2(("DOM: %O\n", dom))
|
||||
return dom;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// $Id: common.c,v 1.8 2005/03/14 10:23:28 lynx Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// yes even we can't avoid having XML parsing classes
|
||||
// used by jabber and RSS (place/news)
|
||||
//
|
||||
#include <interface.h>
|
||||
|
||||
#include "xml.h"
|
||||
|
||||
string xmlquote(string s) {
|
||||
// return xml escaped version of s
|
||||
s = replace(s, "&", "&");
|
||||
s = replace(s, "<", "<");
|
||||
s = replace(s, ">", ">");
|
||||
s = replace(s, "\"", """);
|
||||
s = replace(s, "'", "'");
|
||||
return s;
|
||||
}
|
||||
|
||||
string xmlunquote(string s) {
|
||||
// return unquoted xml version of s
|
||||
s = replace(s, "&", "&");
|
||||
s = replace(s, "<", "<");
|
||||
s = replace(s, ">", ">");
|
||||
s = replace(s, """, "\"");
|
||||
s = replace(s, "'", "'");
|
||||
// should this take care of ß-style thingies
|
||||
// s = regreplace(s, "ß", 223);
|
||||
s = regreplace(s, "&#[0-9][0-9][0-9];",
|
||||
(: return sprintf("%c", to_int($1[2..<2])); :), 1);
|
||||
return s;
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
// $Id: parse.c,v 1.12 2005/06/07 07:03:02 fippo Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// the actual RSS parser
|
||||
// why the file is called "parse.c" i don't know
|
||||
// it certainly wouldn't be a good idea to have several parsers in one file
|
||||
// so you may as well rename it into rss.c? TODO
|
||||
//
|
||||
#include <net.h>
|
||||
#include <xml.h>
|
||||
inherit NET_PATH "xml/common";
|
||||
|
||||
// DOM style XML parser
|
||||
xmlparse(a) {
|
||||
// this one is very similar to the jabber parser
|
||||
// from a syntax point of view
|
||||
string tag, data, params;
|
||||
int pos, close;
|
||||
int list;
|
||||
|
||||
XMLNode currentnode = 0;
|
||||
XMLNode nodestack = ({ });
|
||||
params = "";
|
||||
pos = 0;
|
||||
close = -1;
|
||||
|
||||
while(pos = strstr(a, "<", pos) + 1) {
|
||||
data = xmlunquote(a[close + 1..pos - 2]);
|
||||
close = strstr(a, ">", pos);
|
||||
|
||||
sscanf(a[pos..close - 1], "%s%t%s", tag, params) || tag = a[pos..close-1];
|
||||
if(tag == "") return -1;
|
||||
if (strlen(tag) && (tag[0] == '!' || tag[0] == '?')){
|
||||
// P2(("skipping tag starting with ! or ?\n"))
|
||||
} else if (strlen(tag) && tag[0] == '/'){
|
||||
P4(("should be closing tag %O and am closing %O\n",
|
||||
currentnode[Tag], tag[1..]))
|
||||
if (!currentnode || currentnode[Tag] != tag[1..]) {
|
||||
// unbalanced xml?
|
||||
} else {
|
||||
// schliessender tag gefunden, die haben keine Parameter
|
||||
if (strlen(data) && data != "\r\n" && data != "\n"){
|
||||
// not sure if this works correct
|
||||
unless(pointerp(currentnode[Cdata]))
|
||||
currentnode[Cdata] = data;
|
||||
else
|
||||
currentnode[Cdata] += ({ data });
|
||||
}
|
||||
if (sizeof(nodestack) == 0) {
|
||||
// we can probably break/return here
|
||||
break;
|
||||
} else {
|
||||
currentnode = nodestack[<1];
|
||||
nodestack = nodestack[..<2];
|
||||
}
|
||||
}
|
||||
} else { // opening tag
|
||||
int selfclosing;
|
||||
mixed newnode;
|
||||
string key, val;
|
||||
|
||||
if (strlen(params) && params[<1] == '/') {
|
||||
params = params[..<2];
|
||||
selfclosing = 1;
|
||||
newnode = new_XMLNode;
|
||||
} else if (tag[<1] == '/') {
|
||||
tag = tag[..<2];
|
||||
selfclosing = 1;
|
||||
newnode = new_XMLNode;
|
||||
} else {
|
||||
newnode = new_XMLNode;
|
||||
}
|
||||
if(currentnode){
|
||||
nodestack += ({ currentnode });
|
||||
if (pointerp(currentnode[Child][tag])) {
|
||||
unless (nodelistp(currentnode[Child][tag])) {
|
||||
// tranform
|
||||
currentnode[Child][tag] = ({ currentnode[Child][tag], newnode });
|
||||
} else {
|
||||
// append
|
||||
currentnode[Child][tag] += ({ newnode });
|
||||
}
|
||||
currentnode = currentnode[Child][tag][<1];
|
||||
} else {
|
||||
currentnode[Child][tag] = newnode;
|
||||
currentnode = currentnode[Child][tag];
|
||||
}
|
||||
} else {
|
||||
currentnode = newnode;
|
||||
}
|
||||
currentnode[Tag] = tag;
|
||||
foreach(string pa: explode(params, " ")) {
|
||||
if(sscanf(pa, "%s=\"%s\"", key, val) == 2 ||
|
||||
sscanf(pa, "%s=\'%s\'", key, val) == 2 ) {
|
||||
currentnode[Param][key] = val;
|
||||
|
||||
}
|
||||
}
|
||||
if (selfclosing) {
|
||||
if (sizeof(nodestack) == 0){
|
||||
PT(("nodestack empty\n"))
|
||||
} else {
|
||||
currentnode = nodestack[<1];
|
||||
nodestack = nodestack[..<2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentnode;
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
// $Id: parse.c,v 1.12 2005/06/07 07:03:02 fippo Exp $ // vim:syntax=lpc
|
||||
//
|
||||
// the actual RSS parser
|
||||
// why the file is called "parse.c" i don't know
|
||||
// it certainly wouldn't be a good idea to have several parsers in one file
|
||||
// so you may as well rename it into rss.c? TODO
|
||||
//
|
||||
#include <net.h>
|
||||
#include <xml.h>
|
||||
inherit NET_PATH "xml/common";
|
||||
|
||||
// DOM style XML parser
|
||||
xmlparse(a) {
|
||||
// this one is very similar to the jabber parser
|
||||
// from a syntax point of view
|
||||
string tag, data, params;
|
||||
int pos, close;
|
||||
int list;
|
||||
|
||||
XMLNode currentnode = 0;
|
||||
XMLNode nodestack = ({ });
|
||||
params = "";
|
||||
pos = 0;
|
||||
close = -1;
|
||||
|
||||
while(pos = strstr(a, "<", pos) + 1) {
|
||||
data = xmlunquote(a[close + 1..pos - 2]);
|
||||
close = strstr(a, ">", pos);
|
||||
|
||||
sscanf(a[pos..close - 1], "%s%t%s", tag, params) || tag = a[pos..close-1];
|
||||
if(tag == "") return -1;
|
||||
if (strlen(tag) && (tag[0] == '!' || tag[0] == '?')){
|
||||
// P2(("skipping tag starting with ! or ?\n"))
|
||||
} else if (strlen(tag) && tag[0] == '/'){
|
||||
P4(("should be closing tag %O and am closing %O\n",
|
||||
currentnode[Tag], tag[1..]))
|
||||
if (!currentnode || currentnode[Tag] != tag[1..]) {
|
||||
// unbalanced xml?
|
||||
} else {
|
||||
// schliessender tag gefunden, die haben keine Parameter
|
||||
if (strlen(data) && data != "\r\n" && data != "\n"){
|
||||
// not sure if this works correct
|
||||
unless(pointerp(currentnode[Cdata]))
|
||||
currentnode[Cdata] = data;
|
||||
else
|
||||
currentnode[Cdata] += ({ data });
|
||||
}
|
||||
if (sizeof(nodestack) == 0) {
|
||||
// we can probably break/return here
|
||||
break;
|
||||
} else {
|
||||
currentnode = nodestack[<1];
|
||||
nodestack = nodestack[..<2];
|
||||
}
|
||||
}
|
||||
} else { // opening tag
|
||||
int selfclosing;
|
||||
mixed newnode;
|
||||
string key, val;
|
||||
|
||||
if (strlen(params) && params[<1] == '/') {
|
||||
params = params[..<2];
|
||||
selfclosing = 1;
|
||||
newnode = new_XMLNode;
|
||||
} else if (tag[<1] == '/') {
|
||||
tag = tag[..<2];
|
||||
selfclosing = 1;
|
||||
newnode = new_XMLNode;
|
||||
} else {
|
||||
newnode = new_XMLNode;
|
||||
}
|
||||
if(currentnode){
|
||||
nodestack += ({ currentnode });
|
||||
if (pointerp(currentnode[Child][tag])) {
|
||||
unless (nodelistp(currentnode[Child][tag])) {
|
||||
// tranform
|
||||
currentnode[Child][tag] = ({ currentnode[Child][tag], newnode });
|
||||
} else {
|
||||
// append
|
||||
currentnode[Child][tag] += ({ newnode });
|
||||
}
|
||||
currentnode = currentnode[Child][tag][<1];
|
||||
} else {
|
||||
currentnode[Child][tag] = newnode;
|
||||
currentnode = currentnode[Child][tag];
|
||||
}
|
||||
} else {
|
||||
currentnode = newnode;
|
||||
}
|
||||
currentnode[Tag] = tag;
|
||||
foreach(string pa: explode(params, " ")) {
|
||||
if(sscanf(pa, "%s=\"%s\"", key, val) == 2 ||
|
||||
sscanf(pa, "%s=\'%s\'", key, val) == 2 ) {
|
||||
currentnode[Param][key] = val;
|
||||
|
||||
}
|
||||
}
|
||||
if (selfclosing) {
|
||||
if (sizeof(nodestack) == 0){
|
||||
PT(("nodestack empty\n"))
|
||||
} else {
|
||||
currentnode = nodestack[<1];
|
||||
nodestack = nodestack[..<2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentnode;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue