// File: /workspace/github_c_makefile_star2_O1/inflex[P]ripMIME/MIME_headers.c
// Function: MIMEH_parse_contentdisposition
int MIMEH_parse_contentdisposition( char *header_name, char *header_value, struct MIMEH_header_info *hinfo )
{
    char  *p;
    char *hv = strdup(header_value);

    // CONTENT DISPOSITION ------------------------------
    // CONTENT DISPOSITION ------------------------------
    // CONTENT DISPOSITION ------------------------------

    //LOGGER_log("%s:%d:DEBUG: Headers='%s'",FL,header_value);
    p = strstr(header_name,"content-disposition");
    if (p != NULL)
    {
        /** 20041216-1107:PLD: Increase our sanity **/
        hinfo->sanity++;

        // Change p to now point to the header VALUE, p no longer
        //      points to the content-disposition start!

        p = header_value;
        PLD_strlower( header_value );

        // Here we just check to find out what type of disposition we have.
        if (strstr(p,"inline"))
        {
            hinfo->content_disposition = _CDISPOSITION_INLINE;
        }
        else if (strstr(p,"form-data"))
        {
            hinfo->content_disposition = _CDISPOSITION_FORMDATA;
        }
        else if (strstr(p,"attachment"))
        {
            hinfo->content_disposition = _CDISPOSITION_ATTACHMENT;
        }
        else
        {
            hinfo->content_disposition = _CDISPOSITION_UNKNOWN;
        }

        // Copy the string to our content-transfer string storage field
        if (p != NULL)
        {
            char *q = p;

            // Step 1 - jump over any whitespace
            while ( *q == ' ' || *q == '\t') q++;

            // Step 2 - Copy the string
            PLD_strncpy( hinfo->content_disposition_string, q, _MIMEH_CONTENT_DISPOSITION_MAX);

            // Step 3 - clean up the string
            q = hinfo->content_disposition_string;
            while (*q && *q != ' ' && *q != '\t' && *q != '\n' && *q != '\r' && *q != ';') q++;

            // Step 4 - Terminate the string
            *q = '\0';
        }

        DMIMEH LOGGER_log("%s:%d:MIMEH_parse_contentdisposition:DEBUG: Disposition string = '%s'",FL, hv);

        // Commence to decode the disposition string into its components.
        p = strpbrk( hv, ";\t\n\r " );
        if (p != NULL)
        {
            //          struct PLD_strtok tx;
            char *param;

            hinfo->name[0]='\0';

            p++;
            param = p;
            while ( param != NULL )
            {
                int parse_result;
                char *data_end_point;

                if (MIMEH_DNORMAL) LOGGER_log("%s:%d:MIMEH_parse_contentdisposition:DEBUG: Parsing '%s'",FL,param);

                // Seek out possible 'filename' parameters

                parse_result = MIMEH_parse_header_parameter(hinfo, param, "filename", hinfo->name, sizeof(hinfo->name), &data_end_point);
                if (data_end_point > param) param = data_end_point;
                if (parse_result == 0) {
                    FNFILTER_filter(hinfo->name, _MIMEH_FILENAMELEN_MAX);
                    SS_push(&(hinfo->ss_filenames), hinfo->name, strlen(hinfo->name));
                    if (SS_count(&(hinfo->ss_filenames)) > 1)
                    {
                        MIMEH_set_defect(hinfo,MIMEH_DEFECT_MULTIPLE_FILENAMES);
                    }
                }

                param = strpbrk( param , ";\n\r\t " );
                if (param) param++;

                //param = PLD_strtok( &tx, NULL, ";\n\r\t " );
            } // While

            if ( hinfo->filename[0] == '\0' )
            {
                snprintf( hinfo->filename, sizeof(hinfo->filename), "%s", hinfo->name );
            }

            // Handle situations where we'll need the filename for the future.
            if ( hinfo->content_type == _CTYPE_MULTIPART_APPLEDOUBLE )
            {
                snprintf( glb.appledouble_filename, sizeof(glb.appledouble_filename), "%s", hinfo->filename );
                if (MIMEH_DNORMAL) LOGGER_log("%s:%d:MIMEH_parse_contentdisposition:DEBUG: Setting appledouble filename to: '%s'",FL,glb.appledouble_filename);
            }

        } // If the header-value contained ;'s ( indicating parameters )

    } // If the header-name actually contained 'content-disposition'

    if (hv != NULL) free(hv);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x23b0
movq %rax, %r13
leaq 0xc567(%rip), %rsi      # 0x16a17
movq %rbx, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa726
incl 0x18d30(%r14)
movq %r15, %rdi
callq 0xbf91
leaq 0xc554(%rip), %rsi      # 0x16a2b
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa4f1
movl $0x64, 0x17100(%r14)
jmp 0xa53e
leaq 0xc53a(%rip), %rsi      # 0x16a32
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa512
movl $0x12c, 0x17100(%r14) # imm = 0x12C
jmp 0xa53e
leaq 0xc092(%rip), %rsi      # 0x165ab
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa533
movl $0xc8, 0x17100(%r14)
jmp 0xa53e
movl $0x0, 0x17100(%r14)
testq %r15, %r15
je 0xa58e
movzbl (%r15), %eax
cmpl $0x20, %eax
je 0xa551
cmpl $0x9, %eax
jne 0xa556
incq %r15
jmp 0xa543
leaq 0x17104(%r14), %rbx
movl $0xa00, %edx            # imm = 0xA00
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbfb6
movabsq $0x800000100002601, %rax # imm = 0x800000100002601
movzbl (%rbx), %ecx
cmpq $0x3b, %rcx
ja 0xa586
btq %rcx, %rax
jb 0xa58b
incq %rbx
jmp 0xa577
movb $0x0, (%rbx)
cmpl $0x0, 0x21df7(%rip)     # 0x2c38c
jle 0xa5b4
leaq 0xc49e(%rip), %rdi      # 0x16a3c
leaq 0xad09(%rip), %rsi      # 0x152ae
movl $0x98f, %edx            # imm = 0x98F
movq %r13, %rcx
xorl %eax, %eax
callq 0xc960
leaq 0xb9ed(%rip), %rsi      # 0x15fa8
movq %r13, %rdi
callq 0x2300
testq %rax, %rax
je 0xa726
movq %rax, %r12
movq %r13, 0x8(%rsp)
leaq 0x6efe(%r14), %r15
movb $0x0, 0x6efe(%r14)
incq %r12
leaq 0x15ec8(%r14), %r13
leaq 0x10(%rsp), %rbx
leaq 0xbfbd(%rip), %rbp      # 0x165b6
cmpl $0x0, 0x21d8c(%rip)     # 0x2c38c
jle 0xa61f
leaq 0xc479(%rip), %rdi      # 0x16a82
leaq 0xac9e(%rip), %rsi      # 0x152ae
movl $0x9a1, %edx            # imm = 0x9A1
movq %r12, %rcx
xorl %eax, %eax
callq 0xc960
movq %r14, %rdi
movq %r12, %rsi
leaq 0x10535(%rip), %rdx     # 0x1ab61
movq %r15, %rcx
movl $0x27f7, %r8d           # imm = 0x27F7
movq %rbx, %r9
callq 0x93c8
movq 0x10(%rsp), %rcx
cmpq %r12, %rcx
cmovaq %rcx, %r12
testl %eax, %eax
jne 0xa68a
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xe6c5
movq %r15, %rdi
callq 0x2110
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x331f
movq %r13, %rdi
callq 0x342c
cmpl $0x2, %eax
jl 0xa68a
movq %r14, %rdi
movl $0xa, %esi
callq 0x802f
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2300
leaq 0x1(%rax), %r12
testq %rax, %rax
cmoveq %rax, %r12
jne 0xa5f9
leaq 0x5efd(%r14), %rbx
cmpb $0x0, 0x5efd(%r14)
jne 0xa6d0
leaq 0xd9cf(%rip), %rdx      # 0x1808d
movl $0x1001, %esi           # imm = 0x1001
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x66, 0x27f8(%r14)
movq 0x8(%rsp), %r13
jne 0xa726
leaq 0x1cc99(%rip), %rdi     # 0x2737f
leaq 0xd9a0(%rip), %rdx      # 0x1808d
movl $0x27f7, %esi           # imm = 0x27F7
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x0, 0x21c89(%rip)     # 0x2c38c
jle 0xa726
leaq 0xc3af(%rip), %rdi      # 0x16abb
leaq 0xab9b(%rip), %rsi      # 0x152ae
leaq 0x1cc65(%rip), %rcx     # 0x2737f
movl $0x9bf, %edx            # imm = 0x9BF
xorl %eax, %eax
callq 0xc960
testq %r13, %r13
je 0xa733
movq %r13, %rdi
callq 0x2030
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq