inc/htmlPage.h File Reference

#include "dystring.h"

Include dependency graph for htmlPage.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  htmlStatus
struct  htmlCookie
struct  htmlAttribute
struct  htmlTag
struct  htmlFormVar
struct  htmlForm
struct  htmlPage

Functions

void htmlStatusFree (struct htmlStatus **pStatus)
void htmlStatusFreeList (struct htmlStatus **pList)
htmlStatushtmlStatusParse (char **pText)
void htmlCookieFree (struct htmlCookie **pCookie)
void htmlCookieFreeList (struct htmlCookie **pList)
htmlCookiehtmlCookieFileRead (char *fileName)
void htmlAttributeFree (struct htmlAttribute **pAttribute)
void htmlAttributeFreeList (struct htmlAttribute **pList)
char * htmlTagAttributeVal (struct htmlPage *page, struct htmlTag *tag, char *name, char *defaultVal)
char * htmlTagAttributeNeeded (struct htmlPage *page, struct htmlTag *tag, char *name)
void htmlTagFree (struct htmlTag **pTag)
void htmlTagFreeList (struct htmlTag **pList)
void htmlFormVarFree (struct htmlFormVar **pVar)
void htmlFormVarFreeList (struct htmlFormVar **pList)
void htmlFormVarPrint (struct htmlFormVar *var, FILE *f, char *prefix)
void htmlFormFree (struct htmlForm **pForm)
void htmlFormFreeList (struct htmlForm **pList)
void htmlFormPrint (struct htmlForm *form, FILE *f)
char * htmlFormCgiVars (struct htmlPage *page, struct htmlForm *form, char *buttonName, char *buttonVal, struct dyString *dyHeader)
htmlFormhtmlFormGet (struct htmlPage *page, char *name)
htmlFormVarhtmlFormVarGet (struct htmlForm *form, char *name)
void htmlFormVarSet (struct htmlForm *form, char *name, char *val)
htmlFormVarhtmlPageGetVar (struct htmlPage *page, struct htmlForm *form, char *name)
void htmlPageSetVar (struct htmlPage *page, struct htmlForm *form, char *name, char *val)
void htmlPageFree (struct htmlPage **pPage)
void htmlPageFreeList (struct htmlPage **pList)
char * htmlExpandUrl (char *base, char *url)
char * htmlNextCrLfLine (char **pS)
slNamehtmlPageScanAttribute (struct htmlPage *page, char *tagName, char *attribute)
slNamehtmlPageLinks (struct htmlPage *page)
void htmlPageFormOrAbort (struct htmlPage *page)
void htmlPageValidateOrAbort (struct htmlPage *page)
char * htmlSlurpWithCookies (char *url, struct htmlCookie *cookies)
htmlPagehtmlPageParse (char *url, char *fullText)
htmlPagehtmlPageParseOk (char *url, char *fullText)
htmlPagehtmlPageParseNoHead (char *url, char *htmlText)
htmlPagehtmlPageFromForm (struct htmlPage *origPage, struct htmlForm *form, char *buttonName, char *buttonVal)
htmlPagehtmlPageGetWithCookies (char *url, struct htmlCookie *cookies)
htmlPagehtmlPageGet (char *url)
htmlPagehtmlPageForwarded (char *url, struct htmlCookie *cookies)
htmlPagehtmlPageForwardedNoAbort (char *url, struct htmlCookie *cookies)


Function Documentation

void htmlAttributeFree ( struct htmlAttribute **  pAttribute  ) 

Definition at line 124 of file htmlPage.c.

References freeMem(), freez(), htmlAttribute::name, and htmlAttribute::val.

Referenced by htmlAttributeFreeList().

