Exemplo n.º 1
0
/* Search down given translated URL searching for actual file name and filling
 * in path_info string.  Doesn't make any claims about file type, must be 
 * handled elsewhere.
 * Returns 0 on success, errno on failure
 */
int extract_path_info(per_request *reqInfo, struct stat *finfo)
  {
    register int x,max;
    char *str;
    int l,u;

    str = newString(HUGE_STRING_LEN,STR_TMP);

    max=count_dirs(reqInfo->filename);
    for(x=max ; x > 0 ; x--) {
        make_dirstr(reqInfo->filename,x+1,str);
	l=strlen(str);
	u=strlen(reqInfo->url);
        if(!(stat(str,finfo)) &&
	    !strcmp(reqInfo->filename+l, reqInfo->url+u-strlen(reqInfo->filename+ l))) 
	{
	  strcat(reqInfo->path_info,&(reqInfo->filename[l]));
	  reqInfo->filename[l] = '\0';
	  reqInfo->url[strlen(reqInfo->url) - strlen(reqInfo->path_info)]='\0';
	  freeString(str);
	  return 0;
        }
    }
    freeString(str);
    return errno;
}
Exemplo n.º 2
0
/*
 * addInputParser :: Parser -> Cstr -> ()
 *
 * Add additional input to the parser input chain.
 */
const char* addInputParser(Parser *p, const char *input) {
  String *inputStr = mkString(input);
  if (! inputStr) return NULL;

  InputChain *link = kmalloc(sizeof *link);
  if (! link) goto fail;

  link->input = inputStr;
  link->next = NULL;

  if (p->last) {
    p->last->next = link;
  } else {
    p->inputChain = link;
    p->input = fromString(link->input);
  }

  p->last = link;

exit:
  return fromString(inputStr);

fail:
  freeString(inputStr);
  goto exit;
}
Exemplo n.º 3
0
static bool testCachePush() {
	//strings
	char * toFirstCell = "";
	char * ramones = "Ramones";
	char toLastCell[] = {(char)254, '\0'};
	char outOfRange[] = {(char)255, '\0'};

	Cache cache = cacheCreate(255, freeString, copyString, compareStrings, getFirstLetter);
	ASSERT_TEST(cache != NULL);

	ASSERT_TEST(cachePush(NULL, toFirstCell) == CACHE_NULL_ARGUMENT);
	ASSERT_TEST(cachePush(cache, NULL) == CACHE_NULL_ARGUMENT);
	ASSERT_TEST(cachePush(cache, toFirstCell) == CACHE_SUCCESS);
	ASSERT_TEST(cacheIsIn(cache, toFirstCell));
	ASSERT_TEST(cacheIsIn(cache, toFirstCell));
	ASSERT_TEST(cachePush(cache, ramones) == CACHE_SUCCESS);
	ASSERT_TEST(cacheIsIn(cache, ramones));
	ASSERT_TEST(cachePush(cache, toLastCell) == CACHE_SUCCESS);
	ASSERT_TEST(cacheIsIn(cache, toLastCell));
	ASSERT_TEST(cachePush(cache, outOfRange) == CACHE_OUT_OF_RANGE);
	ASSERT_TEST(!cacheIsIn(cache, outOfRange));
	ASSERT_TEST(cachePush(cache, ramones) == CACHE_ITEM_ALREADY_EXISTS);
	ASSERT_TEST(cachePush(cache, toFirstCell) == CACHE_ITEM_ALREADY_EXISTS);
	ASSERT_TEST(cachePush(cache, toLastCell) == CACHE_ITEM_ALREADY_EXISTS);
	ASSERT_TEST(cachePush(cache, outOfRange) == CACHE_OUT_OF_RANGE);

	char * toFirstCellCopy = cacheExtractElementByKey(cache, getFirstLetter(toFirstCell));
	char * ramonesCopy = cacheExtractElementByKey(cache, getFirstLetter(ramones));
	char * toLastCellCopy = cacheExtractElementByKey(cache, getFirstLetter(toLastCell));
	char * outOfRangeCopy = cacheExtractElementByKey(cache, getFirstLetter(outOfRange));

	ASSERT_TEST(!strcmp(toFirstCell, toFirstCellCopy));
	ASSERT_TEST(!strcmp(ramones, ramonesCopy));
	ASSERT_TEST(!strcmp(toLastCell, toLastCellCopy));
	ASSERT_TEST(outOfRangeCopy == NULL);

	ASSERT_TEST(cacheExtractElementByKey(cache, getFirstLetter(toFirstCell)) == NULL);
	ASSERT_TEST(cacheExtractElementByKey(cache, getFirstLetter(ramones)) == NULL);
	ASSERT_TEST(cacheExtractElementByKey(cache, getFirstLetter(toLastCell)) == NULL);

	freeString(toFirstCellCopy);
	freeString(ramonesCopy);
	freeString(toLastCellCopy);
	cacheDestroy(cache);

	return true;
}
Exemplo n.º 4
0
/**
 * Closes the stream and reclaims any resources used by the stream.
 * The stream object will be freed, so the client must not access it again.
 * @returns NULL in all cases.
 */
