示例#1
0
文件: caldav.c 项目: akpoff/kcaldav
static void
parseopen(void *dat, const XML_Char *s, const XML_Char **atts)
{
	struct parse	*p = dat;
	enum calelem	 elem;

	if (CALELEM__MAX != (elem = calelem_find(s)))
		kdbg("Known element: %s", s);
	else
		kdbg("Unknown element: %s", s);

	switch (elem) {
	case (CALELEM_CALENDAR_QUERY):
		caldav_alloc(p, TYPE_CALQUERY);
		break;
	case (CALELEM_CALENDAR_MULTIGET):
		caldav_alloc(p, TYPE_CALMULTIGET);
		break;
	case (CALELEM_PROPERTYUPDATE):
		caldav_alloc(p, TYPE_PROPERTYUPDATE);
		break;
	case (CALELEM_PROPFIND):
		caldav_alloc(p, TYPE_PROPFIND);
		break;
	case (CALELEM_HREF):
		p->buf.sz = 0;
		XML_SetDefaultHandler(p->xp, parsebuffer);
		break;
	case (CALELEM_PROP):
		XML_SetElementHandler(p->xp, propopen, propclose);
		break;
	default:
		break;
	}
}
示例#2
0
文件: caldav.c 项目: akpoff/kcaldav
static void
propopen(void *dat, const XML_Char *s, const XML_Char **atts)
{
	struct parse	*p = dat;
	enum calelem	 elem;

	if (CALELEM__MAX == (elem = calelem_find(s))) 
		kdbg("Unknown property: %s", s);
	else
		kdbg("Known property: %s", s);

	switch (elem) {
	case (CALELEM__MAX):
		propadd(p, s, PROP__MAX, NULL);
		break;
	default:
		if (PROP__MAX == calprops[elem]) {
			propadd(p, s, PROP__MAX, NULL);
			break;
		}
		p->buf.sz = 0;
		XML_SetDefaultHandler(p->xp, parsebuffer);
		break;
	}
}
示例#3
0
static int hello_init(void)
{
    struct task_struct *p = get_current();

    kdbg("%s enter\n", __FUNCTION__);
    kdbg("paramters: count=%d, name=%s\n",count,name);
    kdbg("current'name=%s, current'pid=%d\n",p->comm, p->pid);
    kdbg("kernel version code is %d, make code is %d\n",LINUX_VERSION_CODE, KERNEL_VERSION(3,10,0));

    return 0;
}
示例#4
0
文件: vm.c 项目: tspink/ksim
void vm_free(struct ksim_context *ctx, void __guest *addr)
{
	struct ksim_vm_info *vmi = thread_current(ctx)->vm;
	struct vm_alloc_region *rgn;
		
	for (rgn = vmi->regions; rgn; rgn = rgn->next) {
		if ((unsigned long)addr == rgn->base) {
			/* TODO: Remove from list. */
			kdbg("vm: free region - not implemented\n");
			break;
		}
	}
	
	kdbg("vm: attempt to free region without matching base pointer\n");
}
示例#5
0
文件: vm.c 项目: tspink/ksim
int vm_alloc_fixed(struct ksim_context *ctx, void __guest *addr, unsigned int size)
{
	struct ksim_vm_info *vmi = thread_current(ctx)->vm;
	struct vm_alloc_region *rgn;
	
	/* Must be aligned to 4-byte boundary. */
	/* TODO: Should this be 8-bytes for 64-bit emulation? */
	if ((unsigned long)addr % 4)
		return -1;
	
	/* Size must be aligned to page size. */
	if (size % GUEST_PAGE_SIZE)
		size += GUEST_PAGE_SIZE - (size % GUEST_PAGE_SIZE);
	
	/* Look for overlapping allocation regions, and instantly refuse
	 * allocation. */
	
	/* TODO: MMAP semantics allow overlapping regions, where
	 * overlapping portions are split. */
	if (is_allocated(ctx, addr)) {
		kdbg("vm: address already allocated\n");
		return -1;
	}
	
	/* Allocate storage for the allocation region descriptor. */
	rgn = malloc(sizeof(*rgn));
	if (!rgn) {
		return -1;
	}
	
	/* Populate the region descriptor, and insert it into the list. */
	rgn->base = (unsigned long)addr;
	rgn->size = size;
	rgn->next = vmi->regions;
	
	vmi->regions = rgn;
	
	kdbg("vm: alloc: base=0x%lx, size=0x%x\n", rgn->base, rgn->size);
	
	return 0;
}
示例#6
0
static void hello_exit(void)
   {
       kdbg("%s exit\n",__FUNCTION__);
       return;
   }