00126 {
00127 struct htmlAttribute *att = *pAttribute;
00128 if (att != NULL)
00129     {
00130     freeMem(att->name);
00131     freeMem(att->val);
00132     freez(pAttribute);
00133     }
00134 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlAttributeFreeList ( struct htmlAttribute **  pList  ) 

Definition at line 136 of file htmlPage.c.

References htmlAttributeFree(), and htmlAttribute::next.

Referenced by htmlTagFree().

00138 {
00139 struct htmlAttribute *el, *next;
00140 
00141 for (el = *pList; el != NULL; el = next)
00142     {
00143     next = el->next;
00144     htmlAttributeFree(&el);
00145     }
00146 *pList = NULL;
00147 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlCookie* htmlCookieFileRead ( char *  fileName  )  [read]

Definition at line 80 of file htmlPage.c.

References AllocVar, cloneString(), errAbort(), lineFile::fileName, lineFileClose(), lineFileNextReal(), lineFileOpen(), lineFile::lineIx, nextWord(), skipLeadingSpaces(), slAddHead, slReverse(), and TRUE.

00083 {
00084 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00085 struct htmlCookie *list = NULL, *cookie;
00086 char *line, *word;
00087 while (lineFileNextReal(lf, &line))
00088     {
00089     word = nextWord(&line);
00090     line = skipLeadingSpaces(line);
00091     if (line == NULL)
00092         errAbort("Missing cookie value line %d of %s", lf->lineIx, lf->fileName);
00093     AllocVar(cookie);
00094     cookie->name = cloneString(word);
00095     cookie->value = cloneString(line);
00096     slAddHead(&list, cookie);
00097     }
00098 lineFileClose(&lf);
00099 slReverse(&list);
00100 return list;
00101 }

Here is the call graph for this function:

void htmlCookieFree ( struct htmlCookie **  pCookie  ) 

Definition at line 52 of file htmlPage.c.

References htmlCookie::domain, htmlCookie::expires, freeMem(), freez(), htmlCookie::name, htmlCookie::path, and htmlCookie::value.

Referenced by htmlCookieFreeList().

00054 {
00055 struct htmlCookie *cookie = *pCookie;
00056 if (cookie != NULL)
00057     {
00058     freeMem(cookie->name);
00059     freeMem(cookie->value);
00060     freeMem(cookie->domain);
00061     freeMem(cookie->path);
00062     freeMem(cookie->expires);
00063     freez(pCookie);
00064     }
00065 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlCookieFreeList ( struct htmlCookie **  pList  ) 

Definition at line 67 of file htmlPage.c.

References htmlCookieFree(), and htmlCookie::next.

Referenced by htmlPageFree().

00069 {
00070 struct htmlCookie *el, *next;
00071 
00072 for (el = *pList; el != NULL; el = next)
00073     {
00074     next = el->next;
00075     htmlCookieFree(&el);
00076     }
00077 *pList = NULL;
00078 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlExpandUrl ( char *  base,
char *  url 
)

Definition at line 1090 of file htmlPage.c.

References asciiEntityDecode(), cloneString(), cloneStringZ(), dyStringAppend(), dyStringAppendC(), dyStringAppendN(), dyStringCannibalize(), dyStringNew, expandRelativePath(), freez(), lastChar(), startsWith(), and dyString::string.

Referenced by htmlPageFromForm().

01093 {
01094 struct dyString *dy = NULL;
01095 char *hostName, *pastHostName;
01096 
01097 /* some mailto: have SGML char encoding, e.g a to hide from spambots */
01098 url = cloneString(url); /* Clone because asciiEntityDecode may modify it. */
01099 asciiEntityDecode(url, url, strlen(url));
01100 
01101 /* In easiest case URL is actually absolute and begins with
01102  * protocol.  Just return clone of url. */
01103 if (startsWith("http:", url) || startsWith("https:", url))
01104     return url;
01105 
01106 /* If it's got a colon, but no http or https, then it's some
01107  * protocol we don't understand, like a mailto.  Just return NULL. */
01108 if (strchr(url, ':') != NULL)
01109     {
01110     freez(&url);
01111     return NULL;
01112     }
01113 
01114 /* Figure out first character past host name. Load up
01115  * return string with protocol (if any) and host name. */
01116 dy = dyStringNew(256);
01117 if (startsWith("http:", base) || startsWith("https:", base))
01118     hostName = (strchr(base, ':') + 3);
01119 else
01120     hostName = base;
01121 pastHostName = strchr(hostName, '/');
01122 if (pastHostName == NULL)
01123     pastHostName = hostName + strlen(hostName);
01124 dyStringAppendN(dy, base, pastHostName - base);
01125 
01126 /* Add url to return string after host name. */
01127 if (startsWith("/", url))       /* New URL is absolute, just append to hostName */
01128     {
01129     dyStringAppend(dy, url);
01130     }
01131 else
01132     {
01133     char *curDir = pastHostName;
01134     char *endDir;
01135     if (curDir[0] == '/')
01136         curDir += 1;
01137     dyStringAppendC(dy, '/');
01138     endDir = strrchr(curDir, '/');
01139     if (endDir == NULL)
01140         endDir = curDir;
01141     if (startsWith("../", url))
01142         {
01143         char *dir = cloneStringZ(curDir, endDir-curDir);
01144         char *path = expandRelativePath(dir, url);
01145         if (path != NULL)
01146              {
01147              dyStringAppend(dy, path);
01148              }
01149         freez(&dir);
01150         freez(&path);
01151         }
01152     else
01153         {
01154         dyStringAppendN(dy, curDir, endDir-curDir);
01155         if (lastChar(dy->string) != '/')
01156             dyStringAppendC(dy, '/');
01157         dyStringAppend(dy, url);
01158         }
01159     }
01160 freez(&url);
01161 return dyStringCannibalize(&dy);
01162 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlFormCgiVars ( struct htmlPage page,
struct htmlForm form,
char *  buttonName,
char *  buttonVal,
struct dyString dyHeader 
)

Definition at line 1262 of file htmlPage.c.

References appendCgiVar(), appendMimeVar(), htmlFormVar::curVal, htmlPage::forms, isMimeEncoded(), htmlFormVar::name, newDyString(), htmlFormVar::next, safef(), sameWord, htmlFormVar::tagName, TRUE, htmlFormVar::type, and htmlForm::vars.

Referenced by htmlPageFromForm().

01266 {
01267 struct dyString *dy = newDyString(0);
01268 struct htmlFormVar *var;
01269 boolean isMime = isMimeEncoded(form);
01270 int mimeParts = 0;
01271 char boundary[256];
01272 
01273 while(TRUE)
01274     {
01275     if (isMime)
01276         {
01277         /* choose a new string for the boundary */
01278         /* Set initial seed */
01279         int i = 0;
01280         safef(boundary,sizeof(boundary),"%s", "---------");
01281         srand( (unsigned)time( NULL ) );
01282         for(i=strlen(boundary);i<41;++i)
01283             {
01284             int r = (int) 26 * (rand() / (RAND_MAX + 1.0));
01285             boundary[i] = r+'A';
01286             }
01287         boundary[i] = 0;
01288         }
01289 
01290     if (form == NULL)
01291         form = page->forms;
01292     if (buttonName != NULL && !isMime)
01293         appendCgiVar(dy, buttonName, buttonVal);
01294     for (var = form->vars; var != NULL; var = var->next)
01295         {
01296         if (sameWord(var->tagName, "SELECT") || 
01297             sameWord(var->tagName, "TEXTAREA") || 
01298             (var->type != NULL &&
01299             ((sameWord(var->type, "RADIO") || sameWord(var->type, "TEXTBOX")
01300             || sameWord(var->type, "PASSWORD") || sameWord(var->type, "HIDDEN")
01301             || sameWord(var->type, "TEXT") || sameWord(var->type, "FILE")))))
01302             {
01303             char *val = var->curVal;
01304             if (val == NULL)
01305                 val = "";
01306             if (isMime)
01307                 {
01308                 ++mimeParts;
01309                 appendMimeVar(dy, var->name, val, var->type, boundary);
01310                 }
01311             else            
01312                 appendCgiVar(dy, var->name, val);
01313             }
01314         else if (var->type != NULL && sameWord(var->type, "CHECKBOX"))
01315             {
01316             if (var->curVal != NULL)
01317                 {
01318                 if (isMime)         
01319                     {
01320                     ++mimeParts;
01321                     appendMimeVar(dy, var->name, var->curVal, var->type, boundary);
01322                     }
01323                 else        
01324                     appendCgiVar(dy, var->name, var->curVal);
01325                 }
01326             }
01327         else if (isMime && buttonName && sameWord(buttonName,var->name))
01328             {
01329             ++mimeParts;
01330             appendMimeVar(dy, buttonName, buttonVal, NULL, boundary);
01331             }
01332         }
01333     if (isMime) 
01334         {
01335         ++mimeParts;
01336         appendMimeTerminus(dy,boundary);
01337         if (countOccurrences(boundary,strlen(boundary),dy->string,dy->stringSize) != mimeParts)
01338             { /* boundary was found in input! # occurrences not as expected */
01339             dyStringClear(dy);
01340             continue;  /* if at first you don't succeed, try another boundary string */
01341             }
01342         dyStringPrintf(dyHeader, "Content-type: multipart/form-data, boundary=%s\r\n",boundary);
01343         if (isMime && verboseLevel() == 2)
01344             {
01345             mustWrite(stderr, dyHeader->string, dyHeader->stringSize);
01346             mustWrite(stderr, dy->string, dy->stringSize);
01347             }
01348         }
01349     break;
01350     }   
01351     
01352 return dyStringCannibalize(&dy);
01353 
01354 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlFormFree ( struct htmlForm **  pForm  ) 

Definition at line 201 of file htmlPage.c.

References freez(), htmlFormVarFreeList(), and htmlForm::vars.

Referenced by htmlFormFreeList().

00203 {
00204 struct htmlForm *form = *pForm;
00205 if (form != NULL)
00206     {
00207     htmlFormVarFreeList(&form->vars);
00208     freez(pForm);
00209     }
00210 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlFormFreeList ( struct htmlForm **  pList  ) 

Definition at line 212 of file htmlPage.c.

References htmlFormFree(), and htmlForm::next.

Referenced by htmlPageFree().

00214 {
00215 struct htmlForm *el, *next;
00216 
00217 for (el = *pList; el != NULL; el = next)
00218     {
00219     next = el->next;
00220     htmlFormFree(&el);
00221     }
00222 *pList = NULL;
00223 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlForm* htmlFormGet ( struct htmlPage page,
char *  name 
) [read]

Definition at line 986 of file htmlPage.c.

References htmlPage::forms, htmlForm::name, htmlForm::next, and sameWord.

00988 {
00989 struct htmlForm *form;
00990 for (form = page->forms; form != NULL; form = form->next)
00991     if (sameWord(form->name, name))
00992         break;
00993 return form;
00994 }

void htmlFormPrint ( struct htmlForm form,
FILE *  f 
)

Definition at line 977 of file htmlPage.c.

References htmlForm::action, htmlFormVarPrint(), htmlForm::method, htmlForm::name, htmlFormVar::next, and htmlForm::vars.

00979 {
00980 struct htmlFormVar *var;
00981 fprintf(f, "%s\t%s\t%s\n", form->name, form->method, form->action);
00982 for (var = form->vars; var != NULL; var = var->next)
00983     htmlFormVarPrint(var, f, "\t");
00984 }

Here is the call graph for this function:

void htmlFormVarFree ( struct htmlFormVar **  pVar  ) 

Definition at line 174 of file htmlPage.c.

References htmlFormVar::curVal, freeMem(), freez(), slFreeList(), htmlFormVar::tags, and htmlFormVar::values.

Referenced by htmlFormVarFreeList().

00176 {
00177 struct htmlFormVar *var = *pVar;
00178 if (var != NULL)
00179     {
00180     freeMem(var->curVal);
00181     slFreeList(&var->values);
00182     slFreeList(&var->tags);
00183     freez(pVar);
00184     }
00185 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlFormVarFreeList ( struct htmlFormVar **  pList  ) 

Definition at line 187 of file htmlPage.c.

References htmlFormVarFree(), and htmlFormVar::next.

Referenced by htmlFormFree().

00189 {
00190 struct htmlFormVar *el, *next;
00191 
00192 for (el = *pList; el != NULL; el = next)
00193     {
00194     next = el->next;
00195     htmlFormVarFree(&el);
00196     }
00197 *pList = NULL;
00198 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlFormVar* htmlFormVarGet ( struct htmlForm form,
char *  name 
) [read]

Definition at line 996 of file htmlPage.c.

References errAbort(), htmlFormVar::name, htmlFormVar::next, sameWord, and htmlForm::vars.

Referenced by htmlFormVarSet(), and htmlPageGetVar().

00998 {
00999 struct htmlFormVar *var;
01000 if (form == NULL)
01001     errAbort("Null form passed to htmlFormVarGet");
01002 for (var = form->vars; var != NULL; var = var->next)
01003     if (sameWord(var->name, name))
01004         break;
01005 return var;
01006 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlFormVarPrint ( struct htmlFormVar var,
FILE *  f,
char *  prefix 
)

Definition at line 966 of file htmlPage.c.

References htmlFormVar::curVal, naForNull(), htmlFormVar::name, slName::name, slName::next, htmlFormVar::tagName, htmlFormVar::type, and htmlFormVar::values.

Referenced by htmlFormPrint().

00968 {
00969 struct slName *val;
00970 fprintf(f, "%s%s\t%s\t%s\t%s\n", prefix, var->name, var->tagName, 
00971         naForNull(var->type), 
00972         naForNull(var->curVal));
00973 for (val = var->values; val != NULL; val = val->next)
00974      fprintf(f, "%s\t%s\n", prefix, val->name);
00975 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlFormVarSet ( struct htmlForm form,
char *  name,
char *  val 
)

Definition at line 1008 of file htmlPage.c.

References AllocVar, cloneString(), htmlFormVar::curVal, errAbort(), freez(), htmlFormVarGet(), slAddHead, and htmlForm::vars.

Referenced by htmlPageSetVar().

01010 {
01011 struct htmlFormVar *var;
01012 if (form == NULL)
01013     errAbort("Null form passed to htmlFormVarSet");
01014 var = htmlFormVarGet(form, name);
01015 if (var == NULL)
01016     {
01017     AllocVar(var);
01018     var->type = "TEXT";
01019     var->tagName = "INPUT";
01020     var->name = name;
01021     slAddHead(&form->vars, var);
01022     }
01023 freez(&var->curVal);
01024 var->curVal = cloneString(val);
01025 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlNextCrLfLine ( char **  pS  ) 

Definition at line 328 of file htmlPage.c.

References verbose().

Referenced by htmlHeaderRead().

00332 {
00333 char *s = *pS, *e;
00334 if (s == NULL || s[0] == 0)
00335     return NULL;
00336 e = strchr(s, '\n');
00337 if (e == NULL)
00338     verbose(1, "End of file in header\n");
00339 else 
00340     {
00341     *e = 0;
00342     if (e == s || e[-1] != '\r')
00343         verbose(1, "Missing <CR> in header line\n");
00344     else
00345        e[-1] = 0;
00346     e += 1;
00347     }
00348 *pS = e;
00349 return s;
00350 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlPageFormOrAbort ( struct htmlPage page  ) 

Definition at line 1755 of file htmlPage.c.

References errAbort(), and htmlPage::forms.

01757 {
01758 if (page == NULL)
01759     errAbort("Can't validate NULL page");
01760 if (page->forms == NULL)
01761     errAbort("No form found");
01762 }

Here is the call graph for this function:

struct htmlPage* htmlPageForwarded ( char *  url,
struct htmlCookie cookies 
) [read]

Definition at line 918 of file htmlPage.c.

References htmlPage::cookies, hashFindVal(), htmlPage::header, htmlPageFree(), and htmlPageGetWithCookies().

Referenced by htmlPageForwardedNoAbort().

00922 {
00923 struct htmlPage *page = htmlPageGetWithCookies(url, cookies);
00924 int level, maxLevels = 7;
00925 for (level = 0; level < maxLevels; ++level)
00926     {
00927     struct htmlPage *newPage;
00928     char *newUrl = hashFindVal(page->header, "Location:");
00929     if (newUrl == NULL)
00930         break;
00931     newPage = htmlPageGetWithCookies(newUrl, cookies);
00932     htmlPageFree(&page);
00933     page = newPage;
00934     }
00935 return page;
00936 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlPage* htmlPageForwardedNoAbort ( char *  url,
struct htmlCookie cookies 
) [read]

Definition at line 938 of file htmlPage.c.

References htmlPage::cookies, errCatchEnd(), errCatchFree(), errCatchNew(), errCatchStart, errCatch::gotError, htmlPageForwarded(), errCatch::message, dyString::string, and warn().

00940 {
00941 struct errCatch *errCatch = errCatchNew();
00942 struct htmlPage *page = NULL;
00943 if (errCatchStart(errCatch))
00944     page = htmlPageForwarded(url, cookies);
00945 errCatchEnd(errCatch);
00946 if (errCatch->gotError)
00947     warn(errCatch->message->string);
00948 errCatchFree(&errCatch);
00949 return page;
00950 }

Here is the call graph for this function:

void htmlPageFree ( struct htmlPage **  pPage  ) 

Definition at line 225 of file htmlPage.c.

References htmlPage::cookies, htmlPage::forms, freeHashAndVals(), freez(), htmlPage::fullText, htmlPage::header, htmlCookieFreeList(), htmlFormFreeList(), htmlStatusFree(), htmlTagFreeList(), htmlPage::status, htmlPage::tags, and htmlPage::url.

Referenced by htmlPageForwarded(), htmlPageFreeList(), qaPageFromForm(), qaPageGet(), and qaStatusOnPage().

00227 {
00228 struct htmlPage *page = *pPage;
00229 if (page != NULL)
00230     {
00231     freez(&page->url);
00232     htmlStatusFree(&page->status);
00233     freeHashAndVals(&page->header);
00234     htmlCookieFreeList(&page->cookies);
00235     freez(&page->fullText);
00236     htmlTagFreeList(&page->tags);
00237     htmlFormFreeList(&page->forms);
00238     freez(pPage);
00239     }
00240 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlPageFreeList ( struct htmlPage **  pList  ) 

Definition at line 242 of file htmlPage.c.

References htmlPageFree(), and htmlPage::next.

00244 {
00245 struct htmlPage *el, *next;
00246 
00247 for (el = *pList; el != NULL; el = next)
00248     {
00249     next = el->next;
00250     htmlPageFree(&el);
00251     }
00252 *pList = NULL;
00253 }

Here is the call graph for this function:

struct htmlPage* htmlPageFromForm ( struct htmlPage origPage,
struct htmlForm form,
char *  buttonName,
char *  buttonVal 
) [read]

Definition at line 1356 of file htmlPage.c.

References htmlForm::action, cookieOutput(), htmlPage::cookies, dyStringAppend(), dyStringCannibalize(), dyStringFree, dyStringNew, dyStringPrintf(), FALSE, freez(), htmlExpandUrl(), htmlFormCgiVars(), htmlPageParse(), htmlForm::method, netOpenHttpExt(), netSlurpFile(), sameWord, dyString::string, dyString::stringSize, htmlPage::url, and verbose().

Referenced by qaPageFromForm().

01360 {
01361 struct htmlPage *newPage = NULL;
01362 struct dyString *dyUrl = dyStringNew(0);
01363 struct dyString *dyHeader = dyStringNew(0);
01364 struct dyString *dyText = NULL;
01365 char *url = htmlExpandUrl(origPage->url, form->action);
01366 char *cgiVars = NULL;
01367 int contentLength = 0;
01368 int sd = -1;
01369 
01370 dyStringAppend(dyUrl, url);
01371 cookieOutput(dyHeader, origPage->cookies);
01372 if (sameWord(form->method, "GET"))
01373     {
01374     cgiVars = htmlFormCgiVars(origPage, form, buttonName, buttonVal, dyHeader);
01375     dyStringAppend(dyUrl, "?");
01376     dyStringAppend(dyUrl, cgiVars);
01377     verbose(3, "GET %s\n", dyUrl->string);
01378     sd = netOpenHttpExt(dyUrl->string, form->method, FALSE);
01379     dyStringAppend(dyHeader, "\r\n");
01380     write(sd, dyHeader->string, dyHeader->stringSize);
01381     }
01382 else if (sameWord(form->method, "POST"))
01383     {
01384     cgiVars = htmlFormCgiVars(origPage, form, buttonName, buttonVal, dyHeader);
01385     contentLength = strlen(cgiVars);
01386     verbose(3, "POST %s\n", dyUrl->string);
01387     sd = netOpenHttpExt(dyUrl->string, form->method, FALSE);
01388     dyStringPrintf(dyHeader, "Content-length: %d\r\n", contentLength);
01389     dyStringAppend(dyHeader, "\r\n");
01390     write(sd, dyHeader->string, dyHeader->stringSize);
01391     write(sd, cgiVars, contentLength);
01392     }
01393 dyText = netSlurpFile(sd);
01394 close(sd);
01395 newPage = htmlPageParse(url, dyStringCannibalize(&dyText));
01396 freez(&url);
01397 dyStringFree(&dyUrl);
01398 dyStringFree(&dyHeader);
01399 freez(&cgiVars);
01400 return newPage;
01401 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlPage* htmlPageGet ( char *  url  )  [read]

Definition at line 953 of file htmlPage.c.

References fileExists(), htmlPageGetWithCookies(), htmlPageParseNoHead(), and readInGulp().

Referenced by qaPageGet().

00955 {
00956 if (fileExists(url))
00957     {
00958     char *buf;
00959     readInGulp(url, &buf, NULL);
00960     return htmlPageParseNoHead(url, buf);
00961     }
00962 else
00963     return htmlPageGetWithCookies(url, NULL);
00964 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlFormVar* htmlPageGetVar ( struct htmlPage page,
struct htmlForm form,
char *  name 
) [read]

Definition at line 1028 of file htmlPage.c.

References htmlPage::forms, and htmlFormVarGet().

01030 {
01031 if (form == NULL)
01032     form = page->forms;
01033 return htmlFormVarGet(form, name);
01034 }

Here is the call graph for this function:

struct htmlPage* htmlPageGetWithCookies ( char *  url,
struct htmlCookie cookies 
) [read]

Definition at line 910 of file htmlPage.c.

References htmlPage::cookies, htmlPageParse(), and htmlSlurpWithCookies().

Referenced by htmlPageForwarded(), and htmlPageGet().

00913 {
00914 char *buf = htmlSlurpWithCookies(url, cookies);
00915 return htmlPageParse(url, buf);
00916 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct slName* htmlPageLinks ( struct htmlPage page  )  [read]

Definition at line 1430 of file htmlPage.c.

References htmlPageScanAttribute().

Referenced by validateCgiUrls().

01432 {
01433 return htmlPageScanAttribute(page, NULL, "HREF");
01434 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlPage* htmlPageParse ( char *  url,
char *  fullText 
) [read]

Definition at line 831 of file htmlPage.c.

References AllocVar, cloneLongString(), cloneString(), htmlPage::cookies, htmlPage::forms, freez(), htmlPage::fullText, hashAdd(), hashFindVal(), htmlPage::header, htmlHeaderRead(), htmlParseForms(), htmlStatusParse(), htmlTagScan(), htmlPage::htmlText, startsWith(), htmlStatus::status, htmlPage::status, htmlPage::tags, htmlPage::url, and warn().

Referenced by htmlPageFromForm(), htmlPageGetWithCookies(), and htmlPageParseOk().

00833 {
00834 struct htmlPage *page;
00835 char *dupe = cloneLongString(fullText);
00836 char *s = dupe;
00837 struct htmlStatus *status = htmlStatusParse(&s);
00838 char *contentType;
00839 
00840 if (status == NULL)
00841     return NULL;
00842 
00843 AllocVar(page);
00844 page->url = cloneString(url);
00845 page->fullText = fullText;
00846 page->status = status;
00847 page->header = htmlHeaderRead(&s, &page->cookies);
00848 contentType = hashFindVal(page->header, "Content-Type:");
00849 if (contentType == NULL)        
00850     {
00851     warn("No contentType, assuming text/html");
00852     contentType = cloneString("text/html");
00853     hashAdd(page->header, "Content-Type:", contentType);
00854     }
00855 page->htmlText = fullText + (s - dupe);
00856 if (startsWith("text/html", contentType))
00857     {
00858     page->tags = htmlTagScan(page->htmlText, s);
00859     page->forms = htmlParseForms(page, page->tags, NULL);
00860     }
00861 freez(&dupe);
00862 return page;
00863 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlPage* htmlPageParseNoHead ( char *  url,
char *  htmlText 
) [read]

Definition at line 865 of file htmlPage.c.

References AllocVar, cloneString(), htmlPage::forms, freez(), htmlPage::fullText, htmlParseForms(), htmlTagScan(), htmlPage::htmlText, htmlPage::tags, and htmlPage::url.

Referenced by htmlPageGet().

00867 {
00868 char *dupe = cloneString(htmlText);
00869 struct htmlPage *page;
00870 AllocVar(page);
00871 page->url = cloneString(url);
00872 page->fullText = page->htmlText = htmlText;
00873 page->tags = htmlTagScan(page->htmlText, dupe);
00874 page->forms = htmlParseForms(page, page->tags, NULL);
00875 freez(&dupe);
00876 return page;
00877 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct htmlPage* htmlPageParseOk ( char *  url,
char *  fullText 
) [read]

Definition at line 879 of file htmlPage.c.

References errAbort(), htmlPageParse(), noWarnAbort(), htmlPage::status, and htmlStatus::status.

00881 {
00882 struct htmlPage *page = htmlPageParse(url, fullText);
00883 if (page == NULL)
00884    noWarnAbort();
00885 if (page->status->status != 200)
00886    errAbort("%s returned with status code %d", url, page->status->status);
00887 return page;
00888 }

Here is the call graph for this function:

struct slName* htmlPageScanAttribute ( struct htmlPage page,
char *  tagName,
char *  attribute 
) [read]

Definition at line 1403 of file htmlPage.c.

References htmlTag::attributes, htmlTag::name, htmlAttribute::name, htmlTag::next, htmlAttribute::next, sameWord, slAddHead, slNameNew, slReverse(), htmlPage::tags, and htmlAttribute::val.

Referenced by htmlPageLinks().

01407 {
01408 struct htmlTag *tag;
01409 struct htmlAttribute *att;
01410 struct slName *list = NULL, *el;
01411 
01412 for (tag = page->tags; tag != NULL; tag = tag->next)
01413     {
01414     if (tagName == NULL || sameWord(tagName, tag->name))
01415         {
01416         for (att = tag->attributes; att != NULL; att = att->next)
01417             {
01418             if (sameWord(attribute, att->name))
01419                 {
01420                 el = slNameNew(att->val);
01421                 slAddHead(&list, el);
01422                 }
01423             }
01424         }
01425     }
01426 slReverse(&list);
01427 return list;
01428 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlPageSetVar ( struct htmlPage page,
struct htmlForm form,
char *  name,
char *  val 
)

Definition at line 1036 of file htmlPage.c.

References errAbort(), htmlPage::forms, and htmlFormVarSet().

01038 {
01039 if (page == NULL)
01040     errAbort("Null page passed to htmlPageSetVar");
01041 if (form == NULL)
01042     form = page->forms;
01043 if (form == NULL)
01044     errAbort("Null form in htmlPageSetVar");
01045 htmlFormVarSet(form, name, val);
01046 }

Here is the call graph for this function:

void htmlPageValidateOrAbort ( struct htmlPage page  ) 

Definition at line 1764 of file htmlPage.c.

References ArraySize, checkExactlyOne(), errAbort(), FALSE, hashFindVal(), htmlPage::header, htmlTag::name, htmlTag::next, sameWord, startsWith(), htmlPage::tags, touppers(), TRUE, validateBody(), validateCgiUrls(), validateNestingTags(), and warn().

Referenced by qaPageFromForm(), and qaPageGet().

01766 {
01767 struct htmlTag *tag;
01768 boolean gotTitle = FALSE;
01769 char *contentType = NULL;
01770 
01771 if (page == NULL)
01772     errAbort("Can't validate NULL page");
01773 if (page->header != NULL)
01774     contentType = hashFindVal(page->header, "Content-Type:");
01775 if (contentType == NULL || startsWith("text/html", contentType))
01776     {
01777     /* To simplify things upper case all tag names. */
01778     for (tag = page->tags; tag != NULL; tag = tag->next)
01779         touppers(tag->name);
01780 
01781     checkExactlyOne(page->tags, "BODY");
01782 
01783     /* Validate header, and make a suggestion or two */
01784     if ((tag = page->tags) == NULL)
01785         errAbort("No tags");
01786     if (!sameWord(tag->name, "HTML"))
01787         errAbort("Doesn't start with <HTML> tag");
01788     tag = tag->next;
01789     if (tag == NULL || !sameWord(tag->name, "HEAD"))
01790         warn("<HEAD> tag does not follow <HTML> tag");
01791     else
01792         {
01793         for (;;)
01794             {
01795             tag = tag->next;
01796             if (tag == NULL)
01797                 errAbort("Missing </HEAD>");
01798             if (sameWord(tag->name, "TITLE"))
01799                 gotTitle = TRUE;
01800             if (sameWord(tag->name, "/HEAD"))
01801                 break;
01802             }
01803         if (!gotTitle)
01804             warn("No title in <HEAD>");
01805         validateNestingTags(page, page->tags, tag, headNesters, ArraySize(headNesters));
01806         tag = tag->next;
01807         }
01808     if (tag == NULL || !sameWord(tag->name, "BODY"))
01809         errAbort("<BODY> tag does not follow <HTML> tag");
01810     tag = validateBody(page, tag->next);
01811     if (tag == NULL || !sameWord(tag->name, "/HTML"))
01812         errAbort("Missing </HTML>");
01813     validateCgiUrls(page);
01814     }
01815 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlSlurpWithCookies ( char *  url,
struct htmlCookie cookies 
)

Definition at line 890 of file htmlPage.c.

References cookieOutput(), dyStringAppend(), dyStringCannibalize(), dyStringFree, dyStringNew, FALSE, netOpenHttpExt(), netSlurpFile(), dyString::string, and dyString::stringSize.

Referenced by htmlPageGetWithCookies().

00895 {
00896 struct dyString *dyHeader = dyStringNew(0);
00897 struct dyString *dyText;
00898 int sd;
00899 
00900 cookieOutput(dyHeader, cookies);
00901 dyStringAppend(dyHeader, "\r\n");
00902 sd = netOpenHttpExt(url, "GET", FALSE);
00903 write(sd, dyHeader->string, dyHeader->stringSize);
00904 dyText = netSlurpFile(sd);
00905 close(sd);
00906 dyStringFree(&dyHeader);
00907 return dyStringCannibalize(&dyText);
00908 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlStatusFree ( struct htmlStatus **  pStatus  ) 

Definition at line 28 of file htmlPage.c.

References freeMem(), freez(), and htmlStatus::status.

Referenced by htmlPageFree(), and htmlStatusFreeList().

00030 {
00031 struct htmlStatus *status = *pStatus;
00032 if (status != NULL)
00033     {
00034     freeMem(status->version);
00035     freez(pStatus);
00036     }
00037 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlStatusFreeList ( struct htmlStatus **  pList  ) 

Definition at line 39 of file htmlPage.c.

References htmlStatusFree(), and htmlStatus::next.

00041 {
00042 struct htmlStatus *el, *next;
00043 
00044 for (el = *pList; el != NULL; el = next)
00045     {
00046     next = el->next;
00047     htmlStatusFree(&el);
00048     }
00049 *pList = NULL;
00050 }

Here is the call graph for this function:

struct htmlStatus* htmlStatusParse ( char **  pText  )  [read]

Definition at line 299 of file htmlPage.c.

References AllocVar, cloneStringZ(), skipLeadingSpaces(), skipToSpaces(), htmlStatus::status, and warn().

Referenced by htmlPageParse().

00302 {
00303 char *text = *pText;
00304 char *end = strchr(text, '\n');
00305 struct htmlStatus *status;
00306 if (end != NULL)
00307    *pText = end+1;
00308 else
00309    *pText = text + strlen(text);
00310 end = skipToSpaces(text);
00311 if (end == NULL)
00312     {
00313     warn("Short status line.");
00314     return NULL;
00315     }
00316 AllocVar(status);
00317 status->version = cloneStringZ(text, end-text);
00318 end = skipLeadingSpaces(end);
00319 if (!isdigit(end[0]))
00320     {
00321     warn("Not a number in status field");
00322     return NULL;
00323     }
00324 status->status = atoi(end);
00325 return status;
00326 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlTagAttributeNeeded ( struct htmlPage page,
struct htmlTag tag,
char *  name 
)

Definition at line 465 of file htmlPage.c.

References htmlTagAttributeVal(), tagWarn(), and htmlAttribute::val.

Referenced by formParseVars(), and htmlParseForms().

00468 {
00469 char *val = htmlTagAttributeVal(page, tag, name, NULL);
00470 if (val == NULL)
00471     {
00472     tagWarn(page, tag, "Missing %s attribute", name);
00473     val = "n/a";
00474     }
00475 return val;
00476 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* htmlTagAttributeVal ( struct htmlPage page,
struct htmlTag tag,
char *  name,
char *  defaultVal 
)

Definition at line 455 of file htmlPage.c.

References htmlTag::attributes, htmlAttributeFindVal(), and htmlAttribute::val.

Referenced by formParseVars(), htmlParseForms(), and htmlTagAttributeNeeded().

00458 {
00459 char *val = htmlAttributeFindVal(tag->attributes, name);
00460 if (val == NULL)
00461     val = defaultVal;
00462 return val;
00463 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlTagFree ( struct htmlTag **  pTag  ) 

Definition at line 149 of file htmlPage.c.

References htmlTag::attributes, freeMem(), freez(), htmlAttributeFreeList(), and htmlTag::name.

Referenced by htmlTagFreeList().

00151 {
00152 struct htmlTag *tag = *pTag;
00153 if (tag != NULL)
00154     {
00155     htmlAttributeFreeList(&tag->attributes);
00156     freeMem(tag->name);
00157     freez(pTag);
00158     }
00159 }

Here is the call graph for this function:

Here is the caller graph for this function:

void htmlTagFreeList ( struct htmlTag **  pList  ) 

Definition at line 161 of file htmlPage.c.

References htmlTagFree(), and htmlTag::next.

Referenced by htmlPageFree().

00163 {
00164 struct htmlTag *el, *next;
00165 
00166 for (el = *pList; el != NULL; el = next)
00167     {
00168     next = el->next;
00169     htmlTagFree(&el);
00170     }
00171 *pList = NULL;
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Tue Dec 25 19:01:50 2007 for blat by  doxygen 1.5.2