extern struct ccn_fetch_stream *
ccn_fetch_close(struct ccn_fetch_stream *fs) {
	// destroys a ccn_fetch_stream object
	// implicit abort of any outstanding fetches
	// always returns NULL
	int i;
    FILE *debug = fs->parent->debug;
	ccn_fetch_flags flags = fs->parent->debugFlags;
    
	// make orphans of all outstanding requests
	// CallMe should handle the cleanup
	struct localClosure * this = fs->requests;
	fs->requests = NULL;
	while (this != NULL) {
		this->fs = NULL;
		this = this->next;
	}
	// free up the buffers
	fs->maxBufs = 0;
	PruneSegments(fs);
	
	if (fs->name != NULL)
		ccn_charbuf_destroy(&fs->name);
	if (fs->interest != NULL)
		ccn_charbuf_destroy(&fs->interest);
	struct ccn_fetch *f = fs->parent;
	if (f != NULL) {
		int ns = f->nStreams;
		fs->parent = NULL;
		for (i = 0; i < ns; i++) {
			struct ccn_fetch_stream *tfs = f->streams[i];
			if (tfs == fs) {
				// found it, so get rid of it
				ns--;
				f->nStreams = ns;
				f->streams[i] = NULL;
				f->streams[i] = f->streams[ns];
				f->streams[ns] = NULL;	
				break;	
			}
		}
	}
	if (debug != NULL && (flags & ccn_fetch_flags_NoteOpenClose)) {
		fprintf(debug, 
				"-- ccn_fetch close, %s, segReq %jd, segsRead %jd, timeouts %jd\n",
				fs->id,
				fs->segsRequested,
				fs->segsRead,
				fs->timeoutsSeen);
		fflush(debug);
	}
	// finally, get rid of the stream object
	freeString(fs->id);
	free(fs);
	return NULL;
}
Exemplo n.º 5
0
/* send_fp(): sends a file pointer to the socket.  Uses fread to read,
 * but uses non-buffered I/O for writes (write())
 *
 * We'll make it return the number of bytes sent
 * so that we know if we need to send a body by default
 */
long send_fp(per_request *reqInfo, FILE *f, void (*onexit)(void))
{
    char *buf;
    long total_bytes_sent;
    register int n,o,w;
    /* ADC hack ZZZZ */
    /* blong Unused? */
    /* int i; */

    buf = newString(IOBUFSIZE,STR_TMP);
    exit_callback = onexit;
    signal(SIGALRM,send_fd_timed_out);
    signal(SIGPIPE,send_fd_timed_out);

    total_bytes_sent = 0;
    rflush(reqInfo);
    while (1) {
        alarm(timeout);
        if((n=fread(buf,sizeof(char),IOBUFSIZE,f)) < 1) {
	   if (errno != EINTR) break;
	    else errno = 0;
        }

        o=0;
        if(reqInfo->bytes_sent != -1)
            reqInfo->bytes_sent += n;
        while(n) {
/*   Seems some systems have broken fwrite's (like AIX 3.2.5 on PowerPC)
 *   this should be a drop in replacement, maybe even be faster.
 *   For now, we'll just replace, but may have to #define one or the other
 *   depending on the system.
 */
              w = write(fileno(reqInfo->out),&buf[o],n);
	    if (w < 0) {
	      if (errno != EINTR) break;
		else errno = 0;
	    }
				/* there goes ADC again...  ZZZZ */
/*
for (i = 0; i<w; i++) 
   fputc(buf[o+i],stderr);
fflush(stderr);
*/

            n-=w;
            o+=w;
	    total_bytes_sent += w;
        }
    }
    alarm(0);
    signal(SIGALRM,SIG_IGN);
    signal(SIGPIPE,SIG_IGN);
    freeString(buf);
    return total_bytes_sent;
}
Exemplo n.º 6
0
/*
  We'll make it return the number of bytes sent
  so that we know if we need to send a body by default
*/
long send_fp_black(per_request *reqInfo, FILE *f, void (*onexit)(void))
{
    char *buf;
    long total_bytes_sent;
    register int n,o,w;
    int isHTML = FALSE;

    buf = newString(IOBUFSIZE,STR_TMP);
    exit_callback = onexit;
    signal(SIGALRM,send_fd_timed_out);
    signal(SIGPIPE,send_fd_timed_out);

    total_bytes_sent = 0;
    if (!strcmp(reqInfo->outh_content_type,"text/html")) {
      isHTML = TRUE;
      total_bytes_sent = rprintf(reqInfo,bodyTag);
    }
    rflush(reqInfo);
    while (1) {
        alarm(timeout);
        if((n=fread(buf,sizeof(char),IOBUFSIZE,f)) < 1) {
	   if (errno != EINTR) break;
        }

        o=0;
        if(reqInfo->bytes_sent != -1)
            reqInfo->bytes_sent += n;
        if (isHTML) {
	    sendBody(reqInfo,buf,n);
	    total_bytes_sent += n;
	    n = 0;
          }
        while(n) {
/*   Seems some systems have broken fwrite's (like AIX 3.2.5 on PowerPC)
 *   this should be a drop in replacement, maybe even be faster.
 *   For now, we'll just replace, but may have to #define one or the other
 *   depending on the system.
 */
	    if ((w=write(fileno(reqInfo->out),&buf[o],n)) < 0) {
	      if (errno != EINTR) break;
	    }
            n-=w;
            o+=w;
	    total_bytes_sent += w;
        }

    }
    if (isHTML) 
    rprintf(reqInfo,"<HR><a href=\"http://www.vtw.org/speech/\">My World Wide Web Pages are black for 48 hours to protest second-class treatment from the US Government for free speech.  Read about it at this WWW page.</a>");
    alarm(0);
    signal(SIGALRM,SIG_IGN);
    signal(SIGPIPE,SIG_IGN);
    freeString(buf);
    return total_bytes_sent;
}
Exemplo n.º 7
0
void appendString( char **aString, char *aAddString )
{
	char *string;

	if( *aString == NULL ) {
		*aString = duplicateString( aAddString );
	} else {
		string = concatenateStrings( *aString, aAddString );
		freeString( aString );
		*aString = string;
	}
}
Exemplo n.º 8
0
PbVariant& PbVariant::operator = (PbVariant&& v) {
  if(this == &v)
    return *this;
  if(type == vt_string) {
    freeString();
  }
  if(v.type == vt_string) {
    value.v_string = v.value.v_string;
    v.value.v_string = NULL;
  } else {
    value.v_uint64 = v.value.v_uint64;
  }
  type = v.type;
  return *this;
};
Exemplo n.º 9
0
PbVariant& PbVariant::operator = (const PbVariant& v) {
  if(this == &v)
    return *this;
  if(type == vt_string) {
    freeString();
  }
  if(v.type == vt_string) {
    value.v_string = new std::string(*(v.value.v_string));
  } else {
    value.v_uint64 = v.value.v_uint64;
  }

  type = v.type;
  return *this;
};
Exemplo n.º 10
0
int			func_key_up(t_edit_line *line)
{
  freeString(line->output_string);
  if (modular_history(0, NULL)->prev == NULL)
    {
      line->output_string = formString(modular_history(0, NULL)->cmd);
      modular_history(1, modular_history(0, NULL)->prev);
    }
  else
    {
      modular_history(1, modular_history(0, NULL)->prev);
      line->output_string = formString(modular_history(0, NULL)->cmd);
    }
  return (0);
}
Exemplo n.º 11
0
int			func_key_down(t_edit_line *line)
{
  if (modular_history(0, NULL) != NULL)
    {
      freeString(line->output_string);
            if (modular_history(0, NULL)->next == NULL)
	{
	  line->output_string = formString(modular_history(0, NULL)->cmd);
	  modular_history(1, modular_history(0, NULL)->next);
	}
      else
	{
	  modular_history(1, modular_history(0, NULL)->next);
	  line->output_string = formString(modular_history(0, NULL)->cmd);
	}
    }
  return (0);
}
Exemplo n.º 12
0
char * buildMd5Key(const char* string){
    unsigned char ss[30];
    char *s  = allocString(string);
    char *buf = allocMem(MD5_KEY_SIZE);
    memset(buf,'\0',MD5_KEY_SIZE);
    struct MD5Context md5c;
    MD5Init( &md5c );
    MD5Update( &md5c, s, strlen(s) );
    MD5Final( ss, &md5c );
    char tmp[3]={'\0'};
    freeString(&s);
    int i =0;
    for( i=0; i<16; i++ ){
        sprintf(tmp,"%02X", ss[i] );
        strcat(buf,tmp);
    }
    buf[MD5_KEY_SIZE-1]='\0';
    return buf;
}
  void
