// File: /workspace/github_c_makefile_star2_O2/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 0xb93f(%rip), %rsi      # 0x15a47
movq %rbx, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa381
incl 0x18d30(%r14)
movq %r15, %rdi
callq 0xba23
leaq 0xb92c(%rip), %rsi      # 0x15a5b
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa149
movl $0x64, 0x17100(%r14)
jmp 0xa193
leaq 0xb912(%rip), %rsi      # 0x15a62
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa16a
movl $0x12c, 0x17100(%r14) # imm = 0x12C
jmp 0xa193
leaq 0xb46a(%rip), %rsi      # 0x155db
movq %r15, %rdi
callq 0x23d0
testq %rax, %rax
je 0xa18b
movl $0xc8, 0x17100(%r14)
jmp 0xa193
andl $0x0, 0x17100(%r14)
testq %r15, %r15
je 0xa1e3
movzbl (%r15), %eax
cmpl $0x20, %eax
je 0xa1a6
cmpl $0x9, %eax
jne 0xa1ab
incq %r15
jmp 0xa198
leaq 0x17104(%r14), %rbx
movl $0xa00, %edx            # imm = 0xA00
movq %rbx, %rdi
movq %r15, %rsi
callq 0xba3e
movabsq $0x800000100002601, %rax # imm = 0x800000100002601
movzbl (%rbx), %ecx
cmpq $0x3b, %rcx
ja 0xa1db
btq %rcx, %rax
jb 0xa1e0
incq %rbx
jmp 0xa1cc
movb $0x0, (%rbx)
cmpl $0x0, 0x211a2(%rip)     # 0x2b38c
jle 0xa209
leaq 0xb879(%rip), %rdi      # 0x15a6c
leaq 0xa0e4(%rip), %rsi      # 0x142de
movl $0x98f, %edx            # imm = 0x98F
movq %r13, %rcx
xorl %eax, %eax
callq 0xc2a1
leaq 0xadc8(%rip), %rsi      # 0x14fd8
movq %r13, %rdi
callq 0x2300
testq %rax, %rax
je 0xa381
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 0xb398(%rip), %rbp      # 0x155e6
testq %r12, %r12
je 0xa301
cmpl $0x0, 0x2112e(%rip)     # 0x2b38c
jle 0xa27d
leaq 0xb84b(%rip), %rdi      # 0x15ab2
leaq 0xa070(%rip), %rsi      # 0x142de
movl $0x9a1, %edx            # imm = 0x9A1
movq %r12, %rcx
xorl %eax, %eax
callq 0xc2a1
movq %r14, %rdi
movq %r12, %rsi
leaq 0xf8c7(%rip), %rdx      # 0x19b51
movq %r15, %rcx
movl $0x27f7, %r8d           # imm = 0x27F7
movq %rbx, %r9
callq 0x9073
movq 0x10(%rsp), %rcx
cmpq %r12, %rcx
cmovaq %rcx, %r12
testl %eax, %eax
jne 0xa2e6
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0xdf02
movq %r15, %rdi
callq 0x2110
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x31c2
movq %r13, %rdi
callq 0x32cd
cmpl $0x2, %eax
jl 0xa2e6
movq %r14, %rdi
pushq $0xa
popq %rsi
callq 0x7d08
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2300
leaq 0x1(%rax), %r12
testq %rax, %rax
cmoveq %rax, %r12
jmp 0xa24e
leaq 0x5efd(%r14), %rbx
cmpb $0x0, 0x5efd(%r14)
jne 0xa32b
leaq 0xcd47(%rip), %rdx      # 0x17060
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 0xa381
leaq 0x1c03e(%rip), %rdi     # 0x2637f
leaq 0xcd18(%rip), %rdx      # 0x17060
movl $0x27f7, %esi           # imm = 0x27F7
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2140
cmpl $0x0, 0x2102e(%rip)     # 0x2b38c
jle 0xa381
leaq 0xb784(%rip), %rdi      # 0x15aeb
leaq 0x9f70(%rip), %rsi      # 0x142de
leaq 0x1c00a(%rip), %rcx     # 0x2637f
movl $0x9bf, %edx            # imm = 0x9BF
xorl %eax, %eax
callq 0xc2a1
movq %r13, %rdi
callq 0x2030
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq