#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "jsmn.h"



/*

 * A small example of jsmn parsing when JSON structure is known and number of

 * tokens is predictable.

 */



static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {

if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&

strncmp(json + tok->start, s, tok->end - tok->start) == 0) {

return 0;

}

return -1;

}


char * jsmn_StringReader(){


char * a;

char * b;

FILE *f1;

f1=fopen("library.json","r");


b=(char *)malloc(sizeof(char));

 a=(char*)malloc(sizeof(char));


while(1){

  fgets(a,sizeof(a),f1);

        if(feof(f1))break;

  b=(char*)realloc(b,strlen(b)+strlen(a));

  //printf("\n%d\n",strlen(a));

  strncat(b,a,strlen(a));

}


fclose(f1);

 return b ;

}




void jsmn_init(jsmn_parser *parser);

int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,jsmntok_t *tokens, unsigned int num_tokens);


int main() {

int i;

int r;

jsmn_parser p;

jsmntok_t t[128]; /* We expect no more than 128 tokens */


jsmn_init(&p);

char * JSON_STRING=jsmn_StringReader();

printf("%s\n",JSON_STRING);

r = jsmn_parse(&p, JSON_STRING, strlen(JSON_STRING), t, sizeof(t)/sizeof(t[0]));

if (r < 0) {

printf("Failed to parse JSON: %d\n", r);

return 1;

}


/* Assume the top-level element is an object */

if (r < 1 || t[0].type != JSMN_OBJECT) {

printf("Object expected\n");

return 1;

}

#ifdef DEBUG_MODE


printf("r의 값은 %d입니다",r);

#endif

/* Loop over all keys of the root object */

for (i = 1; i < r; i++) {

if (jsoneq(JSON_STRING, &t[i], "name") == 0) {

/* We may use strndup() to fetch string value */

printf("- Name: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


        printf("User의 token은 %d번째입니다",i);

        #endif

} else if (jsoneq(JSON_STRING, &t[i], "keywords") == 0) {

/* We may additionally check if the value is either "true" or "false" */

printf("- Keywords: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Admin의 token은 %d번째입니다",i);

                 #endif


} else if (jsoneq(JSON_STRING, &t[i], "description") == 0) {

/* We may want to do strtol() here to get numeric value */

printf("- Description: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

} 


else if (jsoneq(JSON_STRING, &t[i], "type") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- type: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "url") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- url: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "frameworks") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Frameworks: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }

else if (jsoneq(JSON_STRING, &t[i], "platforms") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Platfroms: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }


else if (jsoneq(JSON_STRING, &t[i], "exclude") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Excludes: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }



else if (jsoneq(JSON_STRING, &t[i], "examples") == 0) {

                        int j;

                        printf("- Exampleis:\n");

                        if (t[i+1].type != JSMN_ARRAY) {

                                continue; /* We expect groups to be an array of strings */

                        }

                        for (j = 0; j < t[i+1].size; j++) {

                                jsmntok_t *g = &t[i+j+2];

                                printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

                        }

                        i += t[i+1].size + 1;

                } 



else if (jsoneq(JSON_STRING, &t[i], "repository") == 0) {

int j;

printf("- Repository:\n");

if (t[i+1].type != JSMN_ARRAY) {

continue; /* We expect groups to be an array of strings */

}

for (j = 0; j < t[i+1].size; j++) {

jsmntok_t *g = &t[i+j+2];

printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

}

i += t[i+1].size + 1;

#ifdef DEBUG_MODE


                 printf("Object인 groups의  token은 %d번째입니다",i);

                 #endif

} else {

printf("Unexpected key: %.*s\n", t[i].end-t[i].start,

JSON_STRING + t[i].start);

}

}

return EXIT_SUCCESS;

}


parsejsonfile.c를 위한 jsmn_StringRader()