freeOperand(operandType *operand)
{
	nullFree(operand);
	switch (operand->kindOfOperand) {

	case EXPRESSION_OPND:
	case IMMEDIATE_OPND:
	case INDIRECT_OPND:
	case POST_INDEXED_Y_OPND:
	case PRE_INDEXED_X_OPND:
	case X_INDEXED_OPND:
	case Y_INDEXED_OPND:
		freeExpression(operand->theOperand.expressionUnion);
		break;

	case A_REGISTER_OPND:
	case X_REGISTER_OPND:
	case Y_REGISTER_OPND:
		break;

	case X_SELECTED_OPND:
	case Y_SELECTED_OPND:
	case PRE_SELECTED_X_OPND:
		freeSelectionList(operand->theOperand.xSelectedUnion);
		break;

	case STRING_OPND:
		freeString(operand->theOperand.stringUnion);
		break;

	case BLOCK_OPND:
		freeBlock(operand->theOperand.blockUnion);
		break;

	default:
		botch("bad operand kind in freeOperand %d\n",
						operand->kindOfOperand);
		break;
	}
	freeOperand(operand->nextOperand);
	free(operand);
}
Exemplo n.º 14
0
int main(int argc, char ** argv)
{
  if (argc < 4)
    {
      printf("need four file names: type, input, output");
      return EXIT_FAILURE;
    }
  if (strcmp(argv[1], "i") == 0) /* sort integers */
    {
      int numInteger = 0;
      int * arrInteger = NULL;
      arrInteger = readInteger(argv[2], & numInteger);
      if (numInteger == 0)
	{
	  return EXIT_FAILURE;
	}
      printInteger(arrInteger, numInteger);
      sortInteger(arrInteger, numInteger);
      printInteger(arrInteger, numInteger);
      saveInteger(argv[3], arrInteger, numInteger);
      freeInteger(arrInteger, numInteger);
      return EXIT_SUCCESS;
    }
  if (strcmp(argv[1], "s") == 0) /* sort strings */
    {
      int numString = 0;
      char * * arrString = NULL;
      arrString = readString(argv[2], & numString);
      if (numString == 0)
	{
	  return EXIT_FAILURE;
	}
      printString(arrString, numString);
      sortString(arrString, numString);
      printString(arrString, numString);
      saveString(argv[3], arrString, numString);
      freeString(arrString, numString);
      return EXIT_SUCCESS;
    }
  /* unknown type */
  return EXIT_FAILURE;
}
Exemplo n.º 15
0
Arquivo: Person.c Projeto: syzhou/p1
/* Destroy a Person object
This is the only function that frees the memory for a Person
and the contained data. */
void destroy_Person(struct Person* person_ptr) {
	freeString(person_ptr->firstname);
	freeString(person_ptr->lastname);
	freeString(person_ptr->phoneno);
	free(person_ptr);
}
Exemplo n.º 16
0
void freeParseToken(ParseToken *tok) {
  freeString(tok->token);
  tok->next = NULL;
  kfree(tok);
}
Exemplo n.º 17
0
/**
 * Creates a stream for a named interest.
 * The name should be a ccnb encoded interest.
 * If resolveVersion, then we assume that the version is unresolved, 
 * and an attempt is made to determine the version number using the highest
 * version.
 * The number of buffers (nBufs) may be silently limited.
 * @returns NULL if the stream creation failed,
 * otherwise returns the new stream.
 */
extern struct ccn_fetch_stream *
ccn_fetch_open(struct ccn_fetch *f,
			   struct ccn_charbuf *name,
			   const char *id,
			   struct ccn_charbuf *interestTemplate,
			   int maxBufs,
			   int resolveVersion,
			   int assumeFixed) {
	// returns a new ccn_fetch_stream object based on the arguments
	// returns NULL if not successful
    if (maxBufs <= 0) return NULL;
	if (maxBufs > 16) maxBufs = 16;
	int res = 0;
	FILE *debug = f->debug;
	ccn_fetch_flags flags = f->debugFlags;
    
	// first, resolve the version
	struct ccn_fetch_stream *fs = calloc(1, sizeof(*fs));
	fs->segSize = (assumeFixed ? 0 : -1);
	fs->name = ccn_charbuf_create();
	fs->id = newStringCopy(id);
	ccn_charbuf_append_charbuf(fs->name, name);
	if (resolveVersion) {
		int tmInc = 40; // TBD: need better strategy for version timeout
		int tm = 0;
		while (tm < CCN_VERSION_TIMEOUT) {
			res = ccn_resolve_version(f->h, fs->name, resolveVersion, tmInc);
			if (res >= 0) break;
			tm = tm + tmInc;
		}
		if (res < 0) {
			// could not resolve version for this name
			// get rid of allocations so far and bail out
			if (debug != NULL && (flags & ccn_fetch_flags_NoteOpenClose)) {
				fprintf(debug, 
						"-- ccn_fetch open, %s, failed to resolve version\n",
						fs->id);
				fflush(debug);
			}
			ccn_charbuf_destroy(&fs->name);
			freeString(fs->id);
			free(fs);
			return NULL;
		}
	}
	fs->maxBufs = maxBufs;
	fs->segsAhead = 0;
	fs->fileSize = -1;
	fs->finalSeg = -1;
	fs->timeoutSeg = -1;
	fs->zeroLenSeg = -1;
	fs->parent = f;
	fs->timeoutUSecs = CCN_INTEREST_TIMEOUT_USECS;  // TBD: how to get better timeout?
	
	// use the supplied template or the default
	if (interestTemplate != NULL) {
		struct ccn_charbuf *cb = ccn_charbuf_create();
		ccn_charbuf_append_charbuf(cb, interestTemplate);
		fs->interest = cb;
	} else
		fs->interest = make_data_template(MaxSuffixDefault);
	
	
	// remember the stream in the parent
	int ns = f->nStreams;
	int max = f->maxStreams;
	if (ns >= max) {
		// extend the vector
		int nMax = max+max/2+4;
        f->streams = realloc(f->streams, sizeof(*(f->streams)) * nMax);
		f->maxStreams = nMax;
	}
	// guaranteed room to add at the end
	f->streams[ns] = fs;
	f->nStreams = ns+1;
	
	if (debug != NULL && (flags & ccn_fetch_flags_NoteOpenClose)) {
		fprintf(debug, 
				"-- ccn_fetch open, %s\n",
				fs->id);
		fflush(debug);
	}
	// prep for the first segment
	NeedSegment(fs, 0);
	return fs;
}
Exemplo n.º 18
0
PbVariant::~PbVariant(){
  freeString();
};
Exemplo n.º 19
0
/* NCSA Imagemap files use: method URL coord1 coord2
 * CERN Imagemap files use: method (coord1) (coord2) URL
 * This version of imagemap will probably work with either in the same file,
 * as long as a full line is in one format or the other.
 */
