📄 url.c
字号:
#line 162 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx"#include "mal_config.h"#include "url.h"#include "mal.h"#include "mal_exception.h"void getword(char *word, char *line, char stop);char x2c(char *what);void plustospace(char *str);url_export str URLnew(str *url, str *val);url_export str URLgetAnchor(str *retval, str *val);url_export str URLgetBasename(str *retval, str *t);url_export str URLgetContent(str *retval, str *Str1);url_export str URLgetContext(str *retval, str *val);url_export str URLgetDirectory(int *ret, str *tv);url_export str URLgetDomain(str *retval, str *tv);url_export str URLgetExtension(str *retval, str *tv);url_export str URLgetFile(str *retval, str *tv);url_export str URLgetHost(str *retval, str *tv);url_export str URLgetPort(str *retval, str *tv);url_export str URLgetProtocol(str *retval, str *tv);url_export str URLgetQuery(str *retval, str *tv);url_export str URLgetQueryArg(int *ret, str *tv);url_export str URLgetUser(str *retval, str *tv);url_export str URLgetRobotURL(str *retval, str *tv);url_export str URLisaURL(bit *retval, str *tv);url_export str URLnew4(str *url, str *protocol, str *server, int *port, str *file);url_export str URLnew3(str *url, str *protocol, str *server, str *file);url_export int URLfromString(str src, int *len, str *url);url_export int URLtoString(str *s, int *len, str src);/* COMMAND "getAnchor": Extract an anchor (reference) from the URL * SIGNATURE: getAnchor(url) : str; */strurl_getAnchor(str *retval, /* put string: pointer to char here. */ url Str1 /* string: pointer to char. */ ){ str s, d; if (Str1 == 0) throw(ILLARG, "url.getAnchor", "url missing"); s = strchr(Str1, '#'); if (s == 0) s= (str) str_nil; d = (str) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getBasename": Extract the base of the last file name of the URL, * thus, excluding the file extension. * SIGNATURE: getBasename(str) : str; */strurl_getBasename(str *retval, url t){ str d = 0, s; if (t == 0) throw(ILLARG, "url.getBasename", "url missing"); s = strrchr(t, '/'); if (s) s++; else s = (str) str_nil; d = (str) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); s = strchr(d, '.'); if (s) *s = 0; *retval = d; return MAL_SUCCEED;}/* COMMAND "getContent": Retrieve the file referenced * SIGNATURE: getContent(str) : str; */strurl_getContent(str *retval, /* put string: pointer to char here. */ url Str1 /* string: pointer to char. */ ){ /* TODO: getContent should not return a string */ if (!Str1) throw(ILLARG, "url.getContent", "url missing"); strcpy(*retval, "functions not implemented"); return MAL_SUCCEED;}/* COMMAND "getContext": Extract the path context from the URL * SIGNATURE: getContext(str) : str; */strurl_getContext(str *retval, url Str1){ str s, d; if (Str1 == 0) throw(ILLARG, "url.getContext", "url missing"); s = strstr(Str1, "://"); if (s) s += 3; else s = Str1; s = strchr(s, '/'); if (s == 0) s= (str) str_nil; d = GDKmalloc(strlen(Str1) - (s - Str1) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getDirectory": Extract the directory names from the URL * SIGNATURE: getDirectory(str) : bat[int,str]; */strurl_getDirectory(BAT **retval, /* put pointer to BAT[int,str] record here. */ url t){ static char buf[1024]; char *s; int i = 0, k = 0; BAT *b = NULL; if (t == 0) throw(ILLARG, "url.getDirectory", "url missing"); while (*t && *t != ':') t++; t++; if (*t != '/') goto getDir_done; t++; if (*t != '/') goto getDir_done; t++; while (*t && *t != '/') t++; b = BATnew(TYPE_int, TYPE_str, 40); if (b == 0) throw(MAL, "url.getDirectory", "could not create BAT"); s = buf; for (t++; *t; t++) { if (*t == '/') { *s = 0; BUNins(b, &k, buf, FALSE); k++; s = buf; *s = 0; i = 0; continue; } *s++ = *t; if (i++ == 1023) throw(PARSE, "url.getDirectory","server name too long"); }getDir_done: #line 128 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx" BATrename(b,"dir_name"); BATroles(b,"dir","name"); BATmode(b,TRANSIENT); *retval= b;#line 325 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx" return MAL_SUCCEED;}/* COMMAND "getDomain": Extract the Internet domain from the URL * SIGNATURE: getDomain(str) : str; */strURLgetDomain(str *retval, str *u){ static char buf[1024]; char *b, *d, *s = buf; int i = 0; url t= *u; *retval = 0; s = (str)str_nil; if (t == 0) throw(ILLARG, "url.getDomain", "domain missing"); while (*t && *t != ':') t++; t++; if (*t != '/') goto getDomain_done; t++; if (*t != '/') goto getDomain_done; t++; b = buf; d = 0; for (; *t && *t != '/'; t++) { if (*t == '.') d = b; if (*t == ':') break; *b++ = *t; if (i++ == 1023) throw(PARSE, "url.getDomain", "server name too long\n"); } *b = 0; if (d) s = d + 1;getDomain_done: d = (char*) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getExtension": Extract the file extension of the URL * SIGNATURE: getExtension(str) : str; */strurl_getExtension(str *retval, url t){ str d = 0, s; if (t == 0) throw(ILLARG, "url.getExtension", "url missing"); s = strrchr(t, '/'); if (s) { s++; s = strchr(s + 1, '.'); if (s) s++; else s = (str) str_nil; } else s = (str) str_nil; d = (str) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getFile": Extract the last file name of the URL * SIGNATURE: getFile(str) : str; */strurl_getFile(str *retval, url t){ str d = 0, s; if (t == 0) throw(ILLARG, "url.getFile", "url missing"); s = strrchr(t, '/'); if (s) s++; else s = (str) str_nil; d = (str) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}#line 425 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx"strurl_getHost(str *retval, /* is GDKfree needed ? */ url t){ static char buf[1024]; char *b, *d, *s; int i = 0; s = (str)str_nil; if (t == 0) throw(ILLARG, "url.getHost", "url missing"); while (*t && *t != ':') t++; t++; if (*t != '/') goto getHost_done; t++; if (*t != '/') goto getHost_done; t++; b = buf; s = buf; for (; *t && *t != '/'; t++) { *b++ = *t; if (i++ == 1023) throw(PARSE, "url.getHost", "server name too long"); } *b = 0;getHost_done: d = (char*) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}#line 464 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx"strurl_getPort(str *retval, url t){ static char buf[1024]; char *b, *d = 0, *s = buf; int i = 0; if (t == 0) throw(ILLARG, "url.getPort", "url missing"); s = (str)str_nil; while (*t && *t != ':') t++; t++; if (*t != '/') goto getPort_done; t++; if (*t != '/') goto getPort_done; t++; b = buf; for (; *t && *t != '/'; t++) { if (*t == ':') d = b; *b++ = *t; if (i++ == 1023) throw(PARSE, "url.getPort", "server name too long"); } *b = 0; if (d) s = d + 1; else s = (str)str_nil;getPort_done: d = (char*) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getProtocol": Extract the protocol from the URL * SIGNATURE: getProtocol(str) : str; */strurl_getProtocol(str *retval, /* put string: pointer to char here. */ url t){ static char buf[1024]; char *b, *d = 0; int i = 0; if (t == 0) throw(ILLARG, "url.getProtocol", "url missing"); b = buf; for (; *t && *t != ':'; t++) { *b++ = *t; if (i++ == 1023) throw(PARSE, "url_getProtocol", "server name too long"); } *b = 0; d = (char*) GDKmalloc(strlen(buf) + 1); if (d) strcpy(d, buf); *retval = d; return MAL_SUCCEED;}strurl_getQuery(str *retval, url Str1){ char *s, *d; if (Str1 == 0) throw(ILLARG, "url.getQuery", "url missing"); s = strchr(Str1, '?'); if (s == 0) s= (str) str_nil; else s++; d = (char*) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d; return MAL_SUCCEED;}/* COMMAND "getQueryArg": Extract the argument mappings from the URL query * SIGNATURE: getQueryArg(str) : bat[str,str]; */strurl_getQueryArg(BAT **retval, url t){ char query[1024]; char val[1024]; char name[1024]; char *unescapedval; BAT *b; if (t == 0) throw(ILLARG, "url.getQueryArg", "url missing"); if (unescape_str(&unescapedval, t) != MAL_SUCCEED) throw(MAL, "url.getQueryArg", "failure to unescape"); t = strchr(unescapedval, '?'); if (t == 0) throw(ILLARG, "url.getQueryArg", "variable missing"); t++; b = BATnew(TYPE_str, TYPE_str, 40); if (b == 0) throw(MAL, "url.getQueryArg","could not create BAT"); if (strlen(t) > 1023) throw(PARSE, "url.getQueryArg", "string too long"); strcpy(query, t); for (; query[0] != '\0';) { getword(val, query, '&'); plustospace(val); getword(name, val, '='); BUNins(b, name, val, FALSE); } #line 128 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx" BATrename(b,"dir_name"); BATroles(b,"dir","name"); BATmode(b,TRANSIENT); *retval= b;#line 583 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/url.mx" return MAL_SUCCEED;}/* COMMAND "getRobotURL": Extract the location of the robot control file * SIGNATURE: getRobotURL(str) : str; */strurl_getRobotURL(str *retval, /* put string: pointer to char here. */ url t /* string: pointer to char. */ ){ static char buf[1024]; char *b, *d, *s = buf; int i = 0; if (t == 0) throw(ILLARG, "url.getRobotURL", "url missing"); b = buf; while (*t && *t != ':') *b++ = *t++; *b++ = *t++; if (*t != '/') goto getRobot_done; *b++ = *t++; if (*t != '/') goto getRobot_done; *b++ = *t++; for (; *t && *t != '/'; t++) { *b++ = *t; if (i++ == 1000) throw(PARSE, "url.getRobot", "server name too long"); } strcpy(b, "/robots.txt");getRobot_done: d = (char*) GDKmalloc(strlen(s) + 1); if (d) strcpy(d, s); *retval = d;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -