# Path: kraut_parser/models.py
# class URI_Object(models.Model):
#     uri_value = models.CharField(max_length=255)
#     uri_type = models.CharField(max_length=255)
#     condition = models.CharField(max_length=255, default="equals")
#     observables = models.ManyToManyField(Observable)
# 
#     def __unicode__(self):
#         if self.uri_value:
#             return u"%s" % (self.uri_value)
#         else:
#             return u"URI Object"
# 
#     class Meta:
#         unique_together = (("uri_value", "uri_type", "condition"),)
# 
# class Port_Object(models.Model):
#     port = models.IntegerField(unique=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.port)


import dateutil, pytz, json
from kraut_parser.models import URI_Object, Port_Object
    """
    client_dict_list = []
    if 'http_request_response' in http_obj:
        for request in http_obj['http_request_response']:
            client_dict = {
                'raw_header': None,
                'message_body': None,
                'request_method': 'GET',
                'request_uri': '/',
                'request_version': '1.1',
                'user_agent': None,
                'domain_name': None,
                'port': None,
            }
            # get message body
            if 'http_client_request' in request and 'http_message_body' in request['http_client_request']:
                client_dict['message_body'] = request['http_client_request']['http_message_body'].get('message_body', None)
            # get raw header
            if 'http_client_request' in request and 'http_request_header' in request['http_client_request']:
                client_dict['raw_header'] = request['http_client_request']['http_request_header'].get('raw_header', None)
                # get host information
                if 'parsed_header' in request['http_client_request']['http_request_header']:
                    host = request['http_client_request']['http_request_header']['parsed_header'].get('host', None)
                    if host:
                        if 'domain_name' in host:
                            uri_dict = {
                                'uri_value': host['domain_name'].get('value', 'No Value'),
                                'uri_type': 'Domain Name',
                                'condition': 'equals'
                            }

# Path: kraut_parser/models.py
# class URI_Object(models.Model):
#     uri_value = models.CharField(max_length=255)
#     uri_type = models.CharField(max_length=255)
#     condition = models.CharField(max_length=255, default="equals")
#     observables = models.ManyToManyField(Observable)
# 
#     def __unicode__(self):
#         if self.uri_value:
#             return u"%s" % (self.uri_value)
#         else:
#             return u"URI Object"
# 
#     class Meta:
#         unique_together = (("uri_value", "uri_type", "condition"),)
# 
# class Port_Object(models.Model):
#     port = models.IntegerField(unique=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.port)


# Path: kraut_parser/cybox_functions.py
import dateutil, pytz, json
from kraut_parser.models import URI_Object, Port_Object

    """
    client_dict_list = []
    if 'http_request_response' in http_obj:
        for request in http_obj['http_request_response']:
            client_dict = {
                'raw_header': None,
                'message_body': None,
                'request_method': 'GET',
                'request_uri': '/',
                'request_version': '1.1',
                'user_agent': None,
                'domain_name': None,
                'port': None,
            }
            # get message body
            if 'http_client_request' in request and 'http_message_body' in request['http_client_request']:
                client_dict['message_body'] = request['http_client_request']['http_message_body'].get('message_body', None)
            # get raw header
            if 'http_client_request' in request and 'http_request_header' in request['http_client_request']:
                client_dict['raw_header'] = request['http_client_request']['http_request_header'].get('raw_header', None)
                # get host information
                if 'parsed_header' in request['http_client_request']['http_request_header']:
                    host = request['http_client_request']['http_request_header']['parsed_header'].get('host', None)
                    if host:
                        if 'domain_name' in host:
                            uri_dict = {
                                'uri_value': host['domain_name'].get('value', 'No Value'),
                                'uri_type': 'Domain Name',
                                'condition': 'equals'
                            }

                            uri_object, uri_object_created = URI_Object.objects.get_or_create(**uri_dict)