int send_imagemap(per_request* reqInfo, struct stat* fi, char allow_options)
{
    char *input, *def, *szPoint, *url, *type;
    double testpoint[2], pointarray[MAXVERTS][2];
    int i, j, k;
    int error_num = 0;
    FILE *fp;
    char *t;
    double dist, mindist = -1;
    int sawpoint = 0;
    int sawparen = 0;
    int Found = 0;

    
    input = newString(HUGE_STRING_LEN,STR_TMP);
    def = newString(MAX_STRING_LEN,STR_TMP);
    szPoint = newString(MAX_STRING_LEN,STR_TMP);
    type = newString(MAX_STRING_LEN,STR_TMP);
    url = newString(MAX_STRING_LEN,STR_TMP);

    def[0] = '\0';
    strcpy(szPoint, reqInfo->args);

    if(!(t = strchr(szPoint,','))) {
        error_num = IMAP_ERR_INCORRECT_ARGS;
	goto imagemap_error;
    }

    *t++ = '\0';
    testpoint[X] = (double) atoi(szPoint);
    testpoint[Y] = (double) atoi(t);

    if(!(fp=FOpen(reqInfo->filename,"r"))){
	log_reason(reqInfo, "File permissions deny server access",
		   reqInfo->filename);
        freeString(input);
        freeString(def);
        freeString(szPoint);
        freeString(url);
        freeString(type);
	die(reqInfo, SC_FORBIDDEN, reqInfo->url);
    }

    while (!Found && fgets(input,HUGE_STRING_LEN,fp)) {
        char num[10];

        /* Skip lines with # as comments and blank lines */
        if((input[0] == '#') || (!input[0]))
            continue;

        type[0] = '\0';url[0] = '\0';

        /* Copy the shape keyword into type */
        for(i=0;!isspace(input[i]) && (input[i]);i++)
            type[i] = input[i];
        type[i] = '\0';

        /* Forward to next word */
        while(isspace(input[i])) ++i;

        /* If no coordinates, must be url for default, or NCSA format  */
	if (input[i] != '(') {
          for(j=0;input[i] && !isspace(input[i]);++i,++j)
            url[j] = input[i];
          url[j] = '\0';
        }

	/* Handle default keyword */
        if(!strcmp(type,"default") && !sawpoint) {
            strcpy(def,url);
            continue;
        }

        /* Looking for Coordinates */
        k=0;
        while (input[i]) {
	    /* Move over spaces and commas */
            while (isspace(input[i]) || input[i] == ',')
                i++;
	    
	    /* Under CERN, coordinates are in parenthesis */
            if (input[i] == '(') {
                sawparen = 1;
                while (isspace(input[++i]));
            }

            /* Copy digits into num array */
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];

            num[j] = '\0';
            if (!j) break;
            pointarray[k][X] = (double) atoi(num);

            /* Skip to next digit */
            while (isspace(input[i]) || input[i] == ',')
                i++;
            /* Copy other number into num */
            j = 0;
            while (isdigit(input[i]))
                num[j++] = input[i++];
            num[j] = '\0';

            if (!j && !sawparen && k > 0) {
              pointarray[k++][Y] = -127;
              break;
            }
  
            if (j)
                pointarray[k++][Y] = (double) atoi(num);
            else {
		error_num = IMAP_ERR_INCORRECT_COORDS;
	        FClose(fp);
		goto imagemap_error;
            }
            
            /* End of parenthesis for coordinates under CERN */
            if (input[i] == ')') {
	      i++;
	      sawparen = 0;
	    } else if (sawparen) {
	      error_num = IMAP_ERR_CERN_MISSING_RIGHT_PAREN;
              FClose(fp);
              goto imagemap_error;	
	    }
        }
        if (url[0] == '\0' && input[i]) {
          while (isspace(input[i])) i++;
          for (j = 0; input[i] && !isspace(input[i]); ++i, ++j)
             url[j] = input[i];
          url[j] = '\0';
        }
        pointarray[k][X] = -1;
        if(!strncmp(type, "poly", 4))
            if(pointinpoly(testpoint,pointarray))
	       Found = 1;
        if(!strncmp(type, "circ", 4))
            if(pointincircle(testpoint,pointarray))
	      Found = 1;
        if(!strncmp(type, "rect", 4))
            if(pointinrect(testpoint,pointarray))
	      Found = 1;
        if(!strcmp(type,"point")) {
	    /* Don't need to take square root. */
	    dist = ((testpoint[X] - pointarray[0][X])
		    * (testpoint[X] - pointarray[0][X]))
		   + ((testpoint[Y] - pointarray[0][Y])
		      * (testpoint[Y] - pointarray[0][Y]));
	    /* If this is the first point, or the nearest, set the default. */
	    if ((! sawpoint) || (dist < mindist)) {
		mindist = dist;
	        strcpy(def,url);
	    }
	    sawpoint++;
	}
    }
    if(Found) {
      sendmesg(reqInfo, url, fp);
      goto imagemap_ok;
    } else {
      if(def[0]) {
        sendmesg(reqInfo, def, fp);
	goto imagemap_ok;
      }
    }
