summaryrefslogtreecommitdiffabout
path: root/libical/src/libicalss/icalcstp.c
blob: ed62b40672863c5826754b4281704ddc4b6ab1c2 (plain)
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
/* -*- Mode: C -*-
    ======================================================================
    FILE: icalcstps.c
    CREATOR: ebusboom 23 Jun 2000
  
    $Id$
    $Locker$
    
    (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of either: 
    
    The LGPL as published by the Free Software Foundation, version
    2.1, available at: http://www.fsf.org/copyleft/lesser.html
    
    Or:
    
    The Mozilla Public License Version 1.0. You may obtain a copy of
    the License at http://www.mozilla.org/MPL/


    ======================================================================*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "ical.h"
#include "icalcstp.h"
#include "pvl.h" 

// Eugen C. <eug@thekompany.com>
#include <defines.h>
#ifndef _QTWIN_
#include <sys/types.h> /* For send(), others */
#include <sys/socket.h>  /* For send(), others. */
#include <unistd.h>
#endif
// Eugen C. <eug@thekompany.com>
#include <errno.h>
#include <stdlib.h> /* for malloc */
#include <string.h>


struct command_map {
	enum icalcstp_command command;
	char *str;
} command_map[] = 
{
    {ICAL_ABORT_COMMAND,"ABORT"},
    {ICAL_AUTHENTICATE_COMMAND,"AUTHENTICATE"},
    {ICAL_CAPABILITY_COMMAND,"CAPABILITY"},
    {ICAL_CONTINUE_COMMAND,"CONTINUE"},
    {ICAL_CALIDEXPAND_COMMAND,"CALIDEXPAND"},
    {ICAL_IDENTIFY_COMMAND,"IDENTIFY"},
    {ICAL_DISCONNECT_COMMAND,"DISCONNECT"},
    {ICAL_SENDDATA_COMMAND,"SENDDATA"},
    {ICAL_STARTTLS_COMMAND,"STARTTLS"},
    {ICAL_UPNEXPAND_COMMAND,"UPNEXPAND"},
    {ICAL_UNKNOWN_COMMAND,"UNKNOWN"}
};


icalcstp_command icalcstp_line_command(char* line)
{
    int i;

    for(i = 0; command_map[i].command != ICAL_UNKNOWN_COMMAND; i++){
        size_t l = strlen(command_map[i].str);

        if(strncmp(line, command_map[i].str, l) == 0){
            return command_map[i].command;
        }
    
    }

    return ICAL_UNKNOWN_COMMAND;
}

icalrequeststatus icalcstp_line_response_code(char* line)
{
    struct icalreqstattype rs; 

    rs = icalreqstattype_from_string(line);

    return rs.code;
}

int icalcstp_line_is_endofdata(char* line)
{
    if(line[0] == '.' && line[1] == '\n'){
        return 1;
    }

    return 0;

}

int icalcstp_line_is_mime(char* line)
{
  return 0;
}


const char* icalcstp_command_to_string(icalcstp_command command){

    int i;

    for(i = 0; command_map[i].command != ICAL_UNKNOWN_COMMAND; i++){
        size_t l = strlen(command_map[i].str);

        if(command_map[i].command == command){
            return command_map[i].str;
        }
    
    }

    return command_map[i].str;

}