//-----------------------------------------------------------------------
      ISDPTypes::SDPPtr SDPParser::parse(const char *blob)
      {
        if (!blob) return SDPPtr();

        SDPPtr sdp(make_shared<SDP>());

        sdp->mOriginal = String(blob);
        std::unique_ptr<char[]> rawBuffer(new char[sdp->mOriginal.length()+1]);
        sdp->mRawBuffer = std::move(rawBuffer);

        memset(sdp->mRawBuffer.get(), 0, sizeof(char)*(sdp->mOriginal.length()+1));
        memcpy(sdp->mRawBuffer.get(), blob, sizeof(char)*(sdp->mOriginal.length()));

        try {
          parseLines(*sdp);
          parseAttributes(*sdp);
          validateAttributeLevels(*sdp);
          parseLinesDetails(*sdp);
          processFlagAttributes(*sdp);
          processSessionLevelValues(*sdp);
          processMediaLevelValues(*sdp);
          processSourceLevelValues(*sdp);
        } catch (const SafeIntException &e) {
          ORTC_THROW_INVALID_PARAMETERS("value found out of legal value range" + string(e.m_code));
        }

        return sdp;
      }
예제 #2
0
//========================================================================
bool NDLocalXmlString::LoadLoginString()
{
	string strFile = NDEngine::NDPath::GetResPath("Login.strings");
	vector<string> vecLines;
	if (readLines( strFile, vecLines ) )
	{
		parseLines( vecLines );
		return true;
	}
	return false;
}
예제 #3
0
파일: MsgPack.c 프로젝트: gaudima/metro-spb
static Scheme* parseScheme(uint8_t* data) {
    Scheme *ret = malloc(sizeof(Scheme));
    int len = parseArraySize(data);
    for(int i = 0; i < len; i++) {
        if(i == 0) {
            ret->lines = parseLines(data, &(ret->linesLen));
        } else if(i == 1) {
            ret->stations = parseStations(data, &(ret->stationsLen));
        } else if(i == 2) {
            ret->links = parseLinks(data, &(ret->linksLen));
        }
    }
    return ret;
}
예제 #4
0
파일: 1_terminalTables.c 프로젝트: MirzaN/C
int main(int argc, char *argv[])
{
    FILE *fileHandle;
    char nextLine[1024] = "";
    char currentLine[1024] = "";


    if (argv[1])  //Verify that CLI parameter exists.
    {
    
        if( fileHandle = fopen(argv[1],"r") ) //Verify input file handle.
        {

            while (fgets (nextLine, 1024, fileHandle)!=NULL) //Read line by line until EOF
            {
                parseLines(currentLine, nextLine);   //Send current and next line to print first line characters followed by border between current and the next line.
                strcpy(currentLine, nextLine);       //Copy next line into current before reading new next line.
            }

            parseLines(currentLine, nextLine);   //Send the very last line for printing.

            fclose(fileHandle);
        }
        else
        {
            printf("\n Unable to open input file \"%s\"!!!\n\n", argv[1]);
            return 2;
        }
    }
    else
    {
        printf("\n No input file specified!  -->%s  <filename>\n Please provide name of the input file.\n\n", argv[0]);
        return 1;
    }

    return 0;
}
예제 #5
0
파일: 2.c 프로젝트: dlove24/dl-bstring
int main (int argc, char* argv[]) {
  FILE* fp;

  if (argc < 2) {
    printf ("%s [inputfile]\n", argv[0]);
    return -__LINE__;
    }

  if (NULL != (fp = fopen (argv[1], "rb"))) {
    bstring src = bread ( (bNread) fread, fp);
    int ret = parseLines (src);
    fclose (fp);
    bdestroy (src);
    return ret;
    }

  return -__LINE__;
  }
예제 #6
0
파일: Network.cpp 프로젝트: 8102/QNetSoul
void    Network::processPackets(void)
{
  int          readbytes;
  char         buffer[128];
  QDataStream  in(&this->_socket);
  //in.setVersion(QDataStream::Qt_4_6); // Not mandatory...

  while (this->_socket.bytesAvailable())
    {
      readbytes = in.readRawData(buffer, sizeof(buffer) - 1);
      if (readbytes > 0)
        {
          buffer[readbytes] = '\0';
          this->_rbuffer.append(buffer);
        }
      else
        {
          return;
        }
    }
  if (this->_rbuffer.contains('\n'))
    parseLines();
}
예제 #7
0
파일: pgm.c 프로젝트: asmeikal/c-utils
/*!
 * @function pgm_load
 * Loads the pgm image at [filename] into a [width] x [height] unsigned char matrix,
 * and stores the pointer into [img].
 * @param img
 * A pointer to an unsigned char pointer where the image will be stored.
 * @param height
 * A pointer to an int where the n of rows of the image will be stored.
 * @param width
 * A pointer to an int where the n of cols of the image will be stored.
 * @param filename
 * The name of the file to be read.
 * @return
 * 0 on success, non-0 on failure.
 */
