Changeset 272

Show
Ignore:
Timestamp:
07/01/06 17:11:09 (6 years ago)
Author:
knok
Message:

Added Container Hook system.
closes: #4.

Location:
MMagic/trunk
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • MMagic/trunk/ChangeLog

    r270 r272  
     12006-07-01  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
     2 
     3        * MMagic.pm (checktype_container): Added container check. 
     4          (Powerd by CodeFest 2006 Akihabara 
     5           https://members.fsij.org/trac/codefestakihabara2006) 
     6 
    172006-06-26  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
    28 
  • MMagic/trunk/MMagic.pm

    r270 r272  
    423423             '\.htm$' => 'text/html', 
    424424    }; 
     425    # content hook 
     426    $self->{chook} = {}; 
    425427    return bless $self, $class; 
    426428} 
     
    492494} 
    493495 
     496sub addContainerHook { 
     497    my $self = shift; 
     498    my $mtype = shift; 
     499    my $funcref = shift; 
     500    $self->{chook}->{$mtype} = $funcref; 
     501} 
     502 
    494503# Not implimented. 
    495504# 
     
    619628    return 'application/octet-stream' if (length($data) <= 0); 
    620629 
     630    $mtype = checktype_contents($self, $data); 
     631    return $mtype unless $mtype eq ""; 
     632 
    621633    $mtype = checktype_magic($self, $data); 
    622634 
     
    630642 
    631643    return $mtype; 
     644} 
     645 
     646sub checktype_container { 
     647    my $self = shift; 
     648    my $data = shift; 
     649    my $href = $self->{chook}; 
     650    foreach my $mtype (keys %$href) { 
     651        my $ret = &{$href->{$mtype}}($self, $data); 
     652        return $ret if $ret ne ""; 
     653    } 
     654    return ""; 
    632655} 
    633656