| top | | | ^ | | | | | | section top | | | ^ | | | | | | section top | | | ^ | | | | | | section top | | - proc wyrm_uriGet—Get a URI part. Returns extracted part or NULL if error.
- Memory. Caller decrements reference count while finished.
| - output intr—Possible error message.
| - input part—Which part to extract.
| - input uri—URI to parse and examine.
|
|
|
Obj wyrm_uriGet(Intr intr,Obj uri,chars part) {
Parts parts = parseURI(intr,uri),gotten; Obj R;
if (!parts) return 0;
if (streq(part,"PATH") || strieq(part,"macintosh") || strieq(part,"unix")) {
<Get file join compatiable path list>
}else {
gotten = getPart(parts,part);
if (!gotten) {
rprintf(intr,"unknown part: %s",part); R = 0;
}else if (gotten->value) {
R = incr(Tcl_NewStringObj(gotten->value,gotten->length));
}else {
rprintf(intr,"missing: %s",part); R = 0;
}
if (streq(part,"path")) R = canonicalPath(R);
}
while (parts) {
parts = deletePart(parts);
}
return R;
}
| ^ | | | | | | section top | | Obj wyrm_uriGet(Intr intr,Obj uri,chars part); | ^ | | | | | | section top | | | ^ | | | | | | section top | | | ^ | | | | | | section top | | - proc wyrm_uriGetAll—Get all URI parts. Returns part/value pairs list of existing parts or NULL if error.
- Memory. Caller decrements reference count while finished.
| - output intr—Possible error message.
| - input uri—URI to parse and examine.
|
|
|
Obj wyrm_uriGetAll(Intr intr,Obj uri) {
Parts parts = parseURI(intr,uri); Obj R;
if (!parts) return 0;
R = incr(Tcl_NewObj());
while (parts) {
if (parts->value) {
Obj name,value;
deescapePart(parts);
name = Tcl_NewStringObj(parts->name,-1);
value = incr(Tcl_NewStringObj(parts->value,parts->length));
if (streq(parts->name,"path")) value = canonicalPath(value);
if (Tcl_ListObjAppendElement(intr,R,name)!=TCL_OK
|| Tcl_ListObjAppendElement(intr,R,value)!=TCL_OK)
{
decr(value); decr(R); R = 0; break;
}
decr(value);
}
parts = deletePart(parts);
}
while (parts) parts = deletePart(parts);
return R;
}
| ^ | | | | | | section top | | Obj wyrm_uriGetAll(Intr intr,Obj uri); | ^ | | | | | | section top | | | ^ | | | | | | section top | | | ^ | | | | | | section top | | - proc wyrm_uriPut—Put URI part value; returns new URI or NULL if error.
- Memory. Caller decrements reference count while finished.
| - output intr—Possible error message.
| - input newpart—New value of the part.
| - input part—Which part to replace or add.
| - input uri—URI to parse and modify.
|
|
|
Obj wyrm_uriPut(Intr intr,Obj uri,chars part,Obj newpart) {
Parts parts = parseURI(intr,uri); Obj cpart = 0, R = 0; char state = 'D';
incr(newpart);
if (streq(part,"macintosh")) {
Obj X = convertMacintosh(intr,newpart);
if (X) {
decr(newpart); newpart = X;
part = "path"; state = 'E';
}
}else if (streq(part,"PATH") || strieq(part,"unix")) {
Obj X = convertUnix(intr,newpart);
if (X) {
decr(newpart); newpart = X;
part = "path"; state = 'E';
}
}
cpart = streq(part,"path") ? canonicalPath(newpart) : newpart;
if (cpart) {
Parts putting; int n; chars s = Tcl_GetStringFromObj(cpart,&n);
if (!parts) {decr(cpart); return 0;}
putting = putPart(parts,part,s,n,state);
if (!putting) {
beforeParts(parts,part,-1,s,n,state);
}
decr(cpart);
R = generateURI(intr,parts);
}else {
R = 0;
}
while (parts) parts = deletePart(parts);
return R;
}
| ^ | | | | | | section top | | Obj wyrm_uriPut(Intr intr,Obj uri,chars part,Obj newpart); | ^ | | | | | | section top | | - proc wyrm_uriPutList—Put URI part value. Returns new URI or NULL if error.
- Memory. Caller decrements reference count while finished.
| - input N—Number of part/value pairs list.
| - input P—Part/value pairs list.
| - output intr—Possible error message.
| - input uri—URI to parse and modify.
|
|
|
Obj wyrm_uriPutList(Intr intr,Obj uri,int N,Obj *P) {
Parts parts = parseURI(intr,uri),putting; Obj R;
if (!parts) return 0;
while (N>1) {
chars part = Tcl_GetStringFromObj(P[0],0); Obj cpart;
Obj newpart = incr(P[1]); int n; chars s; char state = 'D';
if (streq(part,"macintosh")) {
Obj X = convertMacintosh(intr,newpart);
if (X) {
decr(newpart); newpart = X;
part = "path"; state = 'E';
}
}else if (streq(part,"PATH") || strieq(part,"unix")) {
Obj X = convertUnix(intr,newpart);
if (X) {
decr(newpart); newpart = X;
part = "path"; state = 'E';
}
}
cpart = streq(part,"path") ? canonicalPath(newpart) : newpart;
s = Tcl_GetStringFromObj(cpart,&n);
N -= 2; P += 2;
putting = putPart(parts,part,s,n,state);
if (!putting) {
beforeParts(parts,part,-1,s,n,state);
}
decr(cpart);
}
R = generateURI(intr,parts);
while (parts) parts = deletePart(parts);
return R;
}
| ^ | | | | | | section top | | Obj wyrm_uriPutList(Intr intr,Obj uri,int N,Obj *P); | ^ | | | | | | section top | | | ^ | | | | | | section top | | | ^ | | | | | | section top | | - proc wyrm_uriRemove—Put URI part value. Returns new URI or NULL if error.
- Memory. Caller decrements reference count while finished.
| - output intr—Possible error message.
| - input part—Which part to remove.
| - input uri—URI to parse and modify.
|
|
|
Obj wyrm_uriRemove(Intr intr,Obj uri,chars part) {
Parts parts = parseURI(intr,uri),removing; Obj R;
if (!parts) return 0;
removing = findPart(parts,part);
if (removing) removing = deletePart(removing);
if (streq(part,"scheme")) {
parts = beforeParts(removing,"scheme",-1,"(relative)",-1,'e')->prev;
parts = parts->prev;
}
R = generateURI(intr,parts);
while (parts) parts = deletePart(parts);
return R;
}
| ^ | | | | | | section top | | Obj wyrm_uriRemove(Intr intr,Obj uri,chars part); | ^ | | |
| |