char * jsmn_StringReader(){


char * a;

char * b;

FILE *f1;

f1=fopen("library.json","r");


b=(char *)malloc(sizeof(char));

 a=(char*)malloc(sizeof(char));


while(1){

  fgets(a,sizeof(a),f1);

        if(feof(f1))break;

  b=(char*)realloc(b,strlen(b)+strlen(a));

  //printf("\n%d\n",strlen(a));

  strncat(b,a,strlen(a));

}


fclose(f1);

 return b ;

}




하나의 text파일에 대하여 하나의 char *f 변수를 잡고 해당 변수에 각 txt의 한줄 한줄을 크기에 대하여 realloc시킴으로써 저장하였다. 

feof()를 통해서 txt파일의 끝까지 읽어 주었다. 


1. 새로운 계정 만들기


$ adduser [userName]

-먼저 계정을 간단히 만든다.


2.wordpress설치

2.1    /home/jeon/www에 아래와 같은 command를 통해서 wordpress를 설치한다.....


$wget http://wordpress.org/latest.tar.gz    ->설치 파일 다운로드

$tar -xvzf latest.tar.gz    ->설치파일 압축 해제

2.2 Apache2와 연결 시켜준다(실행권한 부여)


$cd /home/jeon/www

$sudo chown www-data:www-data * -R

$sudo usermod -a -G www-data jeon

$sudo chmod -R 775 /home/jeon/www


2.3 apache2를 제사작한다

$ service apache2 restart



3.해당 계정에 대한 VIrtualHost를 설정해준다

3.1 apache2.conf설정 

$ vim /etc/apache2/apache.conf




(나의 새로운 계정은  jeon이었으며, /home/jeon/www/wordpress에 대하여 virtualhost를 설정했다)

3.2 wordpress.conf생성하기

$cd /etc/apache2/site-available/

$vim wordpress.conf


(설정 값을 다음과 같이 부여한다.)

그리고 /etc/apache2/site-available/에서 $sudo a2ensite wordpress.conf 를 통해서 ../site-enable에도 만들어주어야 virtualhost가 완벽하게 만들어진다.....


3.3 DNS를 설정한다

$vim /etc/hosts



wordpress로 접속될 DNS값을 설정한다





4. Mysql을 통해서 설치한 wordpress와 database를 연결한다

아래와 같은 방법으로 mysql에 접속한다

$mysql -u root -r

(mysql설치할때, 설정한 비밀번호로 접속하면 된다)


접속이 되었다면, database를 만들어준다

>create database wordpress;

("wordpress"라는 이름의 database를 만든 것이다)


wordpress의 database를 관리할게 될 계정을 만들어준다

>create user  jeon@localhost;

>set password for jeon@localhost=password("PASSWORD");     

(이때, "PASSWORD"는 정말 jeon@localhost의 비밀번호이기 때문에 기억 할 수있는 비밀번호를 사용하여야 한다)


이제 jeon@localhost에게 wordpress의 database의 권한을 부여한다

>grant all privileges on wordpress.* to jeon@localhost identified by 'PASSWORD';

>flush privileges;

>exit


이제 mysql의 사용자에 대한 설정이 반 끝났다.


5. 나머지 반은 이제 /home/jeon/www/wordpress의 wp-config-sample.php에 방금 설정한 user의 값을 삽이하면 된다

(이 예제는 지금, wordpress라는 database에 "jeon"의 비밀번호로 설정된  jeon@localhost가 관리를 하게 하기 이한 설정이다)

 6. 이제 wordpress에 접속하면된다....

Let's go!

(submit해도 계속 wp-config.php이야기하면서 db랑 연결이 안된다고 오류가 뜰때가있다. 즉, wp-config.php에 저장된 값들과 mysql의 db와 정보가 다른 경우를 말한다. 그런경우 mysql에 접속해서 db를 drop(삭제)하고 create(생성)한 다음 계정의 차근차근 다시 생성하면된다)

설정한 db 아이디와 비밀번호로 로그인하면 된다....





















mysq; 명령어 정리: https://pat.im/624

$ apache2ctl restart 실 발생한 error들.....

ah00558 httpd could not reliably determine the server's fully qualified domain name.....
위와 같이 error가 뜨는 경우 /etc/apache2/apache2.conf에 ServerName localhost를 추가하면된다


