Esempio n. 1
0
/*----------------------------------------------------------------------
 * Start a new packet
 */
static void
start_new_packet (void)
{
    if (debug>=1)
        fprintf(stderr, "Start new packet\n");

    /* Write out the current packet, if required */
    write_current_packet();

    /* Ensure we parse the packet preamble as it may contain the time */
    parse_preamble();
}
Esempio n. 2
0
void dicom_load(const char *path, dicom_t *dicom,
                char *out_buffer, int buffer_size)
{
    FILE *in = fopen(path, "rb");
    int state = 0;
    const char *uid_name;

    element_t element = {
        .buffer = out_buffer,
        .buffer_size = buffer_size,
    };

    if (!parse_preamble(in)) {
        state |= STATE_IMPLICIT_VR;
    }

    while (true) {
        if (!parse_element(in, state, &element)) break;

        #define S(attr, tag_, v_) \
            if (element.tag.v == tag_.v) \
                dicom->attr = element.value.v_;

        S(instance_number,      TAG_INSTANCE_NUMBER,    is);
        S(slice_location,       TAG_SLICE_LOCATION,     ds);
        S(samples_per_pixel,    TAG_SAMPLES_PER_PIXEL,  us);
        S(rows,                 TAG_ROWS,               us);
        S(columns,              TAG_COLUMNS,            us);
        S(bits_allocated,       TAG_BITS_ALLOCATED,     us);
        S(bits_stored,          TAG_BITS_STORED,        us);
        S(high_bit,             TAG_HIGH_BIT,           us);

        #undef S

        if (element.tag.v == TAG_PIXEL_DATA.v)
            dicom->data_size = element.length;

        if (element.tag.v == TAG_TRANSFER_SYNTAX_UID.v) {
            uid_name = get_uid_name(element.value.ui);
            if (uid_name && strstr(uid_name, "Implicit")) {
                state |= STATE_IMPLICIT_VR;
            }
            if (!streq(element.value.ui, "1.2.840.10008.1.2.1")) {
                LOG_E("format not supported: %s", uid_name);
                CHECK(false);
            }
        }
    }

    fclose(in);
}
Esempio n. 3
0
int mime_parse(Octstr *boundary, Octstr *mime_content, Octstr **pap_content, 
               Octstr **push_data, List **content_headers, 
               Octstr **rdf_content)
{
    int ret;

    *pap_content = NULL;
    *push_data = NULL;
    *content_headers = NULL;
    *rdf_content = NULL;

    if (parse_preamble(&mime_content, boundary) < 0) {
        warning(0, "erroneous preamble");
        return 0;
    }
    if (parse_body_part(&mime_content, boundary, pap_content) <= 0) {
        warning(0, "erroneous control entity");
        return 0;
    }
    if (check_control_headers(pap_content) == 0) {
        warning(0, "erroneous control headers");
        return 0;
    }

    ret = -1;
    if ((ret = parse_encapsulation(&mime_content, boundary, push_data, 
                                   content_headers, rdf_content)) < 0) {
        warning(0, "erroneous content entity (push message)");
        return 0;
    } else if (ret == 0) {
        gw_assert(*rdf_content == NULL);
        if (octstr_len(mime_content) != 0)
            parse_epilogue(&mime_content);
        return 1;
    }

    if (check_control_headers(rdf_content) == 0) {
        warning(0, "erroneous capacity (rdf) headers");
        return 0;
    }

    if (octstr_len(mime_content) != 0)
        parse_epilogue(&mime_content);
    gw_assert(octstr_len(mime_content) == 0);
    
    return 1;
}