lavf/ftp: make response parsing more RFC compliant
Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
This commit is contained in:
		
							parent
							
								
									cf8c44fc47
								
							
						
					
					
						commit
						3ba6dce48d
					
				@ -119,7 +119,7 @@ static int ftp_get_line(FTPContext *s, char *line, int line_size)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static int ftp_status(FTPContext *s, char **line, const int response_codes[])
 | 
					static int ftp_status(FTPContext *s, char **line, const int response_codes[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int err, i, dash = 0, result = 0, code_found = 0;
 | 
					    int err, i, dash = 0, result = 0, code_found = 0, linesize;
 | 
				
			||||||
    char buf[CONTROL_BUFFER_SIZE];
 | 
					    char buf[CONTROL_BUFFER_SIZE];
 | 
				
			||||||
    AVBPrint line_buffer;
 | 
					    AVBPrint line_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -135,25 +135,36 @@ static int ftp_status(FTPContext *s, char **line, const int response_codes[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        av_log(s, AV_LOG_DEBUG, "%s\n", buf);
 | 
					        av_log(s, AV_LOG_DEBUG, "%s\n", buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (strlen(buf) < 4)
 | 
					        linesize = strlen(buf);
 | 
				
			||||||
            continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        err = 0;
 | 
					        err = 0;
 | 
				
			||||||
        for (i = 0; i < 3; ++i) {
 | 
					        if (linesize >= 3) {
 | 
				
			||||||
            if (buf[i] < '0' || buf[i] > '9')
 | 
					            for (i = 0; i < 3; ++i) {
 | 
				
			||||||
                continue;
 | 
					                if (buf[i] < '0' || buf[i] > '9') {
 | 
				
			||||||
            err *= 10;
 | 
					                    err = 0;
 | 
				
			||||||
            err += buf[i] - '0';
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                err *= 10;
 | 
				
			||||||
 | 
					                err += buf[i] - '0';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        dash = !!(buf[3] == '-');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; response_codes[i]; ++i) {
 | 
					        if (!code_found) {
 | 
				
			||||||
            if (err == response_codes[i]) {
 | 
					            for (i = 0; response_codes[i]; ++i) {
 | 
				
			||||||
                if (line)
 | 
					                if (err == response_codes[i]) {
 | 
				
			||||||
                    av_bprintf(&line_buffer, "%s", buf);
 | 
					                    code_found = 1;
 | 
				
			||||||
                code_found = 1;
 | 
					                    result = err;
 | 
				
			||||||
                result = err;
 | 
					                    break;
 | 
				
			||||||
                break;
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (code_found) {
 | 
				
			||||||
 | 
					            if (line)
 | 
				
			||||||
 | 
					                av_bprintf(&line_buffer, "%s\r\n", buf);
 | 
				
			||||||
 | 
					            if (linesize >= 4) {
 | 
				
			||||||
 | 
					                if (!dash && buf[3] == '-')
 | 
				
			||||||
 | 
					                    dash = err;
 | 
				
			||||||
 | 
					                else if (err == dash && buf[3] == ' ')
 | 
				
			||||||
 | 
					                    dash = 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user