Beispiel #1
0
func pgsqlErrorParser(s *PgsqlStream) {

	m := s.message

	for len(s.data[s.parseOffset:]) > 0 {
		// read field type(byte1)
		field_type := s.data[s.parseOffset]
		s.parseOffset += 1

		if field_type == 0 {
			break
		}

		// read field value(string)
		field_value, err := common.ReadString(s.data[s.parseOffset:])
		if err != nil {
			logp.Err("Fail to read the column field")
		}
		s.parseOffset += len(field_value) + 1

		if field_type == 'M' {
			m.ErrorInfo = field_value
		} else if field_type == 'C' {
			m.ErrorCode = field_value
		} else if field_type == 'S' {
			m.ErrorSeverity = field_value
		}

	}
	logp.Debug("pgsqldetailed", "%s %s %s", m.ErrorSeverity, m.ErrorCode, m.ErrorInfo)
}
Beispiel #2
0
func pgsqlErrorParser(s *PgsqlStream, buf []byte) {
	m := s.message
	off := 0
	for off < len(buf) {
		// read field type(byte1)
		typ := buf[off]
		if typ == 0 {
			break
		}

		// read field value(string)
		val, err := common.ReadString(buf[off+1:])
		if err != nil {
			logp.Err("Failed to read the column field")
			break
		}
		off += len(val) + 2

		switch typ {
		case 'M':
			m.ErrorInfo = val
		case 'C':
			m.ErrorCode = val
		case 'S':
			m.ErrorSeverity = val
		}
	}
	detailedf("%s %s %s", m.ErrorSeverity, m.ErrorCode, m.ErrorInfo)
}
Beispiel #3
0
func (pgsql *Pgsql) parseExtReq(s *PgsqlStream, length int) (bool, bool) {
	// Ready for query -> Parse for an extended query request
	detailedf("Parse")

	m := s.message
	m.start = s.parseOffset
	m.IsRequest = true

	s.parseOffset += 1 //type
	s.parseOffset += length
	m.end = s.parseOffset
	m.Size = uint64(m.end - m.start)
	m.toExport = true

	query, err := common.ReadString(s.data[m.start+6:])
	if err != nil {
		detailedf("Invalid extended query request")
		return false, false
	}
	m.Query = query
	detailedf("Parse in an extended query request: %s", m.Query)

	// Ignore SET statement
	if strings.HasPrefix(m.Query, "SET ") {
		m.toExport = false
	}
	s.parseState = PgsqlExtendedQueryState
	return pgsql.parseMessageExtendedQuery(s)
}
Beispiel #4
0
func pgsqlFieldsParser(s *PgsqlStream) {
	m := s.message

	// read field count (int16)
	field_count := int(common.Bytes_Ntohs(s.data[s.parseOffset : s.parseOffset+2]))
	s.parseOffset += 2
	logp.Debug("pgsqldetailed", "Row Description field count=%d", field_count)

	fields := []string{}
	fields_format := []byte{}

	for i := 0; i < field_count; i++ {
		// read field name (null terminated string)
		field_name, err := common.ReadString(s.data[s.parseOffset:])
		if err != nil {
			logp.Err("Fail to read the column field")
		}
		fields = append(fields, field_name)
		m.NumberOfFields += 1
		s.parseOffset += len(field_name) + 1

		// read Table OID (int32)
		s.parseOffset += 4

		// read Column Index (int16)
		s.parseOffset += 2

		// read Type OID (int32)
		s.parseOffset += 4

		// read column length (int16)
		s.parseOffset += 2

		// read type modifier (int32)
		s.parseOffset += 4

		// read format (int16)
		format := common.Bytes_Ntohs(s.data[s.parseOffset : s.parseOffset+2])
		fields_format = append(fields_format, byte(format))
		s.parseOffset += 2

		logp.Debug("pgsqldetailed", "Field name=%s, format=%d", field_name, format)
	}
	m.Fields = fields
	m.FieldsFormat = fields_format
	if m.NumberOfFields != field_count {
		logp.Err("Missing fields from RowDescription. Expected %d. Received %d", field_count, m.NumberOfFields)
	}
}
Beispiel #5
0
func pgsqlFieldsParser(s *PgsqlStream, buf []byte) error {
	m := s.message

	if len(buf) < 2 {
		return errEmptyFieldsBuffer
	}

	// read field count (int16)
	off := 2
	fieldCount := readCount(buf)
	detailedf("Row Description field count=%d", fieldCount)

	fields := []string{}
	fieldsFormat := []byte{}

	for i := 0; i < fieldCount; i++ {
		if len(buf) <= off {
			return errFieldBufferShort
		}

		// read field name (null terminated string)
		fieldName, err := common.ReadString(buf[off:])
		if err != nil {
			return errNoFieldName
		}
		fields = append(fields, fieldName)
		m.NumberOfFields += 1
		off += len(fieldName) + 1

		// read Table OID (int32)
		off += 4

		// read Column Index (int16)
		off += 2

		// read Type OID (int32)
		off += 4

		// read column length (int16)
		off += 2

		// read type modifier (int32)
		off += 4

		// read format (int16)
		format := common.Bytes_Ntohs(buf[off : off+2])
		off += 2
		fieldsFormat = append(fieldsFormat, byte(format))

		detailedf("Field name=%s, format=%d", fieldName, format)
	}

	if off < len(buf) {
		return errFieldBufferBig
	}

	m.Fields = fields
	m.FieldsFormat = fieldsFormat
	if m.NumberOfFields != fieldCount {
		logp.Err("Missing fields from RowDescription. Expected %d. Received %d",
			fieldCount, m.NumberOfFields)
	}
	return nil
}