IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PureBasic Discussion :

acces nntp newsgroup


Sujet :

PureBasic

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2
    Points : 1
    Points
    1
    Par défaut acces nntp newsgroup
    Bonjour,

    je voudrait acceder aux newsgroup via un programme purebasic.
    j'ai debute un code, mais je n'arrive pas a obtenir la liste de tous les newsgroup disponible

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    liste.s = ""
     
    Buffer.d = AllocateMemory(10000000)
    If InitNetwork() = 0
      MessageRequester("Error", "impossible d'initialiser le reseau", 0)
      End
    EndIf
     
    retour_chariot.s=Chr(13)+Chr(10)
    ; ============CHANGE HERE ===================
    usenet_provider.s   = "europe.newsdemon.com"
    login.s=""
    password.s=""
    Port.l = 119
    ; ============CHANGE HERE ===================
    ConnectionID = OpenNetworkConnection(usenet_provider, Port)
    If ConnectionID 
      Debug "connexion"
      a.s = PeekS(Buffer.d,ReceiveNetworkData(ConnectionID, Buffer.d , 10000000)) 
      Debug a
      Debug "****************"
      ; ************************************************************************************
      ; ************************************************************************************
      ;                    LOGIN sur compte privé !!
      SendNetworkString(ConnectionID, "AUTHINFO USER "+login+retour_chariot) 
      ab.d= ReceiveNetworkData(ConnectionID, Buffer.d , 10000000)
      b.s = PeekS(Buffer.d,ab.d)   
      code_erreur.s = (StringField(b.s, 1, " ") )
    ;  Debug code_erreur.s
     
      SendNetworkString(ConnectionID, "AUTHINFO PASS "+password+retour_chariot)
      ab.d= ReceiveNetworkData(ConnectionID, Buffer.d , 10000000)
      b.s = PeekS(Buffer.d,ab.d)   
      code_erreur = (StringField(b.s, 1, " ") )
    ;  Debug code_erreur.s
    ;Debug "******************"
     
     
     
      ; ************************************************************************************
      ; ************************************************************************************
      ; ; *** recupere la liste des groupes ***
      ;
       SendNetworkString(ConnectionID, "LIST"+retour_chariot)
       ab.d= ReceiveNetworkData(ConnectionID, Buffer.d  , 10000000)
       b.s = PeekS(Buffer.d ,ab.d) 
       nbr_ligne = CountString( b.s, Chr(13)) 
       Debug "nombre ligne : " + Str(nbr_ligne)
       For i=1 To nbr_ligne
        liste = (StringField(b.s, i, Chr(13)) ):liste$=Mid(liste$,2,Len(liste$))
    ;    Debug liste
       Next i 
    ;   Debug "******************"
     
    EndIf
    quelqu'un peut m'aider ?

  2. #2
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 261
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 261
    Points : 9 924
    Points
    9 924
    Billets dans le blog
    8
    Par défaut
    Attention tu déclares une variable Liste.s ="" et plus loin dans ton code je vois
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    liste$=Mid(liste$,2,Len(liste$))
    Liste.s et Liste$ sont deux variables distinctes.

    Sinon par curiosité j'ai fait un essai avec news.free.fr et j'obtiens une liste, j'ai aussi essayé de me connecter avec mon compte free, et ça fonctionne, si je mets un mauvais mot de passe j'ai un message d'erreur, si je mets le bon mot de passe, j'ai la réponse 'OK'. Voici mon test

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    NewList ListNewsGroup.s()
     
    *Buffer = AllocateMemory(10000000)
    If InitNetwork() = 0
      MessageRequester("Error", "impossible d'initialiser le reseau", 0)
      End
    EndIf
     
    ; ============CHANGE HERE ===================
    usenet_provider.s   = "news.free.fr"
    login.s="xxx@free.fr"
    password.s="yyy"
    Port.l = 995
     
    ; ============CHANGE HERE ===================
    ConnectionID = OpenNetworkConnection(usenet_provider, Port)
     
    If ConnectionID 
      Debug "connexion"
      a.s = PeekS(*Buffer, ReceiveNetworkData(ConnectionID, *Buffer, 10000000)) 
      Debug a
      Debug "****************"
      ; ************************************************************************************
     
    ;Je peux aussi me connecter avec mon compte Free, il suffit d'enlever les commentaires des lignes suivantes pour tester
     
    ;   SendNetworkString(ConnectionID, "AUTHINFO USER " + login + #CRLF$) 
    ;   Reponse.i = ReceiveNetworkData(ConnectionID, *Buffer, 10000000)
    ;   b.s = PeekS(*Buffer, Reponse)   
    ;   Debug b
    ;   SendNetworkString(ConnectionID, "AUTHINFO PASS " + password + #CRLF$) 
    ;   Reponse.i = ReceiveNetworkData(ConnectionID, *Buffer, 10000000)
    ;   b.s = PeekS(*Buffer, Reponse)   
    ;   Debug b  
     
      SendNetworkString(ConnectionID, "LIST" + #CRLF$) 
      Reponse.i = ReceiveNetworkData(ConnectionID, *Buffer, 10000000)
      b.s = PeekS(*Buffer, Reponse)
      nbr_ligne = CountString( b.s, #CR$)    
     
      Debug "Nombre de lignes " + Str(nbr_ligne)
     
      ;Stocke la liste dans une liste chainées
      For i = 1 To nbr_ligne
        AddElement(ListNewsGroup())
        ListNewsGroup() = StringField(b, i, #CR$)
      Next
     
      ;Affiche la liste 
      ForEach ListNewsGroup()
        Debug ListNewsGroup() 
      Next
     
      CloseNetworkConnection(ConnectionID)
      FreeMemory(*Buffer)
    EndIf
    Voici un échantillon de ce que j'obtiens avec mon login

    connexion
    200 news-4.free.fr (2-1) NNRP Service Ready - newsmaster@proxad.net (posting ok)

    ****************
    381 PASS required

    281 Ok

    Nombre de lignes 259
    215 Newsgroups in form "group high low flags".

    clari.web.local.nebraska 0000001018 0000000920 m

    borland.public.bes.appserver.ejb 0000000957 0000000958 y

    de.alt.ofowgexy.com.mx 0000000001 0000000002 y

    clari.web.local.maryland 0000002130 0000001933 m

    alt.personals.big-folk 0000001025 0000000991 y

    microsoft.public.tw.visio 0000000133 0000000128 y

    macromedia.general.france 0000157411 0000157398 y
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 2
    Points : 1
    Points
    1
    Par défaut autre soucis
    Ok, j'ai un peu continué, et j'arrive a me connecter, obtenir la liste des newsgroups du server, a me connecter sur un groupe precis.
    Mais maintenant, quand j'essaye d'obtenir l'entete et le corp du message, je n'est pas la meme chose, alors que je passe le meme numero d'article.

    Voici le code créer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
     
    Enumeration
      #fichier
    EndEnumeration
     
    usenet_provider.s   = "europe.newsdemon.com"
    login.s=""
    password.s=""
    Port.l = 119
     
     
    Global ConnectionID.l = 0
    Global retour_chariot.s=Chr(13)+Chr(10)
    Global nombre_groupes.l = 0
    Global Dim nom_groupe.s(500000)
    Global Dim index_article_1.l(500000)
    Global Dim index_article_fin.l(500000)
     
     
    Global liste.s = ""
    Global Dim code_erreur.s(1000)
     
    Global Buffer.d 
     
    code_erreur(281) = "Authentication succeeded"
    code_erreur(480) = "Authentication required"
    code_erreur(500) = "Command Not understood"
    code_erreur(501) = "Command Not supported"
    code_erreur(502) = "No permission"
    code_erreur(503) = "Program error, function Not performed"
    code_erreur(381) = "More authentication information required"
    code_erreur(482) = "Authentication rejected"
     
    If InitNetwork() = 0
      MessageRequester("Error", "impossible d'initialiser le reseau", 0)
      End
    EndIf
     
    ConnectionID = OpenNetworkConnection(usenet_provider, Port)
    If ConnectionID 
      ;;;;;;;;;;;;;;;;;;;;
      ; AUTHENTIFICATION ;
      ;;;;;;;;;;;;;;;;;;;;
     
      Buffer = AllocateMemory(10000000)
      PeekS(Buffer.d,ReceiveNetworkData(ConnectionID, Buffer , 10000000)) 
      SendNetworkString(ConnectionID, "AUTHINFO USER "+login+retour_chariot) 
      FreeMemory(buffer)
      Buffer = AllocateMemory(10000000)
      ab.d= ReceiveNetworkData(ConnectionID, Buffer , 10000000)
      b.s = PeekS(Buffer,ab)   
      code_retour.s = (StringField(b, 1, " ") )
      SendNetworkString(ConnectionID, "AUTHINFO PASS "+password+retour_chariot)
      FreeMemory(buffer)
      Buffer = AllocateMemory(10000000)
      ab = ReceiveNetworkData(ConnectionID, Buffer , 10000000)
      b = PeekS(Buffer,ab)   
      FreeMemory(buffer)
      code_retour = (StringField(b, 1, " ") )
      If Val(code_retour) <> 281
        CloseNetworkConnection(ConnectionID)
        MessageRequester("Desolé","l'authentification a échouée : " + Chr(10) + Chr(13) + code_erreur(Val(code_retour)))
        End
      EndIf
     
      nom_group.s="alt.binaries.games.dox "
      SendNetworkString(ConnectionID, "GROUP " + nom_group + retour_chariot)
     
      Buffer = AllocateMemory(100000)
      b = PeekS(Buffer,ReceiveNetworkData(ConnectionID, Buffer.d , 100000)) 
      code_erreur.s = (StringField(b.s, 1, " ") )
      nbr_article.s = (StringField(b.s, 2, " ") )
      premier_art.s = (StringField(b.s, 3, " ") )
      dernier_art.s = (StringField(b.s, 4, " ") )
      Debug "index du premier article "+ premier_art
      Debug "index du dernier article "+dernier_art
      FreeMemory(buffer)
      corp=0
     
      premier_art = "1170000"
     
     
    Debug "''''''''''''''''''''"
     
    CreateFile(#fichier,"c:\headers.txt")
    For i.l = Val(premier_art)  To Val(premier_art) + 3
      Buffer = AllocateMemory(200000)
      SendNetworkString(ConnectionID, "HEAD " + Str(i) + retour_chariot)
      ReceiveNetworkData(ConnectionID, Buffer , 200000)
      b.s = PeekS(Buffer,-1,#PB_Ascii )
      Debug b
      FreeMemory(buffer)
      If StringField(b, 1, " ") = "480"
        Goto finnext
      EndIf
      WriteString(#fichier, b)
      WriteString(#fichier,"*********************")
      If FindString(b,"Subject: ",0)
        Debut.l = FindString(b,"Subject: ",0) +9
        fin.l = FindString(b,Chr(13) + Chr(10), FindString(b,"Subject: ",0))
        Debug Mid(b, debut , fin-debut)
      EndIf
    ;  Debug Str(i)
      finnext:
    Next i
    CloseFile(#fichier)
     
    Debug "//////////////////"
    For i.l = Val(premier_art)  To Val(premier_art) + 3
      buffer = 0
      Buffer = AllocateMemory(200000)
      SendNetworkString(ConnectionID, "BODY " + Str(i) + retour_chariot)
      ReceiveNetworkData(ConnectionID, Buffer , 200000)
      b = PeekS(Buffer,-1,#PB_Ascii )
      FreeMemory(buffer)
      If StringField(b, 1, " ") = "480"
        Goto finnext2
      EndIf
      CreateFile(#fichier,"c:\"+Str(i)+".txt")
      WriteString(#fichier, b)
      If FindString(b,"Subject: ",0)
        Debut.l = FindString(b,"Subject: ",0) +9
        fin.l = FindString(b,Chr(13) + Chr(10), FindString(b,"Subject: ",0))
        Debug Mid(b, debut , fin-debut)
      EndIf
    ;  Debug Str(i)
      finnext2:
      CloseFile(#fichier)
    Next i
     
    CloseNetworkConnection(ConnectionID)
     
    End
    Dans mon code, pour tester, je veut charger le code 1170000 et les 3 suivant. C'est un code fixe qui devrait toujours etre identique.
    Quand je l'execute, j'ai divers probleme :
    1) parfois, je n'ai pas toujours le meme entete qui ressort.
    2) le corps du fichier a charger est SOUVENT different du 1170000.

Discussions similaires

  1. Accès au newsgroup fr.comp.lang.c
    Par habilité dans le forum Outlook Express / Windows Mail
    Réponses: 4
    Dernier message: 23/07/2007, 19h00
  2. [Windows]accès base de registre windows
    Par Greg01 dans le forum API standards et tierces
    Réponses: 27
    Dernier message: 05/06/2007, 15h14
  3. Package pour gerer le protocole NNTP (Newsgroups) ???
    Par Gunsnake dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 11/04/2006, 12h39
  4. Exécution indivisible (accès conccurent)
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 23/07/2002, 08h09
  5. Accès à une application ouverte (OLE Automation ?)
    Par PascalB dans le forum C++Builder
    Réponses: 6
    Dernier message: 17/06/2002, 14h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo