Пример #1
0
int main(int argc, char *argv[])
{
   int ret;

   /* etterlog copyright */
   fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", 
                      GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS);
  
  
   /* allocate the global target */
   SAFE_CALLOC(GBL_TARGET, 1, sizeof(struct target_env));
  
   /* initialize to all target */
   GBL_TARGET->all_mac = 1;
   GBL_TARGET->all_ip = 1;
   GBL_TARGET->all_port = 1;
   
   /* getopt related parsing...  */
   parse_options(argc, argv);

   /* get the global header */
   ret = get_header(&GBL.hdr);
   if (ret == -EINVALID)
      FATAL_ERROR("Invalid log file");
   
   fprintf(stderr, "Log file version    : %s\n", GBL.hdr.version);
   fprintf(stderr, "Timestamp           : %s", ctime((time_t *)&GBL.hdr.tv.tv_sec));
   fprintf(stderr, "Type                : %s\n\n", (GBL.hdr.type == LOG_PACKET) ? "LOG_PACKET" : "LOG_INFO" );
  
   
   /* analyze the logfile */
   if (GBL.analyze)
      analyze();

   /* rewind the log file and skip the global header */
   gzrewind(GBL_LOG_FD);
   get_header(&GBL.hdr);
   
   /* create the connection table (respecting the filters) */
   if (GBL.connections)
      conn_table_create();

   /* display the connection table */
   if (GBL.connections && !GBL.decode)
      conn_table_display();

   /* extract files from the connections */
   if (GBL.decode)
      conn_decode();
   
   /* not interested in the content... only analysis */
   if (GBL.analyze || GBL.connections)
      return 0;
   
   /* display the content of the logfile */
   display();
   
   return 0;
}
Пример #2
0
PyObject *
typecast_cast(PyObject *obj, const char *str, Py_ssize_t len, PyObject *curs)
{
    PyObject *old, *res = NULL;
    typecastObject *self = (typecastObject *)obj;

    Py_INCREF(obj);
    old = ((cursorObject*)curs)->caster;
    ((cursorObject*)curs)->caster = obj;

    if (self->ccast) {
        res = self->ccast(str, len, curs);
    }
    else if (self->pcast) {
        PyObject *s;
        /* XXX we have bytes in the adapters and strings in the typecasters.
         * are you sure this is ok?
         * Notice that this way it is about impossible to create a python
         * typecaster on a binary type. */
        if (str) {
#if PY_MAJOR_VERSION < 3
            s = PyString_FromStringAndSize(str, len);
#else
            s = conn_decode(((cursorObject *)curs)->conn, str, len);
#endif
        }
        else {
            Py_INCREF(Py_None);
            s = Py_None;
        }
        if (s) {
            res = PyObject_CallFunctionObjArgs(self->pcast, s, curs, NULL);
            Py_DECREF(s);
        }
    }
    else {
        PyErr_SetString(Error, "internal error: no casting function found");
    }

    ((cursorObject*)curs)->caster = old;
    Py_DECREF(obj);

    return res;
}
Пример #3
0
int sdp_decode(struct sdp_session *sess, struct mbuf *mb, bool offer)
{
	struct sdp_media *m;
	struct pl pl, val;
	struct le *le;
	char type = 0;
	int err = 0;

	if (!sess || !mb)
		return EINVAL;

	sdp_session_rreset(sess);

	for (le=sess->medial.head; le; le=le->next) {

		m = le->data;

		sdp_media_rreset(m);
	}

	pl.p = (const char *)mbuf_buf(mb);
	pl.l = mbuf_get_left(mb);

	m = NULL;

	for (;pl.l && !err; pl.p++, pl.l--) {

		switch (*pl.p) {

		case '\r':
		case '\n':
			if (!type)
				break;

			switch (type) {

			case 'a':
				err = attr_decode(sess, m,
						  m ? &m->rdir : &sess->rdir,
						  &val);
				break;

			case 'b':
				err = bandwidth_decode(m? m->rbwv : sess->rbwv,
						       &val);
				break;

			case 'c':
				err = conn_decode(m ? &m->raddr : &sess->raddr,
						  &val);
				break;

			case 'm':
				err = media_decode(&m, sess, offer, &val);
				break;

			case 'v':
				err = version_decode(&val);
				break;
			}

#if 0
			if (err)
				re_printf("*** %c='%r': %s\n", type, &val,
					  strerror(err));
#endif

			type = 0;
			break;

		default:
			if (type) {
				val.l++;
				break;
			}

			if (pl.l < 2 || *(pl.p + 1) != '=') {
				err = EBADMSG;
				break;
			}

			type  = *pl.p;
			val.p = pl.p + 2;
			val.l = 0;

			pl.p += 1;
			pl.l -= 1;
			break;
		}
	}

	if (err)
		return err;

	if (type)
		return EBADMSG;

	for (le=sess->medial.head; le; le=le->next)
		sdp_media_align_formats(le->data, offer);

	return 0;
}