/* No reason to log each of these as an "error" */
/*    log_reason(reqInfo, "No default defined in imagemap.",
	       reqInfo->filename); */
    FClose(fp);
    freeString(input);
    freeString(def);
    freeString(szPoint);
    freeString(url);
    freeString(type);
    die(reqInfo, SC_NO_CONTENT, reqInfo->url);
    return 0;
 
 imagemap_ok:
    FClose(fp);
    freeString(input);
    freeString(def);
    freeString(szPoint);
    freeString(url);
    freeString(type);
    return 1;
 
 imagemap_error:
   freeString(input);
   freeString(def);
   freeString(szPoint);
   freeString(url);
   freeString(type);
   log_reason(reqInfo,imagemap_errors[error_num-1],reqInfo->filename);
   die(reqInfo,SC_BAD_IMAGEMAP,imagemap_errors[error_num-1]);
   return -1;
}
Exemplo n.º 20
0
void send_file(per_request *reqInfo, struct stat *fi, char allow_options) 
{
    FILE *f;
#ifdef BLACKOUT_CODE
    int isblack = FALSE;
#endif /* BLACKOUT_CODE */    

    if ((reqInfo->method != M_GET) && (reqInfo->method != M_HEAD)) {
	sprintf(error_msg,"%s to non-script",methods[reqInfo->method]);
	die(reqInfo,SC_NOT_IMPLEMENTED,error_msg);
    }
    set_content_type(reqInfo,reqInfo->filename);

    if((allow_options & OPT_INCLUDES) && (!reqInfo->outh_content_encoding[0])) {
#ifdef XBITHACK
        if((fi->st_mode & S_IXUSR) ||
           (!strcmp(reqInfo->outh_content_type,INCLUDES_MAGIC_TYPE))) {
#else
	if(!strcmp(reqInfo->outh_content_type,INCLUDES_MAGIC_TYPE)) {
#endif /* XBITHACK */
	    reqInfo->bytes_sent = 0;
	    send_parsed_file(reqInfo, allow_options & OPT_INCNOEXEC);
	    log_transaction(reqInfo);
	    return;
	}
    }
    if (reqInfo->path_info[0]) {
	strcat(reqInfo->filename,reqInfo->path_info);
	strcat(reqInfo->url,reqInfo->path_info);
	sprintf(error_msg,"No file matching URL: %s",reqInfo->url);
	log_reason(reqInfo, error_msg, reqInfo->filename);
	die(reqInfo,SC_NOT_FOUND,reqInfo->url);
    }
	
    if(!(f=FOpen(reqInfo->filename,"r"))) {
      if (errno == EACCES) {
	log_reason(reqInfo,"(1) file permissions deny server access",
		   reqInfo->filename);
	/* we've already established that it exists */
	die(reqInfo,SC_FORBIDDEN,reqInfo->url); 
      } else {
	/* We know an error occured, of an unexpected variety. 
	 * This could be due to no more file descriptors.  We have this
	 * child exit after this stage so that errors of state are 
	 * swept under the carpet.
	 */
	standalone = 0;
	sprintf(error_msg,"File Open error, errno=%d",errno);
	log_reason(reqInfo,error_msg,reqInfo->filename);
	die(reqInfo,SC_SERVER_ERROR,error_msg);
      }
    }
    reqInfo->bytes_sent = 0;

#ifdef BLACKOUT_CODE
    if (!strcmp(reqInfo->outh_content_type,BLACKOUT_MAGIC_TYPE)) {
      isblack = TRUE;
      strcpy(reqInfo->outh_content_type,"text/html");
    }
#endif /* BLACKOUT_CODE */

    if(reqInfo->http_version != P_HTTP_0_9) {
      /* No length dependent headers since black is parsed */
#ifdef BLACKOUT_CODE
      if (isblack == FALSE) { 
#endif /* BLACKOUT_CODE */
#ifdef CONTENT_MD5
	reqInfo->outh_content_md5 = (unsigned char *)md5digest(f);
#endif /* CONTENT_MD5 */
	set_content_length(reqInfo,fi->st_size);
	if (set_last_modified(reqInfo,fi->st_mtime)) {
	    FClose(f);
	    return;
	}
      }
      if (reqInfo->http_version != P_HTTP_0_9) {
           send_http_header(reqInfo);
      }
#ifdef BLACKOUT_CODE
    }
#endif /* BLACKOUT_CODE */

    if(reqInfo->method != M_HEAD) {
#ifdef BLACKOUT_CODE
      if (isblack == TRUE)
	send_fp_black(reqInfo,f,NULL);
       else
#endif /* BLACKOUT_CODE */
	send_fp(reqInfo,f,NULL);
    }
    log_transaction(reqInfo);
    FClose(f);
}


void send_dir(per_request *reqInfo,struct stat *finfo, char allow_options) {
  char *name_ptr, *end_ptr;
  char *ifile, *temp_name;

  ifile = newString(HUGE_STRING_LEN,STR_TMP);
  temp_name = newString(HUGE_STRING_LEN,STR_TMP);

/* Path Alias (pa) array should now have the trailing slash */
  /*  if (pa[0] != '/') { */
  if ((reqInfo->filename[strlen(reqInfo->filename) - 1] != '/') && 
      (reqInfo->path_info[0] != '/')) {
    strcpy_dir(ifile,reqInfo->url);
    construct_url(temp_name,reqInfo->hostInfo,ifile);
    escape_url(temp_name);
    die(reqInfo,SC_REDIRECT_PERM,temp_name);
  }

  /* Don't allow PATH_INFO to directory indexes as a compromise for 
     error messages for files which don't exist */

  if ((reqInfo->path_info[0] != '\0') || (strlen(reqInfo->path_info) > 1)) {
        strcat(reqInfo->filename,reqInfo->path_info);
        strcat(reqInfo->url,reqInfo->path_info);
        sprintf(error_msg,"No file matching URL: %s",reqInfo->url);
        log_reason(reqInfo, error_msg, reqInfo->filename);
	freeString(temp_name);
	freeString(ifile);
        die(reqInfo,SC_NOT_FOUND,reqInfo->url);
  }
    
  strncpy(temp_name, reqInfo->hostInfo->index_names, HUGE_STRING_LEN-1);
  end_ptr = name_ptr = temp_name;

  while (*name_ptr) {
    
    while (*name_ptr && isspace (*name_ptr)) ++name_ptr;
    end_ptr = name_ptr;
    if (strchr(end_ptr, ' ') ) {
      end_ptr = strchr(name_ptr, ' ');
      *end_ptr = '\0';
      end_ptr++;
    } else
      end_ptr += strlen(end_ptr);
    make_full_path(reqInfo->filename,name_ptr,ifile);
    if(stat(ifile,finfo) == -1) {
      if(! *end_ptr && (allow_options & OPT_INDEXES)) {
        if (reqInfo->path_info[0]) {
          strcat(reqInfo->filename,reqInfo->path_info);
	  strcat(reqInfo->url,reqInfo->path_info);
	  log_reason(reqInfo,"file does not exist",reqInfo->filename);
	  freeString(ifile);
	  freeString(temp_name);
	  die(reqInfo,SC_NOT_FOUND,reqInfo->url);
	}
	if ((reqInfo->method != M_GET) && (reqInfo->method != M_HEAD)) {
	  sprintf(error_msg,"%s to non-script",methods[reqInfo->method]);
	  freeString(ifile);
	  freeString(temp_name);
	  die(reqInfo,SC_NOT_IMPLEMENTED,error_msg);
	}	
	index_directory(reqInfo);
	freeString(ifile);
	freeString(temp_name);
	return;
      } else if (! *end_ptr) {
	log_reason(reqInfo,"(2) file permissions deny server access",
		   reqInfo->filename);
	freeString(ifile);
	freeString(temp_name);
	die(reqInfo,SC_FORBIDDEN,reqInfo->url);
      }
    } else {
      strcpy(reqInfo->filename,ifile);
      probe_content_type(reqInfo,reqInfo->filename);
      if(!strcmp(reqInfo->outh_content_type,CGI_MAGIC_TYPE))
	send_cgi(reqInfo,finfo,allow_options);
      else
	send_file(reqInfo,finfo,allow_options);
      freeString(ifile);
      freeString(temp_name);
      return;
    }
    name_ptr = end_ptr;
  }	 
}
Exemplo n.º 21
0
u_int32_t
NIS_query(void *c, dsrecord *pattern, dsrecord **list)
{
	agent_private *ap;
	u_int32_t cat;
	dsattribute *a;
	dsdata *k;
	dsrecord *lastrec;
	char *map;
	dsrecord *item = NULL;
	int match;
	char *key, *val, *lastkey;
	int status, keylen, vallen, lastlen;
	char scratch[4096];
	int single_item, stamp;

	if (c == NULL) return 1;
	if (pattern == NULL) return 1;
	if (list == NULL) return 1;

	*list = NULL;
	lastrec = NULL;
	single_item = 0;
	stamp = 0;

	ap = (agent_private *)c;

	k = cstring_to_dsdata(CATEGORY_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);

	if (a == NULL) return 1;
	if (a->count == 0) return 1;

	cat = atoi(dsdata_to_cstring(a->value[0]));
	dsattribute_release(a);

	map = categoryMap[cat];
	if (map == NULL) return 1;

	k = cstring_to_dsdata(STAMP_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);
	if (a != NULL)
	{
		dsrecord_remove_attribute(pattern, a, SELECT_META_ATTRIBUTE);
		stamp = 1;
	}
	dsattribute_release(a);

	if (stamp == 1)
	{
		item = dsrecord_new();
		add_validation(item);
		*list = item;
		return 0;
	}

	k = cstring_to_dsdata(SINGLE_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);
	if (a != NULL)
	{
		dsattribute_release(a);
		single_item = 1;
	}

	key = NULL;
	val = NULL;
	vallen = 0;
	lastkey = NULL;

	syslock_lock(rpcLock);
	status = yp_first(ap->nis_domain_name, map, &key, &keylen, &val, &vallen);
	if (status != 0)
	{
		syslock_unlock(rpcLock);
		return 1;
	}

	while (status == 0)
	{
		switch (cat)
		{
			case LUCategoryNetgroup:
				bcopy(key, scratch, keylen);
				scratch[keylen] = ' ';
				bcopy(val, scratch+keylen+1, vallen);
				scratch[keylen + vallen + 1] = '\0';
				break;
			case LUCategoryAlias:
				bcopy(key, scratch, keylen);
				scratch[keylen] = ':';
				scratch[keylen + 1] = ' ';
				bcopy(val, scratch+keylen+2, vallen);
				scratch[keylen + vallen + 2] = '\0';
				break;
			default:
				bcopy(val, scratch, vallen);
				scratch[vallen] = '\0';
		}

		freeString(val);
		val = NULL;
		vallen = 0;

		item = parse(scratch, cat);

		freeString(lastkey);
		lastkey = NULL;

		if (item != NULL) 
		{
			match = dsrecord_match_select(item, pattern, SELECT_ATTRIBUTE);
			if (match == 1)
			{
				add_validation(item);

				if (*list == NULL) *list = dsrecord_retain(item);
				else lastrec->next = dsrecord_retain(item);

				lastrec = item;

				if (single_item == 1)
				{
					dsrecord_release(item);
					break;
				}
			}
			dsrecord_release(item);
		}

		lastkey = key;
		lastlen = keylen;

		status = yp_next(ap->nis_domain_name, map, lastkey, lastlen, &key, &keylen, &val, &vallen);
	}

	syslock_unlock(rpcLock);

	freeString(lastkey);

	return 0;
}
Exemplo n.º 22
0
u_int32_t
FF_query(void *c, dsrecord *pattern, dsrecord **list)
{
	agent_private *ap;
	u_int32_t cat;
	dsattribute *a;
	dsdata *k, *k4, *k6;
	dsrecord *lastrec;
	char *fname;
	FILE *fp;
	char *line;
	dsrecord *item = NULL;
	dsrecord *host = NULL;
	char *fpath;
	long ts;
	int match, single_item, stamp;
	ff_cache_t *cache;
	struct stat sb;

	if (c == NULL) return 1;
	if (pattern == NULL) return 1;
	if (list == NULL) return 1;

	*list = NULL;
	lastrec = NULL;
	single_item = 0;
	stamp = 0;

	ap = (agent_private *)c;

	k = cstring_to_dsdata(CATEGORY_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);

	if (a == NULL) return 1;
	if (a->count == 0) return 1;

	cat = atoi(dsdata_to_cstring(a->value[0]));
	dsattribute_release(a);

	fname = categoryFilename[cat];
	if (fname == NULL) return 1;

	k = cstring_to_dsdata(STAMP_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);
	if (a != NULL)
	{
		dsrecord_remove_attribute(pattern, a, SELECT_META_ATTRIBUTE);
		stamp = 1;
	}
	dsattribute_release(a);

	k = cstring_to_dsdata(SINGLE_KEY);
	a = dsrecord_attribute(pattern, k, SELECT_META_ATTRIBUTE);
	dsdata_release(k);
	if (a != NULL)
	{
		dsattribute_release(a);
		single_item = 1;
	}

	asprintf(&fpath, "%s/%s", ap->dir, fname);

	ts = 0;
	cache = NULL;
	if (ap->flags == 0) cache = cache_for_category(cat);
	if (cache != NULL)
	{
		ts = cache->modtime;
	}
	else
	{
		memset(&sb, 0, sizeof(struct stat));
		if (stat(fpath, &sb) < 0) ts = 0;
		else ts = sb.st_mtime;
	}

	if (stamp == 1)
	{
		item = dsrecord_new();
		add_validation(item, fpath, ts);
		*list = item;
		free(fpath);
		return 0;
	}

	if (cache != NULL)
	{
		free(fpath);
		return cache_query(cache, cat, single_item, pattern, list);
	}

	fp = fopen(fpath, "r");
	if (fp == NULL)
	{
		free(fpath);
		return 1;
	}

	/* bootptab entries start after a "%%" line */
	if (cat == LUCategoryBootp)
	{
		while (NULL != (line = getLineFromFile(fp)))
		{
			if (!strncmp(line, "%%", 2)) break;
			freeString(line);
			line = NULL;
		}
		if (line == NULL)
		{
			fclose(fp);
			free(fpath);
			return 0;
		}

		freeString(line);
		line = NULL;
	}
		
	while (NULL != (line = getLineFromFile(fp)))
	{
		if (line[0] == '#') 
		{
			freeString(line);
			line = NULL;
			continue;
		}

		item = parse(line, cat);

		freeString(line);
		line = NULL;

		if (item == NULL) continue;

		match = dsrecord_match_select(item, pattern, SELECT_ATTRIBUTE);
		if (match == 1)
		{
			add_validation(item, fpath, ts);

			if (*list == NULL) *list = dsrecord_retain(item);
			else lastrec->next = dsrecord_retain(item);

			lastrec = item;

			if (cat == LUCategoryHost)
			{
			}
			else if (single_item == 1)
			{
				dsrecord_release(item);
				break;
			}
		}

		dsrecord_release(item);
	}

	free(fpath);
	fclose(fp);

	if ((cat == LUCategoryHost) && (single_item == 1))
	{
		if ((*list) == NULL) return 0;
		if ((*list)->next == NULL) return 0;

		k = cstring_to_dsdata("name");
		k4 = cstring_to_dsdata("ip_address");
		k6 = cstring_to_dsdata("ipv6_address");
		host = *list;

		for (item = host->next; item != NULL; item = item->next)
		{
			a = dsrecord_attribute(item, k, SELECT_ATTRIBUTE);
			dsrecord_merge_attribute(host, a, SELECT_ATTRIBUTE);
			dsattribute_release(a);

			a = dsrecord_attribute(item, k4, SELECT_ATTRIBUTE);
			dsrecord_merge_attribute(host, a, SELECT_ATTRIBUTE);
			dsattribute_release(a);

			a = dsrecord_attribute(item, k6, SELECT_ATTRIBUTE);
			dsrecord_merge_attribute(host, a, SELECT_ATTRIBUTE);
			dsattribute_release(a);
		}

		dsdata_release(k);
		dsdata_release(k4);
		dsdata_release(k6);

		dsrecord_release(host->next);
		host->next = NULL;
	}

	return 0;
}
Exemplo n.º 23
0
void freeInputChain(InputChain *c) {
  freeString(c->input);
  kfree(c);
}
Exemplo n.º 24
0
void replaceString( char **aString, char *aNewString )
{
	freeString( aString );
	*aString = duplicateString( aNewString );
}
Exemplo n.º 25
0
static ff_cache_t *
load_cache(int cat, ff_cache_t *cache)
{
	dsrecord *lastrec;
	char *fname;
	FILE *fp;
	char *line;
	dsrecord *item = NULL;
	char *fpath;
	int status;
	struct stat sb;

	if (cache == NULL) return NULL;

	dsrecord_release(cache->crecord);
	cache->crecord = NULL;

	fname = categoryFilename[cat];
	if (fname == NULL) return NULL;

	asprintf(&fpath, "%s/%s", DEFAULT_FF_DIR, fname);

	memset(&sb, 0, sizeof(struct stat));
	status = stat(fpath, &sb);
	if (status < 0)
	{
		free(fpath);
		return NULL;
	}

	cache->modtime = sb.st_mtime;

	fp = fopen(fpath, "r");
	if (fp == NULL)
	{
		free(fpath);
		return NULL;
	}

	/* bootptab entries start after a "%%" line */
	if (cat == LUCategoryBootp)
	{
		while (NULL != (line = getLineFromFile(fp)))
		{
			if (!strncmp(line, "%%", 2)) break;
			freeString(line);
			line = NULL;
		}

		if (line == NULL)
		{
			fclose(fp);
			free(fpath);
			return 0;
		}

		freeString(line);
		line = NULL;
	}

	lastrec = NULL;

	while (NULL != (line = getLineFromFile(fp)))	
	{
		if (line[0] == '#')
		{
			freeString(line);
			line = NULL;
			continue;
		}

		item = parse(line, cat);

		freeString(line);
		line = NULL;

		if (item == NULL) continue;

		add_validation(item, fpath, cache->modtime);

		if (cache->crecord == NULL) cache->crecord = item;
		if (lastrec != NULL) lastrec->next = item;
		lastrec = item;
	}

	free(fpath);
	fclose(fp);

	return cache;
}
Exemplo n.º 26
0
/*
 * freeParseError :: ParseResult(ParseError) -> ()
 *
 * Release internal memeory of a ParseError
 */
void freeParseError(ParseResult *pe) {
  freeString((String*)pe->data.error);
}