Example #1
0
/* draw char at cp, expand tabs, ctl chars */
static int
Draw(Char *cp, int nocomb, int drawPrompt)
{
    int w, i, lv, lh;
    Char c, attr;

#ifdef WIDE_STRINGS
    if (!drawPrompt) {			/* draw command-line */
	attr = 0;
	c = *cp;
    } else {				/* draw prompt */
	/* prompt with attributes(UNDER,BOLD,STANDOUT) */
	if (*cp & (UNDER | BOLD | STANDOUT)) {		/* *cp >= STANDOUT */

	    /* example)
	     * We can't distinguish whether (*cp=)0x02ffffff is
	     * U+02FFFFFF or U+00FFFFFF|STANDOUT.
	     * We handle as U+00FFFFFF|STANDOUT, only when drawing prompt. */
	    attr = (*cp & ATTRIBUTES);
	    /* ~(UNDER | BOLD | STANDOUT) = 0xf1ffffff */
	    c = *cp & ~(UNDER | BOLD | STANDOUT);

	    /* if c is ctrl code, we handle *cp as havnig no attributes */
	    if ((c < 0x20 && c >= 0) || c == 0x7f) {
		attr = 0;
		c = *cp;
	    }
	} else {			/* prompt without attributes */
	    attr = 0;
	    c = *cp;
	}
    }
#else
    attr = *cp & ~CHAR;
    c = *cp & CHAR;
#endif
    w = NLSClassify(c, nocomb, drawPrompt);
    switch (w) {
	case NLSCLASS_NL:
	    Vdraw('\0', 0);		/* assure end of line	 */
	    vcursor_h = 0;		/* reset cursor pos	 */
	    vcursor_v++;
	    break;
	case NLSCLASS_TAB:
	    do {
		Vdraw(' ', 1);
	    } while ((vcursor_h & 07) != 0);
	    break;
	case NLSCLASS_CTRL:
	    Vdraw('^' | attr, 1);
	    if (c == CTL_ESC('\177')) {
		Vdraw('?' | attr, 1);
	    } else {
#ifdef IS_ASCII
		/* uncontrolify it; works only for iso8859-1 like sets */
		Vdraw(c | 0100 | attr, 1);
#else
		Vdraw(_toebcdic[_toascii[c]|0100] | attr, 1);
#endif
	    }
	    break;
	case NLSCLASS_ILLEGAL:
	    Vdraw('\\' | attr, 1);
	    Vdraw((((c >> 6) & 7) + '0') | attr, 1);
	    Vdraw((((c >> 3) & 7) + '0') | attr, 1);
	    Vdraw(((c & 7) + '0') | attr, 1);
	    break;
	case NLSCLASS_ILLEGAL2:
	case NLSCLASS_ILLEGAL3:
	case NLSCLASS_ILLEGAL4:
	case NLSCLASS_ILLEGAL5:
	    Vdraw('\\', 1);
	    Vdraw('U', 1);
	    Vdraw('+', 1);
	    for (i = 16 + 4 * (-w-5); i >= 0; i -= 4)
		Vdraw("0123456789ABCDEF"[(c >> i) & 15] | attr, 1);
	    break;
	case 0:
	    lv = vcursor_v;
	    lh = vcursor_h;
	    for (;;) {
		lh--;
		if (lh < 0) {
		    lv--;
		    if (lv < 0)
			break;
		    lh = Strlen(Vdisplay[lv]) - 1;
		}
		if (Vdisplay[lv][lh] != CHAR_DBWIDTH)
		    break;
	    }
	    if (lv < 0) {
		Vdraw('\\' | attr, 1);
		Vdraw((((c >> 6) & 7) + '0') | attr, 1);
		Vdraw((((c >> 3) & 7) + '0') | attr, 1);
		Vdraw(((c & 7) + '0') | attr, 1);
		break;
	    }
	    Vdisplay[lv][lh] = MakeLiteral(cp, 1, Vdisplay[lv][lh]);
	    break;
	default:
	    Vdraw(*cp, w);
	    break;
    }
Example #2
0
/* The actual "aliasing" of for backgrounds() is done here
   with the aid of insert_we().   */
static void
insert(struct wordent *pl, int file_args)
{
    struct wordent *now, *last;
    Char   *cmd, *bcmd, *cp1, *cp2;
    size_t cmd_len;
    Char   *upause = STRunderpause;
    size_t p_len = Strlen(upause);

    cmd_len = Strlen(pl->word);
    cmd = xcalloc(1, (cmd_len + 1) * sizeof(Char));
    (void) Strcpy(cmd, pl->word);
/* Do insertions at beginning, first replace command word */

    if (file_args) {
	now = pl;
	xfree(now->word);
	now->word = xcalloc(1, 5 * sizeof(Char));
	(void) Strcpy(now->word, STRecho);

	now = xcalloc(1, sizeof(struct wordent));
	now->word = xcalloc(1, 6 * sizeof(Char));
	(void) Strcpy(now->word, STRbackqpwd);
	insert_we(now, pl);

	for (last = now; *last->word != '\n' && *last->word != ';';
	     last = last->next)
	    continue;

	now = xcalloc(1, sizeof(struct wordent));
	now->word = xcalloc(1, 2 * sizeof(Char));
	(void) Strcpy(now->word, STRgt);
	insert_we(now, last->prev);

	now = xcalloc(1, sizeof(struct wordent));
	now->word = xcalloc(1, 2 * sizeof(Char));
	(void) Strcpy(now->word, STRbang);
	insert_we(now, last->prev);

	now = xcalloc(1, sizeof(struct wordent));
	now->word = xcalloc(1, (cmd_len + p_len + 4) * sizeof(Char));
	cp1 = now->word;
	cp2 = cmd;
	*cp1++ = '~';
	*cp1++ = '/';
	*cp1++ = '.';
	while ((*cp1++ = *cp2++) != '\0')
	    continue;
	cp1--;
	cp2 = upause;
	while ((*cp1++ = *cp2++) != '\0')
	    continue;
	insert_we(now, last->prev);

	now = xcalloc(1, sizeof(struct wordent));
	now->word = xcalloc(1, 2 * sizeof(Char));
	(void) Strcpy(now->word, STRsemi);
	insert_we(now, last->prev);
	bcmd = xcalloc(1, (cmd_len + 2) * sizeof(Char));
	*bcmd = '%';
	Strcpy(bcmd + 1, cmd);
	now = xcalloc(1, sizeof(struct wordent));
	now->word = bcmd;
	insert_we(now, last->prev);
    }
    else {
	struct wordent *del;

	now = pl;
	xfree(now->word);
	now->word = xcalloc(1, (cmd_len + 2) * sizeof(Char));
	*now->word = '%';
	Strcpy(now->word + 1, cmd);
	for (now = now->next;
	     *now->word != '\n' && *now->word != ';' && now != pl;) {
	    now->prev->next = now->next;
	    now->next->prev = now->prev;
	    xfree(now->word);
	    del = now;
	    now = now->next;
	    xfree(del);
	}
    }
}
Example #3
0
/* parseLS_COLORS():
 *	Parse the LS_COLORS environment variable
 */
void
parseLS_COLORS(const Char *value)
{
    size_t  i, len;
    const Char	 *v;		/* pointer in value */
    char   *c;			/* pointer in colors */
    Extension *volatile e;	/* pointer in extensions */
    jmp_buf_t osetexit;
    size_t omark;

    (void) &e;

    /* init */
    xfree(extensions);
    for (i = 0; i < nvariables; i++)
	variables[i].color = variables[i].defaultcolor;
    colors = NULL;
    extensions = NULL;
    nextensions = 0;

    if (value == NULL)
	return;

    len = Strlen(value);
    /* allocate memory */
    i = 1;
    for (v = value; *v; v++)
	if ((*v & CHAR) == ':')
	    i++;
    extensions = xmalloc(len + i * sizeof(Extension));
    colors = i * sizeof(Extension) + (char *)extensions;
    nextensions = 0;

    /* init pointers */
    v = value;
    c = colors;
    e = &extensions[0];

    /* Prevent from crashing if unknown parameters are given. */

    omark = cleanup_push_mark();
    getexit(osetexit);

    if (setexit() == 0) {

    /* parse */
    while (*v) {
	switch (*v & CHAR) {
	case ':':
	    v++;
	    continue;

	case '*':		/* :*ext=color: */
	    v++;
	    if (getstring(&c, &v, &e->extension, '=') &&
		0 < e->extension.len) {
		v++;
		getstring(&c, &v, &e->color, ':');
		e++;
		continue;
	    }
	    break;

	default:		/* :vl=color: */
	    if (v[0] && v[1] && (v[2] & CHAR) == '=') {
		for (i = 0; i < nvariables; i++)
		    if ((Char)variables[i].variable[0] == (v[0] & CHAR) &&
			(Char)variables[i].variable[1] == (v[1] & CHAR))
			break;
		if (i < nvariables) {
		    v += 3;
		    getstring(&c, &v, &variables[i].color, ':');
		    continue;
		}
		else
		    stderror(ERR_BADCOLORVAR, v[0], v[1]);
	    }
	    break;
	}
	while (*v && (*v & CHAR) != ':')
	    v++;
    }
    }

    cleanup_pop_mark(omark);
    resexit(osetexit);

    nextensions = e - extensions;
}
Example #4
0
// DLL Entry Point
extern "C" BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
{
	if (dwReason==DLL_PROCESS_ATTACH)
	{
		InitSettings();
		g_TlsIndex=TlsAlloc();
		if (g_TlsIndex==TLS_OUT_OF_INDEXES) 
			return FALSE; // TLS failure

		wchar_t path[_MAX_PATH];
		GetModuleFileName(NULL,path,_countof(path));
		const wchar_t *exe=PathFindFileName(path);
		g_bExplorerExe=(_wcsicmp(exe,L"explorer.exe")==0 || _wcsicmp(exe,L"verclsid.exe")==0);
		bool bReplaceUI=GetWinVersion()<WIN_VER_WIN8 && (GetSettingBool(L"ReplaceFileUI") || GetSettingBool(L"ReplaceFolderUI") || GetSettingBool(L"EnableMore"));
		if (_wcsicmp(exe,L"regsvr32.exe")!=0 && _wcsicmp(exe,L"msiexec.exe")!=0 && _wcsicmp(exe,L"ClassicExplorerSettings.exe")!=0 && !g_bExplorerExe)
		{
			// some arbitrary app
			if ((!GetSettingBool(L"ShareOverlay") || GetSettingBool(L"ShareExplorer")) && (!bReplaceUI || GetSettingBool(L"FileExplorer")))
				return FALSE;
			CString whiteList=GetSettingString(L"ProcessWhiteList");
			if (!whiteList.IsEmpty())
			{
				// check for whitelisted process names
				const wchar_t *str=whiteList;
				bool bFound=false;
				while (*str)
				{
					wchar_t token[_MAX_PATH];
					str=GetToken(str,token,_countof(token),L",;");
					wchar_t *start=token;
					while (*start==' ')
						start++;
					wchar_t *end=start+Strlen(start);
					while (end>start && end[-1]==' ')
						end--;
					*end=0;
					if (_wcsicmp(exe,start)==0)
					{
						bFound=true;
						break;
					}
				}
				if (!bFound)
					return FALSE;
			}
			else
			{
				// check for blacklisted process names
				CString blackList=GetSettingString(L"ProcessBlackList");
				const wchar_t *str=blackList;
				while (*str)
				{
					wchar_t token[_MAX_PATH];
					str=GetToken(str,token,_countof(token),L",;");
					wchar_t *start=token;
					while (*start==' ')
						start++;
					wchar_t *end=start+Strlen(start);
					while (end>start && end[-1]==' ')
						end--;
					*end=0;
					if (_wcsicmp(exe,start)==0)
						return FALSE;
				}
			}
		}

		g_Instance=hInstance;
		g_LoadedSettingsAtom=(LPCWSTR)GlobalAddAtom(L"ClassicExplorer.LoadedSettings");

		GetModuleFileName(hInstance,path,_countof(path));
		*PathFindFileName(path)=0;
		wchar_t fname[_MAX_PATH];
		Sprintf(fname,_countof(fname),L"%s" INI_PATH L"ExplorerL10N.ini",path);
		CString language=GetSettingString(L"Language");
		ParseTranslations(fname,language);

		HINSTANCE resInstance=NULL;
		if (!language.IsEmpty())
		{
			wchar_t fname[_MAX_PATH];
			Sprintf(fname,_countof(fname),L"%s" INI_PATH L"%s.dll",path,language);
			resInstance=LoadLibraryEx(fname,NULL,LOAD_LIBRARY_AS_DATAFILE|LOAD_LIBRARY_AS_IMAGE_RESOURCE);
		}
		else
		{
			wchar_t languages[100]={0};
			ULONG size=4; // up to 4 languages
			ULONG len=_countof(languages);
			GetThreadPreferredUILanguages(MUI_LANGUAGE_NAME,&size,languages,&len);

			for (const wchar_t *language=languages;*language;language+=Strlen(language)+1)
			{
				wchar_t fname[_MAX_PATH];
				Sprintf(fname,_countof(fname),L"%s" INI_PATH L"%s.dll",path,language);
				resInstance=LoadLibraryEx(fname,NULL,LOAD_LIBRARY_AS_DATAFILE|LOAD_LIBRARY_AS_IMAGE_RESOURCE);
				if (resInstance)
					break;
			}
		}

		if (resInstance && GetVersionEx(resInstance)!=GetVersionEx(g_Instance))
		{
			FreeLibrary(resInstance);
			resInstance=NULL;
		}
		LoadTranslationResources(g_Instance,resInstance,g_LoadDialogs);

		if (resInstance)
			FreeLibrary(resInstance);

		g_bHookCopyThreads=(bReplaceUI && (g_bExplorerExe || !GetSettingBool(L"FileExplorer")));
		if (g_bHookCopyThreads)
		{
			InitClassicCopyProcess();
			InitClassicCopyThread();
		}

		if (GetSettingBool(L"ShareOverlay") && (g_bExplorerExe || !GetSettingBool(L"ShareExplorer")))
			CShareOverlay::InitOverlay(GetSettingString(L"ShareOverlayIcon"));
	}

	if (dwReason==DLL_THREAD_ATTACH)
	{
		if (g_bHookCopyThreads)
			InitClassicCopyThread();
	}

	if (dwReason==DLL_THREAD_DETACH)
	{
		void *pData=TlsGetValue(g_TlsIndex);
		if (pData)
			LocalFree((HLOCAL)pData);
		TlsSetValue(g_TlsIndex,NULL);
		if (g_bHookCopyThreads)
			FreeClassicCopyThread();
	}

	if (dwReason==DLL_PROCESS_DETACH)
	{
		void *pData=TlsGetValue(g_TlsIndex);
		if (pData)
			LocalFree((HLOCAL)pData);
		TlsSetValue(g_TlsIndex,NULL);
		TlsFree(g_TlsIndex);
		GlobalDeleteAtom((ATOM)g_LoadedSettingsAtom);
	}

	return _AtlModule.DllMain(dwReason, lpReserved);
}
int
rd_word_add1 (struct JT *jtl,
	      w_char *pyomi,	/* normal order (not reversed) */
	      int hinsi,
	      w_char *pkanji,	/* normal order (not reversed) */
	      w_char *comment)
{
  struct rind1 *tary;
  int key, key0, keye;
  int serial = jtl->maxserial;
  w_char *tmp = (w_char *) 0;
  struct rind2 *ri2;
  int ind;
  int which;
  w_char *csult;

  w_char yomi[LENGTHYOMI];
  w_char kanji[LENGTHYOMI];

#ifdef  CONVERT_with_SiSheng
  unsigned int sisheng_int;
  char pan_tmp[256];
  w_char pan_yomi[LENGTHYOMI];

  sisheng_int = 0;
  biki_sisheng (pyomi, pan_tmp, yomi);
  sscanf (pan_tmp, "%d", &sisheng_int);
  Strcpy (kanji, pkanji);
#else
# ifdef CONVERT_from_TOP
  Strcpy (yomi, pyomi);
  Strcpy (kanji, pkanji);
# else
  Sreverse (yomi, pyomi);
  Sreverse (kanji, pkanji);
# endif /* CONVERT_from_TOP */
#endif /* CONVERT_with_SiSheng */

  if ((jtl->bufsize_kanji <= jtl->maxkanji + (Strlen (kanji) + Strlen (comment) + Strlen (yomi) + 3) * sizeof (w_char) + 1)
      && (ud_realloc_kanji (jtl) == 0))
    {
      return (-1);
    }
  if (jtl->bufsize_ri1[D_YOMI] <= jtl->maxri1[D_YOMI] + 2
     && rd_realloc_ri1 (jtl, D_YOMI) == 0)
    {
      return (-1);
    }
  if (jtl->bufsize_ri1[D_KANJI] <= jtl->maxri1[D_KANJI] + 2
     && rd_realloc_ri1 (jtl, D_KANJI) == 0)
    {
      return (-1);
    }
  if (jtl->bufsize_serial <= jtl->maxserial + 4
     && ud_realloc_serial (jtl) == 0)
    {
      return (-1);
    }

  ri2 = jtl->ri2;

  tary = jtl->ri1[D_YOMI];
  key = rd_binary_same (tary, yomi, jtl->maxri1[D_YOMI], jtl->ri2, jtl->kanji, D_YOMI);
  if (key != -1)
    {                           /*  Entry with same yomi */
      ind = tary[key].pter;
      while (1)
        {
          w_char kanji1[LENGTHKANJI];
          w_char comment1[LENGTHKANJI];
          if (jtl->hinsi[ind] == hinsi)
            {
              Get_kanji (ri2[ind].kanjipter + jtl->kanji, yomi, Strlen (yomi), kanji1, NULL, comment1);
              if (Strcmp (pkanji, kanji1) == 0)
                {
                  /* Same hinsi, same kanji, same yomi */
                  if (Strcmp (comment, comment1) != 0)
                    {
                      /* set_comment */
                      ri2[ind].kanjipter = jtl->maxkanji;
                      kanjiadd (jtl, pkanji, pyomi, comment);
                    }
                  return (ind);
                }
            }
          if (ri2[ind].next[D_YOMI] == RD_ENDPTR)
            break;
          ind = ri2[ind].next[D_YOMI];
        }
    }
  for (which = 0; which < 2; which++)
    {
      csult = (which == 0) ? yomi : kanji;
      tary = jtl->ri1[which];
      key = rd_binary1 (tary, csult, jtl->maxri1[which], jtl->ri2, jtl->kanji, which);
      if (key >= 0)
        {
          tmp = KANJI_str (ri2[tary[key].pter].kanjipter + jtl->kanji, which);
#ifdef  CONVERT_with_SiSheng
          tmp = biki_sisheng (tmp, pan_tmp, pan_yomi);
#endif
        }
      if (key < 0 || Strcmp (csult, tmp))
        {                       /* No entry with same yomi */
          key += 1;
          for (key0 = key - 1; key0 >= 0; key0 = tary[key0].pter1)
            {
              tmp = KANJI_str (ri2[tary[key0].pter].kanjipter + jtl->kanji, which);
#ifdef  CONVERT_with_SiSheng
              tmp = biki_sisheng (tmp, pan_tmp, pan_yomi);
#endif
              if (Substr (tmp, csult))
                {
                  break;
                }
            }
#ifdef CONVERT_by_STROKE
          if (jtl->bind != NULL)
            b_index_add (jtl, pyomi, serial);
#endif
          rd_make_space (tary, key, jtl, jtl->maxri1[which], which);
          for (keye = key + 1; keye < jtl->maxri1[which]; keye++)
            {
              tmp = KANJI_str (ri2[tary[keye].pter].kanjipter + jtl->kanji, which);
#ifdef  CONVERT_with_SiSheng
              tmp = biki_sisheng (tmp, pan_tmp, pan_yomi);
#endif
              if (!Substr (csult, tmp))
                break;
              if (tary[keye].pter1 == key0)
                tary[keye].pter1 = key;
            }
          tary[key].pter1 = key0;
          ri2[serial].next[which] = RD_ENDPTR;
        }
      else
        {
          ri2[serial].next[which] = tary[key].pter;
        }
      tary[key].pter = serial;
    }
  jtl->maxserial++;
  jtl->maxri2++;
  jtl->gosuu++;
  ri2[serial].kanjipter = jtl->maxkanji;
  jtl->hinsi[serial] = hinsi;
  jtl->hindo[serial] = 0;       /* Hindo is set later on upper module */
#ifdef  CONVERT_with_SiSheng
  jtl->sisheng[serial] = sisheng_int;
#endif
  kanjiadd (jtl, pkanji, pyomi, comment);
  return (serial);
}
//----------------------------------------------------------------------------
int medHTMLTemplateParserBlock::PreParseTag( wxString *inputTemplate, int &parsingPos )
//----------------------------------------------------------------------------
{
    int templateSize=inputTemplate->size();
    wxString tagName;

    // OPENING TAG
    if (SubStringCompare(inputTemplate,MED_HMTL_TAG_OPENING,parsingPos))
    {
        int substitutionType;

        int subPos;

        parsingPos+=Strlen(MED_HMTL_TAG_OPENING);
        //cheking the opening tag type
        if (SubStringCompare(inputTemplate,MED_HTML_TAG_VARIABLE,parsingPos))
        {
            substitutionType=MED_HTML_SUBSTITUTION_VARIABLE;
            parsingPos+=Strlen(MED_HTML_TAG_VARIABLE);
        }
        else if (SubStringCompare(inputTemplate,MED_HTML_TAG_LOOP,parsingPos))
        {
            substitutionType=MED_HTML_SUBSTITUTION_BLOCK;
            parsingPos+=Strlen(MED_HTML_TAG_LOOP);
        }
        else if (SubStringCompare(inputTemplate,MED_HTML_TAG_IF,parsingPos))
        {
            substitutionType=MED_HTML_SUBSTITUTION_BLOCK;
            parsingPos+=Strlen(MED_HTML_TAG_IF);
        }
        else if (SubStringCompare(inputTemplate,MED_HTML_TAG_ELSE,parsingPos))
        {
            //if I find a else tag I update local variables and continue parsing inside this block
            if (m_BlockType!=MED_HTML_TEMPLATE_IF)
                mafLogMessage("medHTMLTemplateParserBlock: [MAFElse] found inside a non [MAFIf] block ");
            parsingPos+=Strlen(MED_HTML_TAG_ELSE);

            ReadTagName(inputTemplate,parsingPos,tagName);

            int comp=tagName.Cmp(m_BlockName);

            if (comp!=0)
                mafLogMessage(" ELSE medHTMLTemplateParserBlock: warning wrong closing tag");
            else m_IfChars=m_PreParsedHTML.size();

            //return because Else tag has not a tag name
            return true;
        }
        else
            mafLogMessage("medHTMLTemplateParserBlock: Invalid TAG Type");

        ReadTagName(inputTemplate,parsingPos,tagName);
        subPos=AddSubstitution(&tagName,substitutionType);



        //Parsing sub tags
        if (subPos>=0 && (substitutionType==MED_HTML_TEMPLATE_IF || substitutionType==MED_HTML_TEMPLATE_LOOP))
        {
            int tablePos=m_Substitutions[subPos].SubsTablePos;
            int blockPos=m_SubstitutionTable[tablePos].Pos;

            if (m_SubstitutionTable[tablePos].Type==MED_HTML_SUBSTITUTION_BLOCK)
                m_SubBlocks[blockPos]->PreParse(inputTemplate,parsingPos);
            else if (m_SubstitutionTable[tablePos].Type==MED_HTML_SUBSTITUTION_BLOCK_ARRAY)
            {
                int actualParsingPos=parsingPos;
                for (int i=0; i<m_LoopsNumber; i++)
                {
                    //Every sub block must be parsed, each loop parsing pos will be increased so we need to
                    //move the parsing pos back in order to parse the same text to each loop
                    parsingPos=actualParsingPos;
                    int x=m_SubBlocksArray[blockPos].size();
                    medHTMLTemplateParserBlock *blockPointer=m_SubBlocksArray[blockPos][i];
                    blockPointer->PreParse(inputTemplate,parsingPos);
                }
            }
            else if (m_SubstitutionTable[tablePos].Type=MED_HTML_SUBSTITUTION_FORWARD_UP)
            {
                mafLogMessage("Tag Name already used");
                return false;
            }
        }

    }
    //CLOSING TAG
    else if (SubStringCompare(inputTemplate,MED_HTML_TAG_CLOSING,parsingPos))
    {
        parsingPos+=Strlen(MED_HTML_TAG_CLOSING);

        if (SubStringCompare(inputTemplate,MED_HTML_TAG_LOOP,parsingPos))
        {
            parsingPos+=Strlen(MED_HTML_TAG_LOOP);
            if (m_BlockType!=MED_HTML_TEMPLATE_LOOP)
                mafLogMessage("medHTMLTemplateParserBlock: Invalid closing TAG Type");
        }
        else if (SubStringCompare(inputTemplate,MED_HTML_TAG_IF,parsingPos))
        {
            parsingPos+=Strlen(MED_HTML_TAG_IF);
            if (m_BlockType!=MED_HTML_TEMPLATE_IF)
                mafLogMessage("medHTMLTemplateParserBlock: Invalid closing TAG Type");
            //if there is not an ELSE TAG the if char are all chars now
            if (m_IfChars==0)
                m_IfChars=m_PreParsedHTML.size();
        }
        else
            mafLogMessage("medHTMLTemplateParserBlock: Invalid TAG Type");

        ReadTagName(inputTemplate,parsingPos,tagName);


        int comp=tagName.Cmp(m_BlockName);

        if (comp!=0)
            mafLogMessage("medHTMLTemplateParserBlock: warning wrong closing tag");

        return comp;
    }
    else
    {
        //there is a '[' char but there is not a MAF tag
        //in this case the input must be copied to pre parsed string
        //we add '[' char to m_PreParsedHTML and increase parsingPos
        //in order to avoid a non ending loop in the caller function
        m_PreParsedHTML.Append("[");
        parsingPos++;
    }

    //continue parsing
    return true;
}
Example #7
0
PAL_Uint32 THREAD_API fireindication(void* param)
{
    Config* config = (Config*)param;
    MI_Result r = MI_RESULT_OK;
    MI_Uint32 failAfterCount = config->failAfterCount;
    MI_Result failResult = config->failResult;

    Atomic_Swap( &config->threadrunning, 1);
    LOGMSG(("Set threadrunning to 1 for config (%p)", config));

    config->count = 0;
    LOGMSG(("Start to fireindication for class (%s)", config->className));

    /* wait for the semaphore */
    LOGMSG(("Wait for semaphore to fire indication"));
    Sem_Wait(&config->sem);
    LOGMSG(("Received semaphore and start firing indication"));

    if (config->testGroup == (MI_Uint32)TestGroup_Misc)
    {
        switch (config->miscTestSubGroup)
        {
        case MiscTestGroup_GetExpression:
        case MiscTestGroup_Evaluate:
        case MiscTestGroup_SelfTest:
            failAfterCount = 1;
            failResult = MI_RESULT_FAILED;
            break;
        default:
            break;
        }
    }

    while((MI_FALSE == config->disabled) && (config->count < failAfterCount))
    {
        config->count++;

        if (config->intervalMS > 0)
        {
            Sleep_Milliseconds(config->intervalMS);
        }
        if (r!= MI_RESULT_OK)
        {
            LOGMSG(("Set property value of indication failed (%d); Ignore #%d indication", r, config->count));
            continue;
        }
        if (config->lifecycleThreadControl == 0)
        {
            const MI_Char* bookmark = NULL;

            DEBUG_ASSERT( NULL != config->setprop );
            r = config->setprop(config->context, &config->indication);
            if (r == MI_RESULT_OK)
            {
                DEBUG_ASSERT( NULL != config->indication );

                if (config->subscribeBookmark &&
                    0 < Strlen(config->subscribeBookmark) &&
                    0 != Strcmp(config->subscribeBookmark, "."))
                {
                    // Only set bookmark if it is non-NULL and non-default
                    bookmark = ansiToMI(config->subscribeBookmark);
                }
                r = MI_Context_PostIndication(config->postctx, config->indication, 0, bookmark);
                if (r!= MI_RESULT_OK)
                {
                    LOGMSG(("Post #%d Indication failed (%d)", config->count, r));
                }

                /* Delete indication instance */
                MI_Instance_Delete( config->indication );
                config->indication = NULL;
            }
            else
            {
                LOGMSG(("config(%p:%s)->setprop failed to create indication instance(%d)", config, config->className, r));
            }
        }
        else
        {
            if (config->lifecycleContext && config->currentSubscriptionTypes != 0 && config->supportedSubscriptionTypes != 0)
            {
                // lifeCycleThreadControl other than 0 and a running thread indicates that we should schedule lifecycle events
                if (config->lifecycleThreadControl & MI_LIFECYCLE_INDICATION_CREATE)
                {
                    r = lifecycle_CreateInstance(config, config->lifecycleInstance);
                    if (r != MI_RESULT_OK)
                    {
                        LOGMSG(("Lifecycle_CreateInstance for class (%s) failed with result (%d)", config->className, r));
                    }
                }
                if (config->lifecycleThreadControl & MI_LIFECYCLE_INDICATION_MODIFY)
                {
                    r = lifecycle_ModifyInstance(config->lifecycleInstance, config);
                    if (r != MI_RESULT_OK)
                    {
                        LOGMSG(("Lifecycle_ModifyInstance for class (%s) failed with result (%d)", config->className, r));
                    }
                }
                if (config->lifecycleThreadControl & MI_LIFECYCLE_INDICATION_DELETE)
                {
                    r = lifecycle_DeleteInstance(config);
                    if (r != MI_RESULT_OK)
                    {
                        LOGMSG(("Lifecycle_DeleteInstance for class (%s) failed with result (%d)", config->className, r));
                    }
                }
                if (config->lifecycleThreadControl & MI_LIFECYCLE_INDICATION_READ)
                {
                    r = lifecycle_EnumerateInstances(config);
                    if (r != MI_RESULT_OK)
                    {
                        LOGMSG(("Lifecycle_EnumerateInstances for class (%s) failed with result (%d)", config->className, r));
                    }
                }
                if (config->lifecycleThreadControl & MI_LIFECYCLE_INDICATION_METHODCALL)
                {
                    r = lifecycle_InvokeMethod(config);
                    if (r != MI_RESULT_OK)
                    {
                        LOGMSG(("Lifecycle_InvokeMethod for class (%s) failed with result (%d)", config->className, r));
                    }
                }
            }
        }
        LOGMSG(("Fired #%d indication for class (%s)", config->count, config->className));
    }

    Atomic_Swap( &config->threadrunning, 0);
    LOGMSG(("Set threadrunning to 0 for config (%p)", config));

    if (MI_FALSE == config->disabled)
    {
        LOGMSG(("fireindication stopped due to class (%s) need to fail after firing (%d) indicaitons", config->className, failAfterCount));
#if !defined(_MSC_VER)
        // if not joined yet, release thread resources
        pthread_detach(config->thread.__impl);
# endif
        if (failResult != MI_RESULT_OK)
        {
            if (config->lifecycleThreadControl == 0)
            {
                MI_Context_PostResult(config->postctx, failResult);
            }
            else
            {
                MI_LifecycleIndicationContext_PostResult(config->lifecycleContext, failResult);
            }
            LOGMSG(("Stop the fireindication and failed the operation with error (%s:%d)", config->className, failResult));
        }
    }
    else
        LOGMSG(("fireindication stopped due to disable indication called"));
    LOGMSG(("Done fireindication for class (%s)", config->className));
    return 0;
}
Example #8
0
//******
//oprator+=
//character
//******
Z_String& Z_String::operator += ( const INT8 *cStr ) {
	Concat( Strlen( cStr ), cStr );
	return *this;
}
Example #9
0
//******
//Constructor
//from c-string
//******
Z_String::Z_String( const INT8 *cStr ) {
	const int l = Strlen( cStr );
	if ( l > 0 ) {
		Concat( l, cStr );
	}
}
Example #10
0
/*######################################################################
 *##
 *## NAME:  HttpGetFileEx
 *##
 *## PURPOSE:  Return headers and body of a http request 
 *##
 *####################################################################*/
int API4U HttpGetFileEx( 
                   LPCSTR szURL, 
                   LPCSTR szProxyURL, 
                   LPCSTR szLocalFile,
                   LPCSTR szHeaderFile,
                   HTTP4U_CALLBACK CbkTransmit,
                   long   lUserValue,
                   LPSTR  szResponse, int nResponseSize,
                   LPSTR  szHeaders,  int nHeadersSize
                   )
{
SOCKET  CSock = INVALID_SOCKET;
int     Rc;
int     hHeaderFile = HFILE_ERROR;
char    szService[SERVICE_LENGTH];
char    szHost[HOST_LENGTH];
char    szFichier[FILE_LENGTH];
LPSTR   szData = NULL;
LPSTR   p;
LPCSTR  szRequest;
long    RealBodySize = -1;

struct S_HttpStatus saRespStatus;
unsigned short usPort = 0;

   Tcp4uLog (LOG4U_HIPROC, "HttpGetFileEx");

#define XX_RETURN(a) {if (szData!=NULL) Free(szData);\
                     if (hHeaderFile!=HFILE_ERROR){\
                        Close(hHeaderFile);\
                        Unlink(szHeaderFile);\
                     }\
                     if (CSock != INVALID_SOCKET) TcpClose(&CSock);\
				     Tcp4uLog (LOG4U_HIEXIT, "HttpGetFileEx with return code %d", a); \
                     return a;\
                     }
#ifdef UNIX
  /* use "hidden" env variable in order to send logs to stdout       */
  if (getenv ("http4u_log")!=NULL)   DO_NOT_LOG = fileno(stdout);
#endif

  /* control URL's validity and receive URL's components. If a proxy */
  /* is used, send the connection components into usPort, szService  */
  /* and szHost.                                                     */
  if (     ! HttpIsValidURL(  szURL,
                            & usPort,
                              szService, sizeof szService ,
                              szHost, sizeof szHost ,
                              szFichier, sizeof szFichier )
       ||  (     szProxyURL!=NULL   
             &&  ! HttpIsValidURL (szProxyURL, & usPort, 
                                   szService, sizeof szService,
                                   szHost, sizeof szHost, NULL, 0))
     )
   {
      XX_RETURN (HTTP4U_BAD_URL);
   }

   /* allocate buffer */
   if ( (szData = Calloc(1,s_uHttp4uBufferSize)) == NULL) 
   {
     XX_RETURN (HTTP4U_INSMEMORY);
   } 

   /* connect to http server, or proxy server : we don't care now */
   Rc = TcpConnect(& CSock,
                      szHost,
                      usPort==0 ? szService : NULL,
                    & usPort);
  switch (Rc)
  {
     case TCP4U_SUCCESS     :  break;  /* continue */
     case TCP4U_HOSTUNKNOWN :  XX_RETURN (HTTP4U_HOST_UNKNOWN);
     default                :  XX_RETURN (HTTP4U_TCP_CONNECT);
  }

   /* send a request-line method "GET", receive reply, receive data */
   szRequest= szProxyURL==NULL? szFichier : szURL; /* if no proxy, simple ! */
   if (   (Rc=HttpSendRequest10  (CSock, "GET ", szRequest)) != HTTP4U_SUCCESS
       || (Rc=HttpRecvRespStatus (CSock, & saRespStatus, 
                                  szResponse,nResponseSize)) != HTTP4U_SUCCESS )
   {
      XX_RETURN (Rc);
    }

   /* an answer has been received, let us have a look on it */
   switch(saRespStatus.code) 
   {
       case 200: break; /* reason-phrase OK */ 
       case 204: XX_RETURN (HTTP4U_NO_CONTENT);
       case 300:
       case 301: XX_RETURN (HTTP4U_MOVED);
       case 400: XX_RETURN (HTTP4U_BAD_REQUEST);
       case 401:
       case 403: XX_RETURN (HTTP4U_FORBIDDEN);
       case 404: XX_RETURN (HTTP4U_NOT_FOUND);
       default:  XX_RETURN (HTTP4U_PROTOCOL_ERROR);
   }

   /* read headers */
   Rc = HttpRecvHeaders10(CSock, szData, s_uHttp4uBufferSize);
   /* copy headers into user buffer even if return incorrect */
   if (szHeaders != NULL) 
     Strcpyn (szHeaders, szData, min(s_uHttp4uBufferSize, (unsigned) nHeadersSize));

   if (Rc!=HTTP4U_SUCCESS)     XX_RETURN (Rc);

   /* write headers into the user local file */
  if (szHeaderFile != NULL ) 
  {
    if ((hHeaderFile = Open(szHeaderFile, WRITE_CR)) == HFILE_ERROR) 
    {
       XX_RETURN (HTTP4U_FILE_ERROR);
    }
    /* write */
    if (Write(hHeaderFile, szData, Strlen(szData)) == HFILE_ERROR) 
    {
        XX_RETURN(HTTP4U_FILE_ERROR);
    }
    Close(hHeaderFile);
    hHeaderFile = HFILE_ERROR;
  } /* szHeaderFile not NULL */

  /* if we do not need something else, just close the connection */
  /* not really nice, but HTTP servers are used to deal with it  */ 
  if (szLocalFile==NULL  &&  CbkTransmit==NULL) 
  {
     XX_RETURN (HTTP4U_SUCCESS);
  }

  /* search real length of the body */ 
  RealBodySize = -1;         /* can not compute it */
  szData[s_uHttp4uBufferSize-1] = '\0';
  p = Tcp4uStrIStr (szData, "content-length:");
  if (p!=NULL) 
  {
    p += sizeof("Content-Length:");
    while (isspace(*p)) p++;  /* skip space character */
    RealBodySize = Tcp4uAtol (p);
  }
    
  /* read Body of the respons */
  Rc=TcpRecvUntilClosedEx (& CSock,
                             szLocalFile,
                             (FARPROC) CbkTransmit,
                             s_uHttp4uTimeout,
                             s_uHttp4uBufferSize,
                             lUserValue,
                             RealBodySize);

  switch (Rc)
  {
    case TCP4U_SUCCESS:     Rc = HTTP4U_SUCCESS;    break; 
    case TCP4U_TIMEOUT:     Rc = HTTP4U_TIMEOUT;    break; 
    case TCP4U_FILE_ERROR : Rc = HTTP4U_FILE_ERROR; break; 
    case TCP4U_INSMEMORY :  Rc = HTTP4U_INSMEMORY;  break; 
    case TCP4U_CANCELLED :  Rc = HTTP4U_CANCELLED;  break; 
    default:                Rc = HTTP4U_TCP_FAILED; break; 
                                                                           
  }
XX_RETURN (Rc);
#undef XX_RETURN
} /* HttpGetFileEx */
Example #11
0
void
execute(struct command *t, int wanttty, int *pipein, int *pipeout)
{
    bool    forked = 0;
    struct biltins *bifunc;
    int     pid = 0;
    int     pv[2];
    sigset_t sigset;

    static sigset_t csigset;

    static sigset_t ocsigset;
    static int onosigchld = 0;
    static int nosigchld = 0;

    UNREGISTER(forked);
    UNREGISTER(bifunc);
    UNREGISTER(wanttty);

    if (t == 0)
	return;

    if (t->t_dflg & F_AMPERSAND)
	wanttty = 0;
    switch (t->t_dtyp) {

    case NODE_COMMAND:
	if ((t->t_dcom[0][0] & (QUOTE | TRIM)) == QUOTE)
	    (void) memmove(t->t_dcom[0], t->t_dcom[0] + 1,
		(Strlen(t->t_dcom[0] + 1) + 1) * sizeof(Char));
	if ((t->t_dflg & F_REPEAT) == 0)
	    Dfix(t);		/* $ " ' \ */
	if (t->t_dcom[0] == 0)
	    return;
	/* fall into... */

    case NODE_PAREN:
	if (t->t_dflg & F_PIPEOUT)
	    mypipe(pipeout);
	/*
	 * Must do << early so parent will know where input pointer should be.
	 * If noexec then this is all we do.
	 */
	if (t->t_dflg & F_READ) {
	    (void) close(0);
	    heredoc(t->t_dlef);
	    if (noexec)
		(void) close(0);
	}

	set(STRstatus, Strsave(STR0));

	/*
	 * This mess is the necessary kludge to handle the prefix builtins:
	 * nice, nohup, time.  These commands can also be used by themselves,
	 * and this is not handled here. This will also work when loops are
	 * parsed.
	 */
	while (t->t_dtyp == NODE_COMMAND)
	    if (eq(t->t_dcom[0], STRnice))
		if (t->t_dcom[1])
		    if (strchr("+-", t->t_dcom[1][0]))
			if (t->t_dcom[2]) {
			    setname("nice");
			    t->t_nice =
				getn(t->t_dcom[1]);
			    lshift(t->t_dcom, 2);
			    t->t_dflg |= F_NICE;
			}
			else
			    break;
		    else {
			t->t_nice = 4;
			lshift(t->t_dcom, 1);
			t->t_dflg |= F_NICE;
		    }
		else
		    break;
	    else if (eq(t->t_dcom[0], STRnohup))
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_NOHUP;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    else if (eq(t->t_dcom[0], STRtime))
		if (t->t_dcom[1]) {
		    t->t_dflg |= F_TIME;
		    lshift(t->t_dcom, 1);
		}
		else
		    break;
	    else
		break;

	/* is it a command */
	if (t->t_dtyp == NODE_COMMAND) {
	    /*
	     * Check if we have a builtin function and remember which one.
	     */
	    bifunc = isbfunc(t);
	    if (noexec) {
		/*
		 * Continue for builtins that are part of the scripting language
		 */
		if (bifunc &&
		    bifunc->bfunct != dobreak   && bifunc->bfunct != docontin &&
		    bifunc->bfunct != doelse    && bifunc->bfunct != doend    &&
		    bifunc->bfunct != doforeach && bifunc->bfunct != dogoto   &&
		    bifunc->bfunct != doif      && bifunc->bfunct != dorepeat &&
		    bifunc->bfunct != doswbrk   && bifunc->bfunct != doswitch &&
		    bifunc->bfunct != dowhile   && bifunc->bfunct != dozip)
		    break;
	    }
	}
	else {			/* not a command */
	    bifunc = NULL;
	    if (noexec)
		break;
	}

	/*
	 * We fork only if we are timed, or are not the end of a parenthesized
	 * list and not a simple builtin function. Simple meaning one that is
	 * not pipedout, niced, nohupped, or &'d. It would be nice(?) to not
	 * fork in some of these cases.
	 */
	/*
	 * Prevent forking cd, pushd, popd, chdir cause this will cause the
	 * shell not to change dir!
	 */
	if (bifunc && (bifunc->bfunct == dochngd ||
		       bifunc->bfunct == dopushd ||
		       bifunc->bfunct == dopopd))
	    t->t_dflg &= ~(F_NICE);
	if (((t->t_dflg & F_TIME) || ((t->t_dflg & F_NOFORK) == 0 &&
	     (!bifunc || t->t_dflg &
	      (F_PIPEOUT | F_AMPERSAND | F_NICE | F_NOHUP)))) ||
	/*
	 * We have to fork for eval too.
	 */
	    (bifunc && (t->t_dflg & (F_PIPEIN | F_PIPEOUT)) != 0 &&
	     bifunc->bfunct == doeval)) {
	    if (t->t_dtyp == NODE_PAREN ||
		t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc) {
		forked++;
		/*
		 * We need to block SIGCHLD here, so that if the process does
		 * not die before we can set the process group
		 */
		if (wanttty >= 0 && !nosigchld) {
		    sigemptyset(&sigset);
		    sigaddset(&sigset, SIGCHLD);
		    sigprocmask(SIG_BLOCK, &sigset, &csigset);
		    nosigchld = 1;
		}

		pid = pfork(t, wanttty);
		if (pid == 0 && nosigchld) {
		    sigprocmask(SIG_SETMASK, &csigset, NULL);
		    nosigchld = 0;
		}
		else if (pid != 0 && (t->t_dflg & F_AMPERSAND))
		    backpid = pid;

	    }
	    else {
		int     ochild, osetintr, ohaderr, odidfds;
		int     oSHIN, oSHOUT, oSHERR, oOLDSTD, otpgrp;
		sigset_t osigset;

		/*
		 * Prepare for the vfork by saving everything that the child
		 * corrupts before it exec's. Note that in some signal
		 * implementations which keep the signal info in user space
		 * (e.g. Sun's) it will also be necessary to save and restore
		 * the current sigaction's for the signals the child touches
		 * before it exec's.
		 */
		if (wanttty >= 0 && !nosigchld && !noexec) {
		    sigemptyset(&sigset);
		    sigaddset(&sigset, SIGCHLD);
		    sigprocmask(SIG_BLOCK, &sigset, &csigset);
		    nosigchld = 1;
		}
		sigemptyset(&sigset);
		sigaddset(&sigset, SIGCHLD);
		sigaddset(&sigset, SIGINT);
		sigprocmask(SIG_BLOCK, &sigset, &osigset);
		ochild = child;
		osetintr = setintr;
		ohaderr = haderr;
		odidfds = didfds;
		oSHIN = SHIN;
		oSHOUT = SHOUT;
		oSHERR = SHERR;
		oOLDSTD = OLDSTD;
		otpgrp = tpgrp;
		ocsigset = csigset;
		onosigchld = nosigchld;
		Vsav = Vdp = 0;
		Vexpath = 0;
		Vt = 0;
		pid = vfork();

		if (pid < 0) {
		    sigprocmask(SIG_SETMASK, &osigset, NULL);
		    stderror(ERR_NOPROC);
		}
		forked++;
		if (pid) {	/* parent */
		    child = ochild;
		    setintr = osetintr;
		    haderr = ohaderr;
		    didfds = odidfds;
		    SHIN = oSHIN;
		    SHOUT = oSHOUT;
		    SHERR = oSHERR;
		    OLDSTD = oOLDSTD;
		    tpgrp = otpgrp;
		    csigset = ocsigset;
		    nosigchld = onosigchld;

		    xfree((ptr_t) Vsav);
		    Vsav = 0;
		    xfree((ptr_t) Vdp);
		    Vdp = 0;
		    xfree((ptr_t) Vexpath);
		    Vexpath = 0;
		    blkfree((Char **) Vt);
		    Vt = 0;
		    /* this is from pfork() */
		    palloc(pid, t);
		    sigprocmask(SIG_SETMASK, &osigset, NULL);
		}
		else {		/* child */
		    /* this is from pfork() */
		    int     pgrp;
		    bool    ignint = 0;

		    if (nosigchld) {
			sigprocmask(SIG_SETMASK, &csigset, NULL);
			nosigchld = 0;
		    }

		    if (setintr)
			ignint =
			    (tpgrp == -1 &&
			     (t->t_dflg & F_NOINTERRUPT))
			    || (gointr && eq(gointr, STRminus));
		    pgrp = pcurrjob ? pcurrjob->p_jobid : getpid();
		    child++;
		    if (setintr) {
			setintr = 0;
			if (ignint) {
			    (void) signal(SIGINT, SIG_IGN);
			    (void) signal(SIGQUIT, SIG_IGN);
			}
			else {
			    (void) signal(SIGINT, vffree);
			    (void) signal(SIGQUIT, SIG_DFL);
			}

			if (wanttty >= 0) {
			    (void) signal(SIGTSTP, SIG_DFL);
			    (void) signal(SIGTTIN, SIG_DFL);
			    (void) signal(SIGTTOU, SIG_DFL);
			}

			(void) signal(SIGTERM, parterm);
		    }
		    else if (tpgrp == -1 &&
			     (t->t_dflg & F_NOINTERRUPT)) {
			(void) signal(SIGINT, SIG_IGN);
			(void) signal(SIGQUIT, SIG_IGN);
		    }

		    pgetty(wanttty, pgrp);
		    if (t->t_dflg & F_NOHUP)
			(void) signal(SIGHUP, SIG_IGN);
		    if (t->t_dflg & F_NICE)
			(void) setpriority(PRIO_PROCESS, 0, t->t_nice);
		}

	    }
	}
	if (pid != 0) {
	    /*
	     * It would be better if we could wait for the whole job when we
	     * knew the last process had been started.  Pwait, in fact, does
	     * wait for the whole job anyway, but this test doesn't really
	     * express our intentions.
	     */
	    if (didfds == 0 && t->t_dflg & F_PIPEIN) {
		(void) close(pipein[0]);
		(void) close(pipein[1]);
	    }
	    if ((t->t_dflg & F_PIPEOUT) == 0) {
		if (nosigchld) {
		    sigprocmask(SIG_SETMASK, &csigset, NULL);
		    nosigchld = 0;
		}
		if ((t->t_dflg & F_AMPERSAND) == 0)
		    pwait();
	    }
	    break;
	}
	doio(t, pipein, pipeout);
	if (t->t_dflg & F_PIPEOUT) {
	    (void) close(pipeout[0]);
	    (void) close(pipeout[1]);
	}
	/*
	 * Perform a builtin function. If we are not forked, arrange for
	 * possible stopping
	 */
	if (bifunc) {
	    func(t, bifunc);
	    if (forked)
		exitstat();
	    break;
	}
	if (t->t_dtyp != NODE_PAREN) {
	    doexec(NULL, t);
	    /* NOTREACHED */
	}
	/*
	 * For () commands must put new 0,1,2 in FSH* and recurse
	 */
	OLDSTD = dcopy(0, FOLDSTD);
	SHOUT = dcopy(1, FSHOUT);
	SHERR = dcopy(2, FSHERR);
	(void) close(SHIN);
	SHIN = -1;
	didfds = 0;
	wanttty = -1;
	t->t_dspr->t_dflg |= t->t_dflg & F_NOINTERRUPT;
	execute(t->t_dspr, wanttty, NULL, NULL);
	exitstat();

    case NODE_PIPE:
	t->t_dcar->t_dflg |= F_PIPEOUT |
	    (t->t_dflg & (F_PIPEIN | F_AMPERSAND | F_STDERR | F_NOINTERRUPT));
	execute(t->t_dcar, wanttty, pipein, pv);
	t->t_dcdr->t_dflg |= F_PIPEIN | (t->t_dflg &
			(F_PIPEOUT | F_AMPERSAND | F_NOFORK | F_NOINTERRUPT));
	if (wanttty > 0)
	    wanttty = 0;	/* got tty already */
	execute(t->t_dcdr, wanttty, pv, pipeout);
	break;

    case NODE_LIST:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & F_NOINTERRUPT;
	    execute(t->t_dcar, wanttty, NULL, NULL);
	    /*
	     * In strange case of A&B make a new job after A
	     */
	    if (t->t_dcar->t_dflg & F_AMPERSAND && t->t_dcdr &&
		(t->t_dcdr->t_dflg & F_AMPERSAND) == 0)
		pendjob();
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT);
	    execute(t->t_dcdr, wanttty, NULL, NULL);
	}
	break;

    case NODE_OR:
    case NODE_AND:
	if (t->t_dcar) {
	    t->t_dcar->t_dflg |= t->t_dflg & F_NOINTERRUPT;
	    execute(t->t_dcar, wanttty, NULL, NULL);
	    if ((getn(value(STRstatus)) == 0) !=
		(t->t_dtyp == NODE_AND))
		return;
	}
	if (t->t_dcdr) {
	    t->t_dcdr->t_dflg |= t->t_dflg &
		(F_NOFORK | F_NOINTERRUPT);
	    execute(t->t_dcdr, wanttty, NULL, NULL);
	}
	break;
    }
    /*
     * Fall through for all breaks from switch
     *
     * If there will be no more executions of this command, flush all file
     * descriptors. Places that turn on the F_REPEAT bit are responsible for
     * doing donefds after the last re-execution
     */
    if (didfds && !(t->t_dflg & F_REPEAT))
	donefds();
}
Example #12
0
File: tw.comp.c Project: lukem/tcsh
/* tw_complete():
 *	Return the appropriate completion for the command
 *
 *	valid completion strings are:
 *	p/<range>/<completion>/[<suffix>/]	positional
 *	c/<pattern>/<completion>/[<suffix>/]	current word ignore pattern
 *	C/<pattern>/<completion>/[<suffix>/]	current word with pattern
 *	n/<pattern>/<completion>/[<suffix>/]	next word
 *	N/<pattern>/<completion>/[<suffix>/]	next-next word
 */
