コード例 #1
0
ファイル: shoutcast.cpp プロジェクト: atmos/butt
int sc_update_song()
{
    int ret;
    int web_socket;
    char send_buf[1024];
    char *song_buf;

    web_socket = sock_connect(cfg.srv[cfg.selected_srv]->addr,
            cfg.srv[cfg.selected_srv]->port, CONN_TIMEOUT);

    if(web_socket < 0)
    {
        switch(web_socket)
        {
            case SOCK_ERR_CREATE:
                print_info("\nupdate_song: could not create network socket", 1);
                ret = 1;
                break;
            case SOCK_ERR_RESOLVE:
                print_info("\nupdate_song: error resolving server address", 1);
                ret = 1;
                break;
            case SOCK_TIMEOUT:
            case SOCK_INVALID:
                ret = 1;
                break;
            default:
                ret = 1;
        }

        return ret;
    }

    song_buf = strdup(cfg.main.song);

    strrpl(&song_buf, " ", "%20");
    strrpl(&song_buf, "&", "%26");

    snprintf(send_buf, 500, "GET /admin.cgi?pass=%s&mode=updinfo&song=%s&url= HTTP/1.0\n"
                      "User-Agent: ShoutcastDSP (Mozilla Compatible)\n\n",
                      cfg.srv[cfg.selected_srv]->pwd,
                      song_buf
                     );

    sock_send(&web_socket, send_buf, strlen(send_buf), SEND_TIMEOUT);
    close(web_socket);
    free(song_buf);

    return 0;
}
コード例 #2
0
ファイル: Main.c プロジェクト: Dev-XYS/Tester
void TestContestant(char *ContestantName)
{
	printf("\n>>> Contestant : %s\n", ContestantName);
	char TesterCommand[1024];
	int LastReturnValue = 0;
	for (int i = 0; i < CommandCount; i++)
	{
		if (strcmp(Config[i].MainCommand, "#TC") == 0)
		{
			char sExecutable[256], Executable[256];
			char sExecutableParameters[256], ExecutableParameters[256];			char sCheckerCommand[256], CheckerCommand[256];
			strrpl(sExecutable, Config[i].Executable, "$(CONTESTANT)", ContestantName);
			strrpl(Executable, sExecutable, "%20", " ");
			strrpl(sExecutableParameters, Config[i].ExecutableParameters, "$(CONTESTANT)", ContestantName);
			strrpl(ExecutableParameters, sExecutableParameters, "%20", " ");
			strrpl(sCheckerCommand, Config[i].CheckerCommand, "$(CONTESTANT)", ContestantName);
			strrpl(CheckerCommand, sCheckerCommand, "%20", " ");
			PrintPrompt(Config[i].Identifier);
			char TesterCommand[1024];
			sprintf(TesterCommand, "./tester %d \"%s\" \"%s\" %d %d \"%s\" RESULT",
				Config[i].TestType,
				Executable,
				ExecutableParameters,
				Config[i].TimeLimit,
				Config[i].MemoryLimit,
				CheckerCommand/*,
				Config[i].OutputFile,
				Config[i].AnswerFile*/);
			LastReturnValue = system(TesterCommand);
			PrintResult();
		}
		else if (strcmp(Config[i].MainCommand, "#N0") == 0)
		{
			if (LastReturnValue != 0)
			{
				i += atoi(Config[i].Parameter);
			}
		}
		else
		{
			char ParsedContestantCommand[1024];
			char ParsedSpaceCommand[1024];
			strrpl(ParsedContestantCommand, Config[i].MainCommand, "$(CONTESTANT)", ContestantName);
			strrpl(ParsedSpaceCommand, ParsedContestantCommand, "%20", " ");
			LastReturnValue = system(ParsedSpaceCommand);
		}
	}
	printf("\n");
}
コード例 #3
0
ファイル: common.c プロジェクト: lesovsky/pgcenter
/*
 ****************************************************************************
 * Replace substring in string.
 * Looking for the 's_string' inside the 'o_string' and replace it with the 
 * 'r_string' when it's found. Return modified the 'o_string'.
 ****************************************************************************
 */