示例#7
0
int kParserSIP(long indatalen,unsigned char *indata,unsigned char **packet_start_point,short *packet_size)
{
  static char tmpBuff[256];
  int i,nmatch=6,ret,startPos,endPos,bodyPos,contentLen;
  regex_t pat1,pat2,pat3;
  regmatch_t match[nmatch];
  char errbuf[100];
#ifdef DBG_PARSER
	kdbg("/tmp/dbg_parser.txt", "%s\n", "initializing.");
	kdbg("/tmp/dbg_parser.txt", "indatalen: %ld\n", indatalen);
#endif	/* DBG_PARSER */
  if(!indatalen) return(PA_ERROR);

  /* パターン文字列のコンパイル */
  if((ret=regcomp(&pat1,SIPPAT1,REG_EXTENDED|REG_ICASE))){
    regerror(ret,&pat1,errbuf,sizeof errbuf);
    kLogWrite(L_ERROR,"%s: regcomp:%d:%s",__FUNCTION__,ret,errbuf);
    return(PA_ERROR);
  }
  if((ret=regcomp(&pat2,SIPPAT2,REG_EXTENDED|REG_ICASE))){
    regerror(ret,&pat2,errbuf,sizeof errbuf);
    kLogWrite(L_ERROR,"%s: regcomp:%d:%s\n",__FUNCTION__,ret,errbuf);
    return(PA_ERROR);
  }
  if((ret=regcomp(&pat3,SIPPAT3,REG_EXTENDED|REG_ICASE))){
    regerror(ret,&pat3,errbuf,sizeof errbuf);
    kLogWrite(L_ERROR,"%s: regcomp:%d:%s\n",__FUNCTION__,ret,errbuf);
    return(PA_ERROR);
  }

  kLogWrite(L_PARSE,"%s: String Length[%ld]\n",__FUNCTION__,indatalen);
  /* SIPパターンのマッチング */
  if( !regexec(&pat1,(const char *)indata,nmatch,match,0) ){

    /* 開始位置の保存 */
    startPos=match[2].rm_so;
    endPos=match[0].rm_eo;
    *packet_start_point=&indata[startPos];
    *packet_size=endPos-startPos;
    
    /* ボディ(\r\n)の検索 */
    for(bodyPos = -1, i = startPos; i < endPos; i ++){
      if(!memcmp("\r\n\r\n",&indata[i],4)){
	bodyPos=i+4;
	break;
      }
    }
    if(bodyPos == -1){
      kLogWrite(L_WARNING,"%s: SIP Body match error",__FUNCTION__);
      return(PA_ERROR);
    }
    kLogWrite(L_PARSE,"%s: Start[%d] Body[%d] End[%d]",__FUNCTION__,startPos,bodyPos,endPos);

    /* Contents-Lengthの検索 */
    if( !regexec(&pat2,(const char *)&indata[startPos],nmatch,match,0)){
      if(match[2].rm_so != -1 && match[2].rm_eo != -1 && match[2].rm_so < bodyPos){
	/* Contents-Lengthがある場合 */
	memcpy(tmpBuff,&indata[startPos+match[2].rm_so],match[2].rm_eo-match[2].rm_so+1);
	tmpBuff[match[2].rm_eo-match[2].rm_so+1]=0;
	contentLen=atoi(tmpBuff);
	kLogWrite(L_PARSE,"%s: Content-Length[%d] Body+Content[%d] Total[%ld]",
		  __FUNCTION__,contentLen,bodyPos+contentLen,indatalen);
	/* マッチした長さを設定 */
	if(bodyPos+contentLen<indatalen){
	  *packet_size=bodyPos+contentLen-startPos;
	  ret=PA_LEFTDATA;
	} else if(bodyPos+contentLen==indatalen){
	  *packet_size=bodyPos+contentLen-startPos;
	  ret=PA_JUSTONE;
	} else{
	  ret=PA_NOMATCH;
	}
	goto EXIT;
      }
    }

    /* Contents-Lengthがない場合、とりあえずボディ部以降にコマンド行があるか調べてみる */
    if( !regexec(&pat3,(const char *)&indata[bodyPos],nmatch,match,0)){
      kLogWrite(L_PARSE,"%s: Next command line exist[%lld]",__FUNCTION__,bodyPos+match[2].rm_so);
      *packet_size=bodyPos+match[2].rm_so-startPos;
      ret=PA_LEFTDATA;
    } else{
      /* ボディ部以降にボディ(\r\n)があればそこまでで区切る */
      for(i = bodyPos ; i < endPos; i ++){
	if(!memcmp("\r\n\r\n",&indata[i],4)){
	  *packet_size=i-startPos+2;
	  ret=PA_LEFTDATA;
	  /* ボディ部以降にボディ(\\r\\n)にあり[%d] */
	  kLogWrite(L_PARSE,"%s: [\\r\\n] exist, after body [%d]",__FUNCTION__,i);
	  goto EXIT;
	}
      }
      kLogWrite(L_PARSE,"%s: One matched",__FUNCTION__);
      ret=PA_JUSTONE;
    }
  } else{
    kLogWrite(L_PARSE,"%s: Not matched",__FUNCTION__);
    ret=PA_NOMATCH;
  }

 EXIT:
  regfree(&pat1);
  regfree(&pat2);
  regfree(&pat3);
  return(ret);
}
示例#8
0
文件: caldav.c 项目: akpoff/kcaldav
/*
 * Add a property we've parsed from our input.
 * Properties appear in nearly all CalDAV XML requests, either as
 * requests for a property (e.g, TYPE_PROPFIND) or for setting
 * properties (e.g., TYPE_PROPERTYUPDATE).
 * If we know about a property, it's type isn't PROP__MAX.
 * If we're setting a property, we also validate the value to make sure
 * it's ok.
 */