int pgm_load(unsigned char ** const img, int * const height, int * const width, const char * const filename)
{
	const char * const fname = "pgm_load";
	if (NULL == img) {
		Debug_out(DEBUG_PGM, "%s: NULL pointer argument.\n", fname);
		goto error1;
	}
	char **lines = parseLines(filename);
	int i = 0, j;
	int l_width, l_height;
	unsigned int tmp;
	/* parse all file lines */
	if (NULL == lines) {
		Debug_out(DEBUG_PGM, "%s: unable to read file '%s'.\n", fname, filename);
		goto error1;
	}
	/* check that first line says P2 */
	if (NULL == lines[i]) {
		Debug_out(DEBUG_PGM, "%s: image ended too early.\n", fname);
		goto error2;
	}
	if (!StringUtils_startsWith(lines[i], "P2")) {
		Debug_out(DEBUG_PGM, "%s: illegal image start: %s.\n", fname, lines[i]);
		goto error2;
	}
	++i;
	/* skip all comment lines */
	while ((NULL != lines[i]) && (StringUtils_startsWith(lines[i], "#"))) {
		/* Comment line */
		Debug_out(DEBUG_PGM, "%s: %s.\n", fname, lines[i]);
		++i;
	}
	if (NULL == lines[i]) {
		Debug_out(DEBUG_PGM, "%s: image ended too early.\n", fname);
		goto error2;
	}
	/* parse width and height */
	if (2 != sscanf(lines[i], "%d %d", &l_width, &l_height)) {
		Debug_out(DEBUG_PGM, "%s: error scanning line %d: %s.\n", fname, i, lines[i]);
		goto error2;
	}
	Debug_out(DEBUG_PGM, "%s: image size is %d x %d.\n", fname, l_width, l_height);
	++i;
	if (NULL == lines[i]) {
		Debug_out(DEBUG_PGM, "%s: image ended too early.\n", fname);
		goto error2;
	}
	/* skip image max value */
	Debug_out(DEBUG_PGM, "%s: image max value is %s.\n", fname, lines[i]);
	++i;
	if (NULL == lines[i]) {
		Debug_out(DEBUG_PGM, "%s: image ended too early.\n", fname);
		goto error2;
	}
	/* allocate image and parse it */
	*img = calloc(l_width * l_height, sizeof(unsigned char));
	if (NULL == img) {
		Debug_out(DEBUG_PGM, "%s: calloc failed.\n", fname);
		goto error2;
	}
	Debug_out(DEBUG_PGM, "%s: Result image buffer allocated.\n", fname);
	for (j = 0; j < l_width * l_height; ++j) {
		if (NULL == lines[i+j]) {
			Debug_out(DEBUG_PGM, "%s: image ended too early.\n", fname);
			goto error3;
		} else if (1 != sscanf(lines[i+j], "%u", &tmp)) {
			Debug_out(DEBUG_PGM, "%s: error scanning line %d: %s.\n", fname, i+j, lines[i+j]);
			goto error3;
		}
		Debug_out(DEBUG_PGM, "%s: Pixel %d is %d.\n", fname, j, tmp);
		(*img)[j] = tmp;
	}
	/* save width and height, and free parsed lines */
	if (NULL != width) {
		*width = l_width;
	}
	if (NULL != height) {
		*height = l_height;
	}
	Vector_free((void **) lines);
	return 0;

error3:
	free(img);
error2:
	Vector_free((void **) lines);
error1:
	return 1;
}
예제 #8
0
//!
//! \brief IrcConnection::readyRead Reads new data from the server and appends it to IrcConnection::_recvbuf.
//!
//! The IrcConnection::parseLines() method will be called afterwards.
//!
void IrcConnection::readyRead()
{
    _recvbuf.append(_sock->readAll());
    parseLines();
}