int
tw_complete(const Char *line, Char **word, Char **pat, int looking, eChar *suf)
{
    Char *buf, **vec, **wl;
    static Char nomatch[2] = { (Char) ~0, 0x00 };
    const Char *ptr;
    size_t wordno;
    int n;

    buf = Strsave(line);
    cleanup_push(buf, xfree);
    /* Single-character words, empty current word, terminating NULL */
    wl = xmalloc(((Strlen(line) + 1) / 2 + 2) * sizeof (*wl));
    cleanup_push(wl, xfree);

    /* find the command */
    if ((wl[0] = tw_tok(buf)) == NULL || wl[0] == INVPTR) {
	cleanup_until(buf);
	return TW_ZERO;
    }

    /*
     * look for hardwired command completions using a globbing
     * search and for arguments using a normal search.
     */
    if ((vec = tw_find(wl[0], &completions, (looking == TW_COMMAND)))
	== NULL) {
	cleanup_until(buf);
	return looking;
    }

    /* tokenize the line one more time :-( */
    for (wordno = 1; (wl[wordno] = tw_tok(NULL)) != NULL &&
		      wl[wordno] != INVPTR; wordno++)
	continue;

    if (wl[wordno] == INVPTR) {		/* Found a meta character */
	cleanup_until(buf);
	return TW_ZERO;			/* de-activate completions */
    }
#ifdef TDEBUG
    {
	size_t i;
	for (i = 0; i < wordno; i++)
	    xprintf("'%s' ", short2str(wl[i]));
	xprintf("\n");
    }
#endif /* TDEBUG */

    /* if the current word is empty move the last word to the next */
    if (**word == '\0') {
	wl[wordno] = *word;
	wordno++;
    }
    wl[wordno] = NULL;
	

#ifdef TDEBUG
    xprintf("\r\n");
    xprintf("  w#: %lu\n", (unsigned long)wordno);
    xprintf("line: %s\n", short2str(line));
    xprintf(" cmd: %s\n", short2str(wl[0]));
    xprintf("word: %s\n", short2str(*word));
    xprintf("last: %s\n", wordno >= 2 ? short2str(wl[wordno-2]) : "n/a");
    xprintf("this: %s\n", wordno >= 1 ? short2str(wl[wordno-1]) : "n/a");
#endif /* TDEBUG */
    
    for (;vec != NULL && (ptr = vec[0]) != NULL; vec++) {
	Char  *ran,	        /* The pattern or range X/<range>/XXXX/ */
	      *com,	        /* The completion X/XXXXX/<completion>/ */
	     *pos = NULL;	/* scratch pointer 			*/
	int   cmd, res;
        Char  sep;		/* the command and separator characters */
	int   exact;

	if (ptr[0] == '\0')
	    continue;

#ifdef TDEBUG
	xprintf("match %s\n", short2str(ptr));
#endif /* TDEBUG */

	switch (cmd = ptr[0]) {
	case 'N':
	    pos = (wordno < 3) ? nomatch : wl[wordno - 3];
	    break;
	case 'n':
	    pos = (wordno < 2) ? nomatch : wl[wordno - 2];
	    break;
	case 'c':
	case 'C':
	    pos = (wordno < 1) ? nomatch : wl[wordno - 1];
	    break;
	case 'p':
	    break;
	default:
	    stderror(ERR_COMPINV, CGETS(27, 1, "command"), cmd);
	    return TW_ZERO;
	}

	sep = ptr[1];
	if (!Ispunct(sep)) {
	    /* Truncates data if WIDE_STRINGS */
	    stderror(ERR_COMPINV, CGETS(27, 2, "separator"), (int)sep);
	    return TW_ZERO;
	}

	ptr = tw_dollar(&ptr[2], wl, wordno, &ran, sep,
			CGETS(27, 3, "pattern"));
	cleanup_push(ran, xfree);
	if (ran[0] == '\0')	/* check for empty pattern (disallowed) */
	{
	    stderror(ERR_COMPINC, cmd == 'p' ?  CGETS(27, 4, "range") :
		     CGETS(27, 3, "pattern"), "");
	    return TW_ZERO;
	}

	ptr = tw_dollar(ptr, wl, wordno, &com, sep,
			CGETS(27, 5, "completion"));
	cleanup_push(com, xfree);

	if (*ptr != '\0') {
	    if (*ptr == sep)
		*suf = CHAR_ERR;
	    else
		*suf = *ptr;
	}
	else
	    *suf = '\0';

#ifdef TDEBUG
	xprintf("command:    %c\nseparator:  %c\n", cmd, (int)sep);
	xprintf("pattern:    %s\n", short2str(ran));
	xprintf("completion: %s\n", short2str(com));
	xprintf("suffix:     ");
        switch (*suf) {
	case 0:
	    xprintf("*auto suffix*\n");
	    break;
	case CHAR_ERR:
	    xprintf("*no suffix*\n");
	    break;
	default:
	    xprintf("%c\n", (int)*suf);
	    break;
	}
#endif /* TDEBUG */

	exact = 0;
	switch (cmd) {
	case 'p':			/* positional completion */
#ifdef TDEBUG
	    xprintf("p: tw_pos(%s, %lu) = ", short2str(ran),
		    (unsigned long)wordno - 1);
	    xprintf("%d\n", tw_pos(ran, wordno - 1));
#endif /* TDEBUG */
	    if (!tw_pos(ran, wordno - 1)) {
		cleanup_until(ran);
		continue;
	    }
	    break;

	case 'N':			/* match with the next-next word */
	case 'n':			/* match with the next word */
	    exact = 1;
	    /*FALLTHROUGH*/
	case 'c':			/* match with the current word */
	case 'C':
#ifdef TDEBUG
	    xprintf("%c: ", cmd);
#endif /* TDEBUG */
	    if ((n = tw_match(pos, ran, exact)) < 0) {
		cleanup_until(ran);
		continue;
	    }
	    if (cmd == 'c')
		*word += n;
	    break;

	default:
	    abort();		       /* Cannot happen */
	}
	tsetenv(STRCOMMAND_LINE, line);
	res = tw_result(com, pat);
	Unsetenv(STRCOMMAND_LINE);
	cleanup_until(buf);
	return res;
    }
    cleanup_until(buf);
    *suf = '\0';
    return TW_ZERO;
} /* end tw_complete */
Example #13
0
static void
setDolp(Char *cp)
{
    Char *dp;
    size_t i;

    if (dolmod.len == 0 || dolmcnt == 0) {
	dolp = cp;
	return;
    }
    cp = Strsave(cp);
    for (i = 0; i < dolmod.len; i++) {
	int didmod = 0;

	/* handle s// [eichin:19910926.0510EST] */
	if(dolmod.s[i] == 's') {
	    Char delim;
	    Char *lhsub, *rhsub, *np;
	    size_t lhlen = 0, rhlen = 0;

	    delim = dolmod.s[++i];
	    if (!delim || letter(delim)
		|| Isdigit(delim) || any(" \t\n", delim)) {
		seterror(ERR_BADSUBST);
		break;
	    }
	    lhsub = &dolmod.s[++i];
	    while(dolmod.s[i] != delim && dolmod.s[++i]) {
		lhlen++;
	    }
	    dolmod.s[i] = 0;
	    rhsub = &dolmod.s[++i];
	    while(dolmod.s[i] != delim && dolmod.s[++i]) {
		rhlen++;
	    }
	    dolmod.s[i] = 0;

	    strip(lhsub);
	    strip(rhsub);
	    strip(cp);
	    dp = cp;
	    do {
		dp = Strstr(dp, lhsub);
		if (dp) {
		    ptrdiff_t diff = dp - cp;
		    size_t len = (Strlen(cp) + 1 - lhlen + rhlen);
		    np = xmalloc(len * sizeof(Char));
		    (void) Strncpy(np, cp, diff);
		    (void) Strcpy(np + diff, rhsub);
		    (void) Strcpy(np + diff + rhlen, dp + lhlen);

		    dp = np + diff + 1;
		    xfree(cp);
		    cp = np;
		    cp[--len] = '\0';
		    didmod = 1;
		    if (diff >= len)
			break;
		} else {
		    /* should this do a seterror? */
		    break;
		}
	    }
	    while (dol_flag_a != 0);
	    /*
	     * restore dolmod for additional words
	     */
	    dolmod.s[i] = rhsub[-1] = (Char) delim;
        } else {

	    do {
		if ((dp = domod(cp, dolmod.s[i])) != NULL) {
		    didmod = 1;
		    if (Strcmp(cp, dp) == 0) {
			xfree(cp);
			cp = dp;
			break;
		    }
		    else {
			xfree(cp);
			cp = dp;
		    }
		}
		else
		    break;
	    }
	    while (dol_flag_a != 0);
	}
	if (didmod && dolmcnt != INT_MAX)
	    dolmcnt--;
#ifdef notdef
	else
	    break;
#endif
    }

    addla(cp);

    dolp = STRNULL;
    if (seterr)
	stderror(ERR_OLD);
}
Example #14
0
/*
 * Handle the multitudinous $ expansion forms.
 * Ugh.
 */