static void
propadd(struct parse *p, const XML_Char *name, 
	enum proptype prop, const char *cp)
{
	const XML_Char	*ns;
	size_t		 namesz, nssz;
	void		*pp;

	if (NULL == p->p) {
		caldav_err(p, "property list in unknown request");
		return;
	} else if (NULL != (ns = strrchr(name, ':'))) {
		namesz = ns - name;
		nssz = strlen(++ns);
	} else {
		namesz = strlen(name);
		nssz = 0;
	}

	pp = reallocarray(p->p->props,
		p->p->propsz + 1, sizeof(struct prop));
	if (NULL == pp) {
		caldav_err(p, "memory exhausted");
		return;
	}
	p->p->props = pp;
	memset(&p->p->props[p->p->propsz], 0, sizeof(struct prop));

	/*
	 * Copy over the name and XML namespace as the parser gives it
	 * to us: with the colon as a separator.
	 */
	p->p->props[p->p->propsz].key = prop;
	p->p->props[p->p->propsz].xmlns = malloc(namesz + 1);
	if (NULL == p->p->props[p->p->propsz].xmlns) {
		caldav_err(p, "memory exhausted");
		return;
	}
	memcpy(p->p->props[p->p->propsz].xmlns, name, namesz);
	p->p->props[p->p->propsz].xmlns[namesz] = '\0';

	p->p->props[p->p->propsz].name = malloc(nssz + 1);
	if (NULL == p->p->props[p->p->propsz].name) {
		caldav_err(p, "memory exhausted");
		return;
	}
	memcpy(p->p->props[p->p->propsz].name, ns, nssz);
	p->p->props[p->p->propsz].name[nssz] = '\0';
	p->p->propsz++;
	
	/* Now prep for settable properties... */
	if (PROP__MAX == prop)
		return;
	if (TYPE_PROPERTYUPDATE != p->p->type) 
		return;

	/*
	 * Copy over any settable value.
	 * Make sure that we validate anything that we could set.
	 */
	assert(NULL != cp);
	p->p->props[p->p->propsz - 1].val = strdup(cp);
	if (NULL == p->p->props[p->p->propsz - 1].val) {
		caldav_err(p, "memory exhausted");
		return;
	} else if (NULL == propvalids[prop])
		return;

	/* Validation... */
	p->p->props[p->p->propsz - 1].valid = 
		propvalids[prop](cp) ? 1 : -1;

	if (p->p->props[p->p->propsz - 1].valid >= 0) 
		return;

	kdbg("Bad property value: %s", 
		p->p->props[p->p->propsz - 1].name);
}