void strrpl(char * o_string, const char * s_string, const char * r_string, unsigned int buf_size)
{
    char buffer[buf_size];
    char * ch;
             
    if(!(ch = strstr(o_string, s_string)))
        return;
    
    strncat(buffer, o_string, ch - o_string);
    sprintf(buffer + (ch - o_string), "%s%s", r_string, ch + strlen(s_string));
    o_string[0] = 0;
    snprintf(o_string, buf_size, "%s", buffer);
    strrpl(o_string, s_string, r_string, buf_size);

    return;
}
コード例 #4
0
ファイル: StreamClient.c プロジェクト: frankzzcn/msgmgt
void *StreamClient(void *pipefd)
{
  int sockfd_connect=-1;
  fd_set readfds, readfds_temp;
  char buf[HTTP_LEN]={0};
  char buf1[HTTP_LEN]={0};
  char str1[PORT_LEN]={0}, str2[PORT_LEN]={0};
  int length=0;
  int reqfd=0, resfd=0;
  ip_t ip_remote = ip[REMOTE][TCP];
  port_t port_remote = port[REMOTE][TCP];
  struct timeval timeout={10,0}, timeout_temp={0};
  int ret=0;

  reqfd = ((int*)pipefd)[PIPE_INDEX(REQUEST,READ)];
  resfd = ((int*)pipefd)[PIPE_INDEX(RESPONSE,WRITE)];

  sockfd_connect = EstablishConnect(ip_remote, port_remote, SOCK_STREAM);

  FD_ZERO(&readfds);

  FD_SET_P(sockfd_connect, &readfds);

  FD_SET_P(reqfd, &readfds);

  while(1) {

    timeout_temp = timeout;
    readfds_temp = readfds;

    ret = select(FD_SETSIZE, &readfds_temp, NULL, NULL, NULL);
    handle_error_nn(ret, 1, "TRANSMIT","select() %s",strerror(errno));

    if(ret == 0) {
      log4c_cdn(mycat, error, "TRANSMIT", "select() timeout");
      exit(-1);
    }

    //monitor sockfd_connect
    if(FD_ISSET(sockfd_connect, &readfds_temp)) {
      memset(buf,0,sizeof(buf));
      length = read(sockfd_connect, buf, sizeof(buf)-1);
      handle_error_nn(length, 0, "TRANSMIT","read() %s",strerror(errno));
      log4c_cdn(mycat, info, "TRANSMIT", "receiving <== connect=%d, length=%d", sockfd_connect, length);
      log4c_cdn(mycat, debug, "TRANSMIT", "Packet content is\n%s",buf);

      if(length <= 0) {
        ret = sd_close(sockfd_connect);
        handle_error_nn(ret, 1, "TRANSMIT","close() %s",strerror(errno));
        FD_CLR_P(sockfd_connect, &readfds);

        sockfd_connect = EstablishConnect(ip_remote, port_remote, SOCK_STREAM);
        FD_SET_P(sockfd_connect, &readfds);
      }
      else if(length == (sizeof(buf)-1)) {
        log4c_cdn(mycat, error, "socket", "http response is too large to store");
        exit(-1);
      }
      else {
        //deal with http packet
        length = write(resfd, buf, strlen(buf));
        handle_error_nn(length, 1, "TRANSMIT","write() %s",strerror(errno));
        log4c_cdn(mycat, info, "TRANSMIT", "sending ==> resfd=%d, length=%d", resfd,length);
      }

    }
    //monitor request fd
    /*else*/ if(FD_ISSET(reqfd, &readfds_temp)) {
      memset(buf,0,sizeof(buf));
      length = read(reqfd, buf, sizeof(buf)-1);
      handle_error_nn(length, 1, "TRANSMIT","read() %s",strerror(errno));
      log4c_cdn(mycat, info, "TRANSMIT", "receiving <== reqfd=%d length=%d", reqfd, length);

      if(length == 0) {
        ret = sd_close(reqfd);
        handle_error_nn(ret, 1, "TRANSMIT","close() %s",strerror(errno));
        FD_CLR_P(reqfd, &readfds);
      }
      else {
        strcpy(buf1, buf);
        strrpl(buf, buf1, "close", "keep-alive");
        strcpy(buf1, buf);
        strrpl(buf, buf1, "Close", "keep-alive");
        strcpy(buf1, buf);
        strrpl(buf, buf1, ip[LOCAL][TCP], server);
        strcpy(buf1, buf);
        sprintf(str1,"%hd",port[LOCAL][TCP]);
        sprintf(str2,"%hd",port[REMOTE][TCP]);
        strrpl(buf, buf1, str1, str2);

        length = write(sockfd_connect, buf, strlen(buf));
        handle_error_nn(length, 1, "TRANSMIT","write() %s",strerror(errno));
        log4c_cdn(mycat, info, "TRANSMIT", "sending ==> connect=%d, length=%d", sockfd_connect,length);
        log4c_cdn(mycat, debug, "TRANSMIT", "Packet content is\n%s",buf);
      }

    }
  }
  return NULL;
}
コード例 #5
0
ファイル: dump.cpp プロジェクト: Artorios/IDAplugins-1
//--------------------------------------------------------------------------
int idaapi accept_file(linput_t *li, char fileformatname[MAX_FILE_FORMAT_NAME], int n)
{
  char line[MAXSTR];
  char *words[MAXSTR];

  if ( n )
    return 0;

  // We try to interpret the input file as a text
  // file with a dump format, i.e. all lines should look like

//00000020:  59 69 74 54-55 B6 3E F7-D6 B9 C9 B9-45 E6 A4 52  YitTU¦>?O?E?E??R
//0020: 59 69 74 54 55 B6 3E F7 D6 B9 C9 B9 45 E6 A4 52  "YitTU¦>?O?E?E??R"
//1000: 12 23 34 56 78
//0100: 31 C7 1D AF 32 04 1E 32 05 1E 3C 32 07 1E 21 D9
//12 23 34 56 78

  // and similar lines
  // We allow non-ascii characters at the end of the line
  // We skip empty lines

  ssize_t p0len = -1;    // length of the first word's hex part
  char w0sep[10];        // separator after the first word
  w0sep[0] = '\0';
  int nl = 0;
  int nontrivial_line_count = 0;
  bool no_more_lines = false;
  uint32 adr, oldadr=0;
  while ( qlgets(line, sizeof(line), li) )
  {
    nl++;
    strrpl(line, '-', ' ');
    int nw = make_words(line, words, qnumber(words));
    if ( line[0] == ';' || line[0] == '#' )
      continue;
    if ( nw == 0 )
      continue;
    nontrivial_line_count++;
    if ( no_more_lines )
      FAILED;
    // od -x format may contain '*' lines which mean repetition
    if ( strcmp(words[0], "*") == 0 && nw == 1 )
      continue;
    // the first word must be a number (more than one digit)
    char *ptr = words[0];
    adr = hex(ptr);
    ssize_t p0 = ptr - words[0];
    if ( p0 <= 1 )
      FAILED;
    if ( nontrivial_line_count > 1 && p0 < p0len )
      FAILED;
    p0len = p0;
    // take the separator from the first line
    if ( nontrivial_line_count == 1 )
    {
      qstrncpy(w0sep, ptr, sizeof(w0sep));
      while ( *ptr )
        if ( strchr(":>-.", *ptr++) == NULL )
          FAILED;
    }
    else
    {
      if ( strcmp(w0sep, ptr) != 0 )
        FAILED;
    }
    bool haspref = p0len >= 4 || w0sep[0] != '\0';
    if ( haspref )
    {
      // if the line contains only the address, then don't accept lines anymore
      if ( nw == 1 )
      {
        if ( nontrivial_line_count == 1 )
          FAILED;
        no_more_lines = true;
        if ( adr <= oldadr )
          FAILED;
      }
      else
      {
        // the remaining words should be numbers with at least 1 position
        // (at least the second word should be so)
        ptr = words[1];
        hex(ptr);
        if ( ptr == words[1] )
          FAILED;
      }
    }
    oldadr = adr;
  }
  if ( nontrivial_line_count == 0 )
    FAILED;

  qstrncpy(fileformatname, "Dump file", MAX_FILE_FORMAT_NAME);
  return 1;
}
コード例 #6
0
ファイル: dump.cpp プロジェクト: Artorios/IDAplugins-1
//--------------------------------------------------------------------------
void idaapi load_file(linput_t *li, ushort _neflag, const char * /*fileformatname*/)
{
  char line[MAXSTR];
  char *words[MAXSTR];

  neflag = _neflag;
  iscode = (neflag & NEF_CODE) != 0;
  sel = BADSEL;
  sea = BADADDR;
  ea_t ea = 0;
  ea_t top= 0;
  bool use32   = false;
  bool octpref = false;
  bool octnum  = false;
  size_t fill = 0;

  // Since we made all the checks in accept_file,
  // here we don't repeat them

  ssize_t p0len = -1;    // length of the first word's hex part
  char w0sep[10];        // separator after the first word
  w0sep[0] = '\0';
  int nontrivial_line_count = 0;
  while ( qlgets(line, sizeof(line), li) )
  {
    strrpl(line, '-', ' ');
    if ( line[0] == ';' || line[0] == '#' )
      continue;
    int n = make_words(line, words, qnumber(words));
    if ( n == 0 )
      continue;
    nontrivial_line_count++;
    ssize_t bi;
    // od -x format may contain '*' lines which mean repetition
    if ( strcmp(words[0], "*") == 0 && n == 1 )
    {
      fill  = size_t(top - ea);
      octpref = true;             // od -x have octal prefixes
      continue;
    }
    // the first word must be a number (more than one digit)
    char *ptr = words[0];
    uint32 w0 = octpref ? oct(ptr) : hex(ptr);
    p0len = ptr - words[0];
    // take the separator from the first line
    if ( nontrivial_line_count == 1 )
      qstrncpy(w0sep, ptr, sizeof(w0sep));

    // process '*' and fill the gap
    if ( fill > 0 )
    {
      while ( top < w0 )
      {
        ea = top;
        top = ea + fill;
        copy(ea, top);
      }
    }

    int idx = 0;
    if ( w0sep[0] != '\0' || p0len >= 4 )
    {
      if ( nontrivial_line_count > 1 && !octpref && top != w0 )
      {
        // strange, the sequence is not contiguous
        // check if the prefixes are octal (od -x)
        ptr = words[0];
        if ( oct(ptr) == top )
        {
          octpref = true;
          ptr = words[0];
          w0 = oct(ptr);
        }
      }
      ea = w0;
      idx = 1;
    }
    else
    {
      ea = top;
    }
    for ( bi=0; idx < n; idx++ ) //lint !e443
    {
      ptr = words[idx];
      if ( nontrivial_line_count == 1 && !octnum && strlen(ptr) == 6 )
      {
        oct(ptr);
        if ( ptr-words[idx] == 6 )
          octnum = true;
        ptr = words[idx];
//        msg("ptr=%s octnum=%d\n", ptr, octnum);
      }
      uint32 b = octnum ? oct(ptr) : hex(ptr);
      ssize_t nc = ptr - words[idx];
      if ( nc < 2 )
      {
        // we tolerate one-letter separators between numbers
        if ( words[idx][1] == '\0' && strchr("\xA6|-:", words[idx][0]) != NULL )
          continue;
        break;
      }
      nc /= octnum ? 3 : 2;             // number of bytes
      *(uint32 *)&bytes[bi] = b;
      bi += nc;
    }
    top = ea + bi;
    copy(ea, top);
  }

  if ( eea >= 0x10000 || p0len > 4 )
    use32 = true;
  if ( neflag & NEF_SEGS )
  {
    if ( use32 )
    {
      set_segm_addressing(getseg(sea), 1);
      if ( ph.id == PLFM_386 ) inf.lflags |= LFLG_PC_FLAT;
    }
    set_default_dataseg(sel);
  }
  if ( (neflag & NEF_RELOAD) == 0 )
    create_filename_cmt();
}
コード例 #7
0
int ic_update_song(void)
{
    int ret;
    int web_socket;
    char send_buf[1024];
    char auth[150];
    char *song_buf;
    char *mount;

    web_socket = sock_connect(cfg.srv[cfg.selected_srv]->addr,
            cfg.srv[cfg.selected_srv]->port, CONN_TIMEOUT);

    if(web_socket < 0)
    {
        switch(web_socket)
        {
            case SOCK_ERR_CREATE:
                print_info("\nupdate_song: could not create network socket", 1);
                ret = 2;
                break;
            case SOCK_ERR_RESOLVE:
                print_info("\nupdate_song: error resolving server address", 1);
                ret = 2;
                break;
            case SOCK_TIMEOUT:
            case SOCK_INVALID:
                ret = 1;
                break;
            default:
                ret = 2;
        }

        return ret;
    }

    song_buf = strdup(cfg.main.song);

    strrpl(&song_buf, (char*)" ", (char*)"%20", MODE_ALL);
    strrpl(&song_buf, (char*)"&", (char*)"%26", MODE_ALL);

    mount = (char*)malloc(strlen(cfg.srv[cfg.selected_srv]->mount)+2);

    if(cfg.srv[cfg.selected_srv]->mount[0] != '/')
        sprintf(mount, "/%s", cfg.srv[cfg.selected_srv]->mount);
    else
        strcpy(mount, cfg.srv[cfg.selected_srv]->mount);

    snprintf(auth, sizeof(auth), "%s:%s", cfg.srv[cfg.selected_srv]->usr, cfg.srv[cfg.selected_srv]->pwd);

    snprintf(send_buf, sizeof(send_buf), "GET /admin/metadata?mode=updinfo&mount=%s&song=%s "
                                         "HTTP/1.0\r\nUser-Agent: %s\r\n"
                                         "Authorization: Basic %s\r\n\r\n",
                                         mount, song_buf, PACKAGE_STRING, util_base64_enc(auth));


    sock_send(&web_socket, send_buf, strlen(send_buf), SEND_TIMEOUT);

    sock_close(&web_socket);
    free(song_buf);
    free(mount);

    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: barak/xsystrace
int
make_policy(char **type, char **data, int count, char **presult, int derive)
{
	static char result[4096];
	char one[2048];
	int i;
	int nfilename, isfilename;

	result[0] = '\0';
	nfilename = 0;
	for (i = 0; i < count; i++) {
		isfilename = 0;
		/* Special case for non existing filenames */
		if (strstr(data[i], "<non-existent filename>") != NULL) {
			snprintf(result, sizeof(result),
			    "filename%s sub \"<non-existent filename>\" then deny[enoent]", i ? "[1]" : "");
			break;
		}

		if (!strcmp(type[i], "uid") || !strcmp(type[i], "gid") ||
		    !strcmp(type[i], "argv"))
			continue;

		/* Special case for system calls with more than one filename */
		if (!strcmp(type[i], "filename")) {
			isfilename = 1;
			nfilename++;
		}
		
		if (strlen(result)) {
			if (strlcat(result, " and ", sizeof(result)) >= sizeof(result))
				return (-1);
		}

		/* Special treatment for filenames */
		if (isfilename) {
			char filename[2048];
			char *operator = "eq";

			if (derive) {
				operator = "match";

				snprintf(filename, sizeof(filename),
				    "%s/*", dirname(data[i]));
			} else
				strlcpy(filename, data[i], sizeof(filename));

			/* Make useful replacements */
			while (strrpl(filename, sizeof(filename),
				   home, "$HOME") != NULL)
				;
			while (strrpl(filename, sizeof(filename),
				   username, "$USER") != NULL)
				;

			snprintf(one, sizeof(one), "%s%s %s \"%s\"",
			    type[i], isfilename && nfilename == 2 ? "[1]" : "",
			    operator, filename);
		} else {
			snprintf(one, sizeof(one), "%s eq \"%s\"",
			    type[i], data[i]);
		}

		if (strlcat(result, one, sizeof(result)) >= sizeof(result))
			return (-1);;
	}

	if (!strlen(result))
		return (-1);

	/* Normal termination */
	if (i == count)
		strlcat(result, " then permit", sizeof(result));

	*presult = result;
	return (nfilename);
}