나는 위치를 고려하지 않고 삽이하여 다시 $ apache2ctl restart를 실행하니 해당 에러가 뜨지 않았다......
(내 생각에는 DNS를 사용하는 경우에는 ServerName을 domain name으로 설정해도 될 것 같다)

구글링 헤보니깐 많은데에서 httpd.conf에 추가 하라고 하는데 blog post시기를 보면 오랜된 대가 많다. 아마 Apache2전 버전에서 해당되는 것 같다





Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

위의 error같은겨우는 sudo user로 실행해야 port 80에 접근이 가능하기 떄문에

$sudo 를 통해서 명령어를 실행시켜야 한다

'오류모음' 카테고리의 다른 글

[Hexo]오류 모음  (0) 2018.05.17
[brew]오류 모음  (0) 2018.05.17


Hexo Error




ERROR Deployer not found: git

-deploy(배포)를 실패하고 있다는 뜻. 

해결방법: $ npm install hexo-deployer-git --save 를 통해서 deployer를 설치한다

'오류모음' 카테고리의 다른 글

[Ubuntu]  (2) 2018.05.18
[brew]오류 모음  (0) 2018.05.17



url: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

-일시적인 network 문제

해결방법: network문제 이기 때문에 다시 실행하면 된다


brew를 통해서 install을 할때 access 문제가 생기면 sudo를 통해서 install하면 된다

권한의 문제기 때문에 super user를 통해서 접근한다



'오류모음' 카테고리의 다른 글

[Ubuntu]  (2) 2018.05.18
[Hexo]오류 모음  (0) 2018.05.17


CMS 






CMS: (Contents Management System)콘텐츠 관리 시스템으로써,  쉽게 생각해서 우리가 사용하는 웹 혹은 blog를 개설하는 system이다. 블로거를 개설하는데 사용되었지만, 웹사이트를 관리하고 개설하는데 많이 사용되고 있다.




drupal: php 기반의 오픈소스 CMS이다. 사용자가 아닌 개발자에 초점이 맞춰져서 다른 CMS 다루기 어렵다. 다른 CMS보다 속도가 빠르며(시스템 리소스를 사용하지 않는다)  보안과 검색에서도 최적화 되어있으며, 복잡한 데이터 구조을 기반으로 하는 웹을 만들때도 적합한 툴이다. 하지만 그만큼 진입 장벽이 높다.


joomla!: Mysql 데이터베이스를 통해서 여러가지의 컨텐츠를 다루는 CMS이다. 여러지지의 templet을 지원하며, 풍부한 확장기능도 존재한다



WordPress:  HTML이나 PHP의 코드의 큰 수정 없이 편집하며, 셀프 호스팅 블로거 툴로 시작한 현재는 가장 많이 사용되는 CMS이다. 진입장벽이 많이 낮음. 또한 다양한 기능을 지원하기에 여러가지의 plug-in,테마가 존재한다. 트랙백과 핑백이 지원 돠며, SNS와도 쉽게 연동될 수 있다. 하지만 반대로 customizing이 어려우며







(핑백: 다른 블로거의 컨텐츠를 가져와 포스팅 할 때, 양쪽에 모두 링크가 남는 경우

트랙백: 다른 블로거의 컨텐츠를 가져와서 포스팅 할 때, 출처의 블로거에만 링크가 남겨지는 경우)














출처:

wordpress의 장단점: http://blog.helloweb.co.kr/the-pros-and-the-cons-of-the-wordpress-homepage/

두루팔이란: http://blog.naver.com/PostView.nhn?blogId=vinylx&logNo=220535085554&parentCategoryNo=&categoryNo=11&viewDate=&isShowPopularPosts=true&from=search


 

'Learning Concept' 카테고리의 다른 글

[Ubuntu & APM]  (0) 2018.05.06

새로운 계정에 홈 디렉토리로 변경 및 name domain사용








0.새로운 계정 만들기

http://kyu-tag.tistory.com/13의 1번을 참고하여서 new user를 생성하면된다.

나 같은 경우는 user1의 홈 디렉토리를 user2의 계정으로 디렉토리를 변경하였다......(목적)





1. 새로운 index.html

새로운 홈 디렉토리를 만들기 위해서는 새로운 html을 만들어준다

지금 같은 경우는 새로운 계정에 새로운 dir을 만들고 그 위에 indext.html을 gedit을 통해서 만들어 주었다


새로운 계정은

$ sudo adduser 새로운 이름


그리고 mkdir을 통해서 user2에 www라는 폴더를 만들고

$ sudo mkdir /home/user2/www


gedit을 통해서 새로운 html을 생성했다

$ sudo gedit index.html





2.apache2.conf 수정

먼저 apache2.conf의 내용을 변경한다

$ sudo gedit /etc/apache2/apache2.conf



디렉토리 설정을 원하는 html파일이 있는 폴더로 다음과 같이 수정한다


그 다음 site-available에 있는 000-default.conf의 내용을 수정하면 된다

$ sudo gedit /etc/apache2/sites-availlable/000-default.conf


apache2.conf 수정 처럼 해당 디렉토리로 변경하면된다



3. 이제 localhost에 들어가 보자

/home/user2(해당 계정)/www/html에 info.php()도 생성해서 확인해 보면......


info.php도 생성 된 것을 알 수 있으며


localhost도 잘 돌아가는 것을 볼 수 있다


4. localhost에 named domain을 만들어보자

wow.com의 도메인을 

$ sudo gedit /etc/hosts

에 들어가서 다음과 같이 수정한다

도메인 창에 wow.com을 치면......

접속이된다........









후기: 처음 실행때는 잘 되다가 2번째대 계속 localhost에서 서버에 대한 접근의 permission이 없다하여서, chmod로 권한 설정 넓히고 구글링하다 결과적으로 고친 오류는 conf에서 수정할때 html을 hmtl의 오타가 있었다. 가끔은 오타의 문제로 프로그램에 오류가 생길 수 있으며 아무리 command 라인을 처도 뜨릴 수 도 있으니 주의하자!!! 







reference:    http://zzaps.tistory.com/242






'OSS' 카테고리의 다른 글

[jsmn] 하나의 text를 하나의 string으로 받기  (0) 2018.05.25
[Ubuntu] Wordpress 설치  (0) 2018.05.25
[ubuntu] ssh server설치 및 접속  (0) 2018.05.08
[Ubuntu]hostname 변경  (0) 2018.05.07
[Ubuntu] Package tool&Network status  (0) 2018.05.07

ssh Server 설치 & 접속


1. ssh에 접속하게 될 계정을 생성한다

user2를 새로 생성하는 command이다


$ sudo adduser user2


그러면 다음 과 같은 사진을 통해서 user에 대한 비밀번호와 기본 정보들을 입력한다



2. ssh를 설치하자


$ sudo apt-get install ssh

install를 하고 위에서 만든 계정으로 로그인을 해보면.......

성공

3. VM에서가 아닌 (ubuntu에서 말고 ) host 컴퓨터에서 접속 해보자

1. 먼저 현재의 ubuntu를 종료한다 (그래야 나중에 어덥터를 추가 할 수 있다)

2. VM에서 전역 도구에 들어가 네트워크를 생성한다

3.머신 도구에 들어가서 해당 vm의 설정에 네트워크 값을 아래와 같이 설정한다


termianl에서 ifconfig를 통해서 새로운 network가 추가된 것을 확인 할 수 있다



4.다시 ubuntu를 켜고 ifconfig를 통해서 이더넷 IP주소를 가저온다

5. host 컴퓨터에서 ssh를 통해서 해당 IP에 접속한다










reference: 

ssh 설치 및 설명:http://programmingskills.net/archives/315

계정 생성:http://mirwebma.tistory.com/112        https://jongmin92.github.io/2016/09/20/Linux%20&%20Ubuntu/add_user/

호스트 컴퓨터에서 접속: http://hongku.tistory.com/75






+ Recent posts