Class ::nntp::Session

::nntp::Session[i] create ... \
           [ -debug:int,slot=::nntp::Session::slot::debug (default "1") ] \
           [ -port:int,slot=::nntp::Session::slot::port,required port:int,slot=::nntp::Session::slot::port,required ] \
           [ -server:required server:required ]

Support for NNTP session. In essence: 1) login 2) run some commands 3) logout
Defined in packages/xowiki/tcl/nntp-procs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::nntp::Session \
     -superclass ::nx::Object

Methods (to be applied on the object)

  • refresh (scripted, public)

     nntp::Session[i] refresh [ -server server ] [ -port port ] \
        [ -group group ]

    Refresh articles in the database with messages from the NNTP news server. ns_section ns/server/${server}/acs/nntp { ns_param NttpUser gustafn ns_param NttpPassword isxqsomzp } ad_schedule_proc -thread t 5m ::nntp::Session refresh

    Switches:
    -server (optional, defaults to "news.eternal-september.org")
    -port (optional, defaults to "119")
    -group (optional, defaults to "comp.lang.tcl")

    Testcases:
    No testcase defined.
    set nntp_user [ns_config "ns/server/[ns_info server]/acs/nntp" NttpUser]
    if {$nntp_user eq ""} {
        error "NntpUser is not configured"
    }
    
    set s [nntp::Session new -server $server -port $port]
    try {
        $s login $nntp_user [ns_config "ns/server/[ns_info server]/acs/nntp" NttpPassword]
        $s group $group
    } finally {
        $s destroy
    }

Methods (to be applied on instances)

  • destroy (scripted, public)

     <instance of nntp::Session[i]> destroy

    Log-out from the session and destroy the session object.

    Testcases:
    No testcase defined.
    ns_log notice "DISCONNECT from channel ${:channel}"
    :writeLine QUIT
    ns_connchan close ${:channel}
    next
  • group (scripted, public)

     <instance of nntp::Session[i]> group name

    update all entries from the specified group

    Parameters:
    name (required)

    Testcases:
    No testcase defined.
    :writeLine "GROUP $name"
    lassign [:readLine] status nr available_from available_to groupname
    ns_log notice "FROM $available_from TO $available_to"
    if {$available_from eq ""} {
        error "nntp group '$name': status '$status' available_from must not be empty"
    }
    lassign [lindex [acs::dc list_of_lists -prepare text dbqd..get_group_info {
        select nntp_id, last_id from nntp_groups where name = :name
    }] 0] nntp_id last_id
    set count 1000
    set fetched_articles [::acs::dc list -prepare integer dbqd..fetch_article_ids {
        select article_id from nntp_articles where nntp_id = :nntp_id
    }]
    ns_log notice "LAST_ID $last_id available_from $available_from, we have [llength $fetched_articles] articles loaded"
    
    for {set article_id $available_from} {$article_id <= $available_to} {incr article_id} {
        if {0 && $last_id > $article_id} {
            #
            # Optimization, don't use it, if we want to refetch some articles
            #
            continue
        }
        if {[incr count -1] < 0} break
        if {$article_id in $fetched_articles} {
            continue
        }
        ns_log notice FETCH ARTICLE $article_id
        set d [:readArticle $article_id]
        ns_log notice INSERT ARTICLE $article_id: $d
        ::xo::dc transaction {
            xo::dc dml insert_article {
                insert into nntp_articles (article_id, nntp_id, dict)
                values (:article_id, :nntp_id, :d)
            }
            xo::dc dml update_last_id {
                update nntp_groups set last_id = :article_id
            }
        }
    }
  • login (scripted, public)

     <instance of nntp::Session[i]> login user password

    Log-in with the provided credentials

    Parameters:
    user (required)
    password (required)

    Testcases:
    No testcase defined.
    :writeLine "AUTHINFO USER $user"
    set line [:readLine]
    :writeLine "AUTHINFO PASS $password"
    set line [:readLine]