static void
Dgetdol(void)
{
    Char *np;
    struct varent *vp = NULL;
    struct Strbuf *name = Strbuf_alloc();
    eChar   c, sc;
    int     subscr = 0, lwb = 1, upb = 0;
    int    dimen = 0, bitset = 0, length = 0;
    static Char *dolbang = NULL;

    cleanup_push(name, Strbuf_free);
    dolmod.len = dolmcnt = dol_flag_a = 0;
    c = sc = DgetC(0);
    if (c == DEOF) {
      stderror(ERR_SYNTAX);
      return;
    }
    if (c == '{')
	c = DgetC(0);		/* sc is { to take } later */
    if ((c & TRIM) == '#')
	dimen++, c = DgetC(0);	/* $# takes dimension */
    else if (c == '?')
	bitset++, c = DgetC(0);	/* $? tests existence */
    else if (c == '%')
	length++, c = DgetC(0); /* $% returns length in chars */
    switch (c) {

    case '!':
	if (dimen || bitset || length)
	    stderror(ERR_SYNTAX);
	if (backpid != 0) {
	    xfree(dolbang);
	    setDolp(dolbang = putn(backpid));
	}
	cleanup_until(name);
	goto eatbrac;

    case '$':
	if (dimen || bitset || length)
	    stderror(ERR_SYNTAX);
	setDolp(doldol);
	cleanup_until(name);
	goto eatbrac;

    case '<'|QUOTE: {
	static struct Strbuf wbuf; /* = Strbuf_INIT; */

	if (bitset)
	    stderror(ERR_NOTALLOWED, "$?<");
	if (dimen)
	    stderror(ERR_NOTALLOWED, "$#<");
	if (length)
	    stderror(ERR_NOTALLOWED, "$%<");
	wbuf.len = 0;
	{
	    char cbuf[MB_LEN_MAX];
	    size_t cbp = 0;
	    int old_pintr_disabled;

	    for (;;) {
	        int len;
		ssize_t res;
		Char wc;

		pintr_push_enable(&old_pintr_disabled);
		res = force_read(OLDSTD, cbuf + cbp, 1);
		cleanup_until(&old_pintr_disabled);
		if (res != 1)
		    break;
		cbp++;
		len = normal_mbtowc(&wc, cbuf, cbp);
		if (len == -1) {
		    reset_mbtowc();
		    if (cbp < MB_LEN_MAX)
		        continue; /* Maybe a partial character */
		    wc = (unsigned char)*cbuf | INVALID_BYTE;
		}
		if (len <= 0)
		    len = 1;
		if (cbp != (size_t)len)
		    memmove(cbuf, cbuf + len, cbp - len);
		cbp -= len;
		if (wc == '\n')
		    break;
		Strbuf_append1(&wbuf, wc);
	    }
	    while (cbp != 0) {
		int len;
		Char wc;

		len = normal_mbtowc(&wc, cbuf, cbp);
		if (len == -1) {
		    reset_mbtowc();
		    wc = (unsigned char)*cbuf | INVALID_BYTE;
		}
		if (len <= 0)
		    len = 1;
		if (cbp != (size_t)len)
		    memmove(cbuf, cbuf + len, cbp - len);
		cbp -= len;
		if (wc == '\n')
		    break;
		Strbuf_append1(&wbuf, wc);
	    }
	    Strbuf_terminate(&wbuf);
	}

	fixDolMod();
	setDolp(wbuf.s); /* Kept allocated until next $< expansion */
	cleanup_until(name);
	goto eatbrac;
    }

    case '*':
	Strbuf_append(name, STRargv);
	Strbuf_terminate(name);
	vp = adrof(STRargv);
	subscr = -1;		/* Prevent eating [...] */
	break;

    case DEOF:
    case '\n':
	np = dimen ? STRargv : (bitset ? STRstatus : NULL);
	if (np) {
	    bitset = 0;
	    Strbuf_append(name, np);
	    Strbuf_terminate(name);
	    vp = adrof(np);
	    subscr = -1;		/* Prevent eating [...] */
	    unDredc(c);
	    break;
	}
	else
	    stderror(ERR_SYNTAX);
	/*NOTREACHED*/

    default:
	if (Isdigit(c)) {
	    if (dimen)
		stderror(ERR_NOTALLOWED, "$#<num>");
	    subscr = 0;
	    do {
		subscr = subscr * 10 + c - '0';
		c = DgetC(0);
	    } while (c != DEOF && Isdigit(c));
	    unDredc(c);
	    if (subscr < 0)
		stderror(ERR_RANGE);
	    if (subscr == 0) {
		if (bitset) {
		    dolp = dolzero ? STR1 : STR0;
		    cleanup_until(name);
		    goto eatbrac;
		}
		if (ffile == 0)
		    stderror(ERR_DOLZERO);
		if (length) {
		    length = Strlen(ffile);
		    addla(putn(length));
		}
		else {
		    fixDolMod();
		    setDolp(ffile);
		}
		cleanup_until(name);
		goto eatbrac;
	    }
#if 0
	    if (bitset)
		stderror(ERR_NOTALLOWED, "$?<num>");
	    if (length)
		stderror(ERR_NOTALLOWED, "$%<num>");
#endif
	    vp = adrof(STRargv);
	    if (vp == 0) {
		vp = &nulargv;
		cleanup_until(name);
		goto eatmod;
	    }
	    break;
	}
	if (c == DEOF || !alnum(c)) {
	    np = dimen ? STRargv : (bitset ? STRstatus : NULL);
	    if (np) {
		bitset = 0;
		Strbuf_append(name, np);
		Strbuf_terminate(name);
		vp = adrof(np);
		subscr = -1;		/* Prevent eating [...] */
		unDredc(c);
		break;
	    }
	    else
		stderror(ERR_VARALNUM);
	}
	for (;;) {
	    Strbuf_append1(name, (Char) c);
	    c = DgetC(0);
	    if (c == DEOF || !alnum(c))
		break;
	}
	Strbuf_terminate(name);
	unDredc(c);
	vp = adrof(name->s);
    }
    if (bitset) {
	dolp = (vp || getenv(short2str(name->s))) ? STR1 : STR0;
	cleanup_until(name);
	goto eatbrac;
    }
    if (vp == NULL || vp->vec == NULL) {
	np = str2short(getenv(short2str(name->s)));
	if (np) {
	    static Char *env_val; /* = NULL; */

	    cleanup_until(name);
	    fixDolMod();
	    if (length) {
		    addla(putn(Strlen(np)));
	    } else {
		    xfree(env_val);
		    env_val = Strsave(np);
		    setDolp(env_val);
	    }
	    goto eatbrac;
	}
	udvar(name->s);
	/* NOTREACHED */
    }
    cleanup_until(name);
    c = DgetC(0);
    upb = blklen(vp->vec);
    if (dimen == 0 && subscr == 0 && c == '[') {
	name = Strbuf_alloc();
	cleanup_push(name, Strbuf_free);
	np = name->s;
	for (;;) {
	    c = DgetC(DODOL);	/* Allow $ expand within [ ] */
	    if (c == ']')
		break;
	    if (c == '\n' || c == DEOF)
		stderror(ERR_INCBR);
	    Strbuf_append1(name, (Char) c);
	}
	Strbuf_terminate(name);
	np = name->s;
	if (dolp || dolcnt)	/* $ exp must end before ] */
	    stderror(ERR_EXPORD);
	if (!*np)
	    stderror(ERR_SYNTAX);
	if (Isdigit(*np)) {
	    int     i;

	    for (i = 0; Isdigit(*np); i = i * 10 + *np++ - '0')
		continue;
	    if (i < 0 || (i > upb && !any("-*", *np))) {
		cleanup_until(name);
		dolerror(vp->v_name);
		return;
	    }
	    lwb = i;
	    if (!*np)
		upb = lwb, np = STRstar;
	}
	if (*np == '*')
	    np++;
	else if (*np != '-')
	    stderror(ERR_MISSING, '-');
	else {
	    int i = upb;

	    np++;
	    if (Isdigit(*np)) {
		i = 0;
		while (Isdigit(*np))
		    i = i * 10 + *np++ - '0';
		if (i < 0 || i > upb) {
		    cleanup_until(name);
		    dolerror(vp->v_name);
		    return;
		}
	    }
	    if (i < lwb)
		upb = lwb - 1;
	    else
		upb = i;
	}
	if (lwb == 0) {
	    if (upb != 0) {
		cleanup_until(name);
		dolerror(vp->v_name);
		return;
	    }
	    upb = -1;
	}
	if (*np)
	    stderror(ERR_SYNTAX);
	cleanup_until(name);
    }
    else {
	if (subscr > 0) {
	    if (subscr > upb)
		lwb = 1, upb = 0;
	    else
		lwb = upb = subscr;
	}
	unDredc(c);
    }
    if (dimen) {
	/* this is a kludge. It prevents Dgetdol() from */
	/* pushing erroneous ${#<error> values into the labuf. */
	if (sc == '{') {
	    c = Dredc();
	    if (c != '}')
		stderror(ERR_MISSING, '}');
	    unDredc(c);
	}
	addla(putn(upb - lwb + 1));
    }
    else if (length) {
	int i;

	for (i = lwb - 1, length = 0; i < upb; i++)
	    length += Strlen(vp->vec[i]);
#ifdef notdef
	/* We don't want that, since we can always compute it by adding $#xxx */
	length += i - 1;	/* Add the number of spaces in */
#endif
	addla(putn(length));
    }
    else {
eatmod:
	fixDolMod();
	dolnxt = &vp->vec[lwb - 1];
	dolcnt = upb - lwb + 1;
    }
eatbrac:
    if (sc == '{') {
	c = Dredc();
	if (c != '}')
	    stderror(ERR_MISSING, '}');
    }
}
Example #15
0
void oStr(const char * const line)
{
	oMem(line, Strlen(line));
}
Example #16
0
int rule_get_target(void * router_rule,void * message,void **result)
{
    BYTE * target;
    int ret;
    char buffer[DIGEST_SIZE*2];
    ROUTE_RULE * rule= (ROUTE_RULE *)router_rule;
    *result=NULL;
    switch(rule->target_type){
	    case ROUTE_TARGET_NAME:
	    case ROUTE_TARGET_PORT:
	    case ROUTE_TARGET_LOCAL:
		    target=Talloc0(DIGEST_SIZE);
		    Strncpy(target,rule->target_name,DIGEST_SIZE);
		    break;
	    case ROUTE_TARGET_UUID:
		    ret=Strnlen(rule->target_name,DIGEST_SIZE*2);
		    target=Talloc0(DIGEST_SIZE);
		    if(ret ==DIGEST_SIZE*2)
		    {
			if(target==NULL)
				return -ENOMEM;
			ret=uuid_to_digest(rule->target_name,target);
			if(ret<0)
				return ret;
		    }		
		    else if(ret<DIGEST_SIZE/4*3)
		    {
		    	Memcpy(target,rule->target_name,ret);
		    }
		    else
			return -EINVAL;
		    break;
	    case ROUTE_TARGET_CONN:
		    target=Talloc0(DIGEST_SIZE);
		    if(target==NULL)
			return -ENOMEM;	
		    ret=Strnlen(rule->target_name,DIGEST_SIZE*2);
		    if(ret>DIGEST_SIZE/4*3-1)
			return -EINVAL;
		    target[0]=':';
		    Memcpy(target+1,rule->target_name,ret);
		    break;
	    case ROUTE_TARGET_RECORD:
		   {
			ret=message_read_elem(message,rule->target_name,0,&target);
			if(ret<0)
				return -EINVAL;
			if(target==NULL)
				return -EINVAL;
			break;
		   }

	    case ROUTE_TARGET_EXPAND:
		   {
			int expand_type;
			int expand_subtype;
			MSG_EXPAND * expand;
			void * expand_template;
			void * expand_data;
			int len;
		
			len=Strlen(rule->target_name);
			if(len>DIGEST_SIZE*3)
				return -EINVAL;
			
			int i=0;
			int offset=0;
			offset=message_read_typestr(rule->target_name,&expand_type,&expand_subtype);
			if(offset<0)
				return offset;
			while(rule->target_name[offset++]!=':')
			{
				if(offset>=len)
					return -EINVAL;
			}

		        ret = message_get_define_expand(message,&expand,expand_type,expand_subtype);
			if(ret<0)
				return -EINVAL;
			if(expand==NULL)
				return -EINVAL;
			expand_template=memdb_get_template(expand_type,expand_subtype);
			if(expand_template==NULL)
				return -EINVAL;		
			target=Talloc(DIGEST_SIZE*2+1);
			ret=struct_read_elem(rule->target_name+offset,expand->expand,target,expand_template);		
			if(ret<0)
				return ret;
		   	if(target==NULL)
				return -EINVAL;
		   	break;
		   }

/*
	    case ROUTE_TARGET_SPLIT:
		    return -EINVAL;

	    case ROUTE_TARGET_MIXUUID:
		    {
			    void * json_root;
			    void * json_elem;
			    const int repeat_time=2;
			    char mixvalue[repeat_time][DIGEST_SIZE*2];
			    char tag[16];
			    char uuid[DIGEST_SIZE*2];
			    int i;

			    ret=json_solve_str(&json_root,rule->target_name);
			    if(ret<0)
				    return ret;
			    if(json_get_type(json_root)!=JSON_ELEM_MAP)
				    return -EINVAL;
			
			    memset(uuid,0,DIGEST_SIZE*2);

			    char * value;
			    char name[DIGEST_SIZE*2];

			    for(i=0;i<repeat_time;i++)
			    {
			   	 memset(mixvalue[i],0,DIGEST_SIZE*2);

				 if(i==0)
				 {
			      	 	 // first json_elem is the node uuid value
			       		json_elem=json_get_first_child(json_root);
				 }
				 else
				 {
					json_elem=json_get_next_child(json_root);

				 }
				 ret=json_node_getname(json_elem,name);
			    	 if(ret<0)
					return ret;
				 if(json_get_type(json_elem)!=JSON_ELEM_STRING)
					return -EINVAL;

				 ret=json_node_getvalue(json_elem,tag,15);
				// tag is "RECORD"  means this elem defines an elem in the message's record
				 if(strcmp(tag,"RECORD")==0)
				 {
					void * record;	
					ret=message_read_elem(message,name,0,&record);
					if(ret<0)
						return ret;
				        int len=strlen(record);
					if(len<DIGEST_SIZE*2)
					{
						Memcpy(mixvalue[i],record,len);
					}
					else
					{
						Memcpy(mixvalue[i],record,DIGEST_SIZE*2);
					}
				}
				// tag is "name" means this elem defines remote proc's value
				else if(strcmp(tag,"NAME")==0)
				{
				        int len=strlen(name);
					if(len<DIGEST_SIZE*2)
					{
						Memcpy(mixvalue[i],name,len);
					}
					else
					{
						Memcpy(mixvalue[i],name,DIGEST_SIZE*2);
					}
				}

			    	else if(strncmp(tag,"EXPAND",6)==0)
			    	{
					char * type=tag+7;
			       		if(strlen(type)!=4)
					{
						return -EINVAL;	
					}		
					void * expand;
				        ret = message_get_define_expand(message,&expand,type);
					if(ret<0)
						return -EINVAL;
					if(expand==NULL)
						return -EINVAL;
					void * struct_template=load_record_template(type);
					if(struct_template==NULL)
						return -EINVAL;
					ret=struct_read_elem(name,expand,mixvalue[i],struct_template);		
					free_struct_template(struct_template);
					if(ret<0)
						return ret;
			    	}

		    		else
			    	{
			    		return -EINVAL;
			    	}
			  	if(i==0)
					continue;
			  	if(i==1)
			   	{
					comp_proc_uuid(mixvalue[0],mixvalue[1],uuid);
				  	continue;
			    	}
			   	comp_proc_uuid(uuid,mixvalue[i],uuid);
		
			  }
		   	 target=malloc(DIGEST_SIZE*2);
		 	 Memcpy(target,uuid,DIGEST_SIZE*2);
		   	 break;
		   }
*/		    
	    case ROUTE_TARGET_ERROR:
	    default:
		    return -EINVAL;
    }
    *result=target;
    return rule